Skip to content

Commit

Permalink
litlle refactor tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mgalofre committed Mar 7, 2017
1 parent cfb3005 commit f5e94d7
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 163 deletions.
40 changes: 19 additions & 21 deletions addonpayments/hpp/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,9 @@

from addonpayments.hpp.card_storage.requests import CardStorageRequest
from addonpayments.hpp.payment.requests import PaymentRequest
from addonpayments.hpp.tests.utils import sample_path, only_mandatory_hpp_request, hpp_request_storage_enabled
from addonpayments.hpp.tests.utils import get_sample_path, only_mandatory_hpp_request, hpp_request_storage_enabled
from addonpayments.hpp.utils import JsonUtils

CHARSET = "utf-8"
HPP_PAYMENT_REQUEST_VALID_JSON_PATH = "samples/hpp_payment_request.json"
HPP_PAYMENT_REQUEST_SUPPLEMENTARY_JSON_PATH = "samples/hpp_payment_request_supplementary_data.json"
HPP_PAYMENT_REQUEST_ENCODED_JSON_PATH = "samples/hpp_payment_request_encoded.json"
HPP_CARD_STORAGE_REQUEST_VALID_JSON_PATH = "samples/hpp_card_storage_request.json"
HPP_CARD_STORAGE_REQUEST_SUPPLEMENTARY_JSON_PATH = "samples/hpp_card_storage_request_supplementary_data.json"
HPP_CARD_STORAGE_REQUEST_ENCODED_JSON_PATH = "samples/hpp_card_storage_request_encoded.json"


@pytest.fixture()
def valid_hpp_request():
Expand All @@ -33,35 +25,41 @@ def valid_hpp_request_storage_enabled():

@pytest.fixture()
def json_hpp_payment_request_valid():
with codecs.open(sample_path(HPP_PAYMENT_REQUEST_VALID_JSON_PATH), 'r', encoding='utf-8') as data_file:
yield JsonUtils.from_json_hpp_request(data_file.read(), CHARSET, False)
path = get_sample_path('samples/hpp_payment_request.json')
with codecs.open(path, 'r', encoding='utf-8') as data_file:
yield JsonUtils.from_json_hpp_request(data_file.read(), 'utf-8', False)


@pytest.fixture()
def json_hpp_payment_request_supplementary_data():
with codecs.open(sample_path(HPP_PAYMENT_REQUEST_SUPPLEMENTARY_JSON_PATH), 'r', encoding='utf-8') as data_file:
yield JsonUtils.from_json_hpp_request(data_file.read(), CHARSET, False)
path = get_sample_path('samples/hpp_payment_request_supplementary_data.json')
with codecs.open(path, 'r', encoding='utf-8') as data_file:
yield JsonUtils.from_json_hpp_request(data_file.read(), 'utf-8', False)


@pytest.fixture()
def json_hpp_payment_request_encoded():
with codecs.open(sample_path(HPP_PAYMENT_REQUEST_ENCODED_JSON_PATH), 'r', encoding='utf-8') as data_file:
yield JsonUtils.from_json_hpp_request(data_file.read(), CHARSET, True)
path = get_sample_path('samples/hpp_payment_request_encoded.json')
with codecs.open(path, 'r', encoding='utf-8') as data_file:
yield JsonUtils.from_json_hpp_request(data_file.read(), 'utf-8', True)


@pytest.fixture()
def json_hpp_card_storage_request_valid():
with codecs.open(sample_path(HPP_CARD_STORAGE_REQUEST_VALID_JSON_PATH), 'r', encoding='utf-8') as data_file:
yield JsonUtils.from_json_hpp_request(data_file.read(), CHARSET, False)
path = get_sample_path('samples/hpp_card_storage_request.json')
with codecs.open(path, 'r', encoding='utf-8') as data_file:
yield JsonUtils.from_json_hpp_request(data_file.read(), 'utf-8', False)


@pytest.fixture()
def json_hpp_card_storage_request_supp_data():
with codecs.open(sample_path(HPP_CARD_STORAGE_REQUEST_SUPPLEMENTARY_JSON_PATH), 'r', encoding='utf-8') as data_file:
yield JsonUtils.from_json_hpp_request(data_file.read(), CHARSET, False)
path = get_sample_path('samples/hpp_card_storage_request_supplementary_data.json')
with codecs.open(path, 'r', encoding='utf-8') as data_file:
yield JsonUtils.from_json_hpp_request(data_file.read(), 'utf-8', False)


@pytest.fixture()
def json_hpp_card_storage_request_encoded():
with codecs.open(sample_path(HPP_CARD_STORAGE_REQUEST_ENCODED_JSON_PATH), 'r', encoding='utf-8') as data_file:
yield JsonUtils.from_json_hpp_request(data_file.read(), CHARSET, True)
path = get_sample_path('samples/hpp_card_storage_request_encoded.json')
with codecs.open(path, 'r', encoding='utf-8') as data_file:
yield JsonUtils.from_json_hpp_request(data_file.read(), 'utf-8', True)
6 changes: 3 additions & 3 deletions addonpayments/hpp/tests/tests/test_generation_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def test_generate_hash(self):
"""
Test Hash generation success case.
"""
test_string = "20120926112654.thestore.ORD453-11.00.Successful.3737468273643.79347"
secret = "mysecret"
expected_result = "368df010076481d47a21e777871012b62b976339"
test_string = '20120926112654.thestore.ORD453-11.00.Successful.3737468273643.79347'
secret = 'mysecret'
expected_result = '368df010076481d47a21e777871012b62b976339'
result = GenerationUtils.generate_hash(test_string, secret)
assert expected_result == result

Expand Down
Loading

0 comments on commit f5e94d7

Please sign in to comment.