Skip to content

Commit

Permalink
migrate client10 test on responses
Browse files Browse the repository at this point in the history
  • Loading branch information
orsinium committed Oct 9, 2019
1 parent e01ff69 commit 67db35e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 20 deletions.
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-r requirements.txt
httpretty
responses
pytest
pytest-cov
pytest-pythonpath
Expand Down
41 changes: 22 additions & 19 deletions tests/test_client10.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@


import pytest
import httpretty
import responses

from libtaxii import messages_10 as tm10

Expand Down Expand Up @@ -30,16 +30,19 @@ def create_client_10(**kwargs):


def register_uri(uri, body, **kwargs):
httpretty.register_uri(
httpretty.POST, uri, body=body,
responses.add(
method=responses.POST,
url=uri,
body=body,
content_type='application/xml',
stream=True,
adding_headers={'X-TAXII-Content-Type': XML_10_BINDING},
**kwargs)


def get_sent_message():
body = httpretty.last_request().body
print(body)
body = responses.calls[-1].request.body
print(repr(body))
return tm10.get_message_from_xml(body)

# Tests
Expand All @@ -59,18 +62,18 @@ def test_no_discovery_path_when_pushing():
client.push(CONTENT, CONTENT_BINDING)


@httpretty.activate
@responses.activate
def test_incorrect_path():

httpretty.register_uri(httpretty.POST, DISCOVERY_URI_HTTP, status=404)
responses.add(responses.POST, DISCOVERY_URI_HTTP, status=404)

client = create_client_10(discovery_path=DISCOVERY_PATH)

with pytest.raises(exc.HTTPError):
client.discover_services()


@httpretty.activate
@responses.activate
def test_discovery():

register_uri(DISCOVERY_URI_HTTP, DISCOVERY_RESPONSE)
Expand All @@ -89,7 +92,7 @@ def test_discovery():
assert type(message) == tm10.DiscoveryRequest


@httpretty.activate
@responses.activate
def test_discovery_https():

register_uri(DISCOVERY_URI_HTTPS, DISCOVERY_RESPONSE)
Expand All @@ -104,7 +107,7 @@ def test_discovery_https():
assert type(message) == tm10.DiscoveryRequest


@httpretty.activate
@responses.activate
def test_collections():

register_uri(FEED_MANAGEMENT_URI, FEED_MANAGEMENT_RESPONSE)
Expand All @@ -130,7 +133,7 @@ def test_collections():
assert type(message) == tm10.FeedInformationRequest


@httpretty.activate
@responses.activate
def test_collections_with_automatic_discovery():

register_uri(DISCOVERY_URI_HTTP, DISCOVERY_RESPONSE)
Expand All @@ -146,7 +149,7 @@ def test_collections_with_automatic_discovery():
assert type(message) == tm10.FeedInformationRequest


@httpretty.activate
@responses.activate
def test_poll():

register_uri(POLL_URI, POLL_RESPONSE)
Expand All @@ -161,7 +164,7 @@ def test_poll():
assert message.feed_name == POLL_FEED


@httpretty.activate
@responses.activate
def test_poll_count_only():

register_uri(POLL_URI, POLL_RESPONSE)
Expand All @@ -172,7 +175,7 @@ def test_poll_count_only():
client.get_content_count(POLL_FEED, uri=POLL_PATH)


@httpretty.activate
@responses.activate
def test_poll_with_subscription():

register_uri(POLL_URI, POLL_RESPONSE)
Expand All @@ -190,7 +193,7 @@ def test_poll_with_subscription():
assert message.subscription_id == SUBSCRIPTION_ID


@httpretty.activate
@responses.activate
def test_poll_with_content_bindings():

register_uri(POLL_URI, POLL_RESPONSE)
Expand Down Expand Up @@ -227,7 +230,7 @@ def test_poll_with_content_bindings():
assert message.content_bindings[0] == binding.id


@httpretty.activate
@responses.activate
def test_subscribe():

register_uri(FEED_MANAGEMENT_URI, SUBSCRIPTION_RESPONSE)
Expand All @@ -248,7 +251,7 @@ def test_subscribe():
assert message.action == tm10.ACT_SUBSCRIBE


@httpretty.activate
@responses.activate
def test_subscribe_with_push():

register_uri(DISCOVERY_URI_HTTP, DISCOVERY_RESPONSE)
Expand Down Expand Up @@ -277,7 +280,7 @@ def test_subscribe_with_push():
assert message.action == tm10.ACT_SUBSCRIBE


@httpretty.activate
@responses.activate
def test_unsubscribe():

register_uri(FEED_MANAGEMENT_URI, SUBSCRIPTION_RESPONSE)
Expand All @@ -300,7 +303,7 @@ def test_unsubscribe():
assert message.action == tm10.ACT_UNSUBSCRIBE


@httpretty.activate
@responses.activate
def test_push():

register_uri(INBOX_URI, INBOX_RESPONSE)
Expand Down

0 comments on commit 67db35e

Please sign in to comment.