Skip to content

Commit

Permalink
Acceptance tests: Response Headers
Browse files Browse the repository at this point in the history
  • Loading branch information
Guido Barbaglia committed Aug 22, 2017
1 parent 720cbc8 commit 2d8915e
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 4 deletions.
12 changes: 11 additions & 1 deletion pact_test/matchers/response_matcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,14 @@ def _is_subset(expected, actual):
actual_items = actual.items() if actual else {}
expected_items = expected.items() if expected else {}

return all(item in expected_items for item in actual_items)
stripped_actual_items = map(_strip_whitespaces_after_commas, actual_items)
stripped_expected_items = map(_strip_whitespaces_after_commas, expected_items)

return all(item in stripped_actual_items for item in expected_items)


def _strip_whitespaces_after_commas(t):
k = t[0]
v = t[1].replace(', ', ',') if type(t[1]) is str else t[1]

return k, v
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tests.acceptance.acceptance_test_loader import load_acceptance_test


def test_different_status():
def test_empty_headers():
data = load_acceptance_test(__file__)

response = PactResponse(headers=[])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tests.acceptance.acceptance_test_loader import load_acceptance_test


def test_different_status():
def test_different_name_case():
data = load_acceptance_test(__file__)

response = PactResponse(headers=[('ACCEPT', 'alligators')])
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pact_test.either import Left
from pact_test.models.response import PactResponse
from pact_test.matchers.response_matcher import match
from tests.acceptance.acceptance_test_loader import load_acceptance_test


def test_different_value_case():
data = load_acceptance_test(__file__)

response = PactResponse(headers=[('Accept', 'Alligators')])
interaction = {'response': {'headers': data['expected']['headers']}}
test_result = match(interaction, response)

assert type(test_result) is Left
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from tests.acceptance.acceptance_test_loader import load_acceptance_test


def test_different_status():
def test_headers_match():
data = load_acceptance_test(__file__)

response = PactResponse(headers=[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pact_test.either import Left
from pact_test.models.response import PactResponse
from pact_test.matchers.response_matcher import match
from tests.acceptance.acceptance_test_loader import load_acceptance_test


def test_order_of_headers():
data = load_acceptance_test(__file__)

response = PactResponse(headers=[('Accept', 'hippos, alligators')])
interaction = {'response': {'headers': data['expected']['headers']}}
test_result = match(interaction, response)

assert type(test_result) is Left
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pact_test.either import Right
from pact_test.models.response import PactResponse
from pact_test.matchers.response_matcher import match
from tests.acceptance.acceptance_test_loader import load_acceptance_test


def test_unexpected_header():
data = load_acceptance_test(__file__)

response = PactResponse(headers=[('Accept', 'alligators')])
interaction = {'response': {'headers': data['expected']['headers']}}
test_result = match(interaction, response)

assert type(test_result) is Right
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
from pact_test.either import Right
from pact_test.models.response import PactResponse
from pact_test.matchers.response_matcher import match
from tests.acceptance.acceptance_test_loader import load_acceptance_test


def test_whitespaces_after_comma():
data = load_acceptance_test(__file__)

response = PactResponse(headers=[('Accept', 'alligators, hippos')])
interaction = {'response': {'headers': data['expected']['headers']}}
test_result = match(interaction, response)

assert type(test_result) is Right

0 comments on commit 2d8915e

Please sign in to comment.