-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Muhammad Noyan Aziz
authored and
Muhammad Noyan Aziz
committed
Dec 12, 2024
1 parent
f60b48c
commit c8a1720
Showing
3 changed files
with
42 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -806,94 +806,84 @@ def test_update_customer_with_anonymized_fields_exception(self): | |
def test_is_first_time_discount_eligible_success(self): | ||
base_url = self.client_set.get_base_url_from_client() | ||
email = '[email protected]' | ||
code = 'discount-code' | ||
|
||
mock_discount_codes = { | ||
mock_orders = { | ||
"total": 1, | ||
"results": [ | ||
{"id": "discount-id-1"}, | ||
{"id": "discount-id-2"} | ||
{ | ||
"discountCodes": [ | ||
{ | ||
"discountCode": { | ||
"obj": { | ||
"code": 'another-code' | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
||
mock_orders = { | ||
"total": 0 | ||
} | ||
|
||
with requests_mock.Mocker(real_http=True, case_sensitive=False) as mocker: | ||
mocker.get( | ||
f"{base_url}discount-codes", | ||
json=mock_discount_codes, | ||
status_code=200 | ||
) | ||
|
||
mocker.get( | ||
f"{base_url}orders", | ||
json=mock_orders, | ||
status_code=200 | ||
) | ||
|
||
result = self.client_set.client.is_first_time_discount_eligible(email) | ||
result = self.client_set.client.is_first_time_discount_eligible(email, code) | ||
self.assertTrue(result) | ||
|
||
def test_is_first_time_discount_eligible_not_eligible(self): | ||
def test_is_first_time_discount_not_eligible(self): | ||
base_url = self.client_set.get_base_url_from_client() | ||
email = '[email protected]' | ||
code = 'discount-code' | ||
|
||
mock_discount_codes = { | ||
mock_orders = { | ||
"total": 1, | ||
"results": [ | ||
{"id": "discount-id-1"}, | ||
{"id": "discount-id-2"} | ||
{ | ||
"discountCodes": [ | ||
{ | ||
"discountCode": { | ||
"obj": { | ||
"code": code | ||
} | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
|
||
mock_orders = { | ||
"total": 1 | ||
} | ||
|
||
with requests_mock.Mocker(real_http=True, case_sensitive=False) as mocker: | ||
mocker.get( | ||
f"{base_url}discount-codes", | ||
json=mock_discount_codes, | ||
status_code=200 | ||
) | ||
|
||
mocker.get( | ||
f"{base_url}orders", | ||
json=mock_orders, | ||
status_code=200 | ||
) | ||
|
||
result = self.client_set.client.is_first_time_discount_eligible(email) | ||
result = self.client_set.client.is_first_time_discount_eligible(email, code) | ||
self.assertFalse(result) | ||
|
||
def test_is_first_time_discount_eligible_invalid_email(self): | ||
invalid_email = "[email protected]" | ||
code = 'discount-code' | ||
base_url = self.client_set.get_base_url_from_client() | ||
|
||
mock_discount_codes = { | ||
"results": [ | ||
{"id": "discount-id-1"}, | ||
{"id": "discount-id-2"} | ||
] | ||
} | ||
|
||
mock_orders = { | ||
"total": 0 | ||
} | ||
|
||
with requests_mock.Mocker(real_http=True, case_sensitive=False) as mocker: | ||
mocker.get( | ||
f"{base_url}discount-codes", | ||
json=mock_discount_codes, | ||
status_code=200 | ||
) | ||
|
||
mocker.get( | ||
f"{base_url}orders", | ||
json=mock_orders, | ||
status_code=200 | ||
) | ||
|
||
result = self.client_set.client.is_first_time_discount_eligible(invalid_email) | ||
result = self.client_set.client.is_first_time_discount_eligible(invalid_email, code) | ||
self.assertTrue(result) | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -271,6 +271,7 @@ class CommercetoolsDiscountEligibilityPipelineTests(TestCase): | |
"""Commercetools pipeline testcase for checking discount eligibility in CT""" | ||
def setUp(self) -> None: | ||
self.mock_email = "[email protected]" | ||
self.mock_code = "mock_code" | ||
self.mock_eligible_result = True | ||
self.mock_ineligible_result = False | ||
|
||
|
@@ -281,7 +282,7 @@ def setUp(self) -> None: | |
def test_pipeline_eligible(self, mock_is_eligible): | ||
pipe = CheckCommercetoolsDiscountEligibility("test_pipe", None) | ||
mock_is_eligible.return_value = self.mock_eligible_result | ||
ret = pipe.run_filter(self.mock_email) | ||
ret = pipe.run_filter(self.mock_email, self.mock_code) | ||
result_data = ret['is_eligible'] | ||
self.assertEqual(result_data, self.mock_eligible_result) | ||
|
||
|
@@ -292,6 +293,6 @@ def test_pipeline_eligible(self, mock_is_eligible): | |
def test_pipeline_ineligible(self, mock_is_eligible): | ||
pipe = CheckCommercetoolsDiscountEligibility("test_pipe", None) | ||
mock_is_eligible.return_value = self.mock_ineligible_result | ||
ret = pipe.run_filter(self.mock_email) | ||
ret = pipe.run_filter(self.mock_email, self.mock_code) | ||
result_data = ret['is_eligible'] | ||
self.assertEqual(result_data, self.mock_ineligible_result) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -393,6 +393,7 @@ class FirstTimeDiscountEligibleViewTests(APITestCase): | |
test_user_username = 'test' | ||
test_user_email = '[email protected]' | ||
test_user_password = 'secret' | ||
test_discount = 'first_time_discount' | ||
|
||
url = reverse('lms:first_time_discount_eligible') | ||
|
||
|
@@ -421,11 +422,11 @@ def test_get_with_valid_email_eligibility_true(self, mock_filter): | |
self.authenticate_user() | ||
mock_filter.return_value = {'is_eligible': True} | ||
|
||
response = self.client.get(self.url, {'email': self.test_user_email}) | ||
response = self.client.get(self.url, {'email': self.test_user_email, 'code': self.test_discount}) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(response.data, {"is_eligible": True}) | ||
mock_filter.assert_called_once_with(email=self.test_user_email) | ||
mock_filter.assert_called_once_with(email=self.test_user_email, code='first_time_discount') | ||
|
||
@patch('commerce_coordinator.apps.lms.views.CheckFirstTimeDiscountEligibility.run_filter') | ||
def test_get_with_valid_email_eligibility_false(self, mock_filter): | ||
|
@@ -435,11 +436,11 @@ def test_get_with_valid_email_eligibility_false(self, mock_filter): | |
self.authenticate_user() | ||
mock_filter.return_value = {'is_eligible': False} | ||
|
||
response = self.client.get(self.url, {'email': self.test_user_email}) | ||
response = self.client.get(self.url, {'email': self.test_user_email, 'code': self.test_discount}) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(response.data, {"is_eligible": False}) | ||
mock_filter.assert_called_once_with(email=self.test_user_email) | ||
mock_filter.assert_called_once_with(email=self.test_user_email, code=self.test_discount) | ||
|
||
def test_get_with_missing_email_fails(self): | ||
""" | ||
|
@@ -450,4 +451,4 @@ def test_get_with_missing_email_fails(self): | |
response = self.client.get(self.url) | ||
|
||
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN) | ||
self.assertEqual(response.data, {'detail': 'Could not detect user email.'}) | ||
self.assertEqual(response.data, {'detail': 'Could not detect user email or discount code.'}) |