Skip to content
This repository has been archived by the owner on Nov 4, 2024. It is now read-only.

Commit

Permalink
fix: fix test files
Browse files Browse the repository at this point in the history
  • Loading branch information
mumarkhan999 committed Dec 14, 2023
1 parent 49fcb6a commit ba7b3d4
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions ecommerce/extensions/api/v2/tests/views/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ def serialize_order(self, order):

def test_get_order(self):
"""Test successful order retrieval."""
response = self.client.get(self.url, headers={"authorization": self.token})
response = self.client.get(self.url, HTTP_AUTHORIZATION=self.token)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, self.serialize_order(self.order))

def test_order_wrong_user(self):
"""Test scenarios where an order should return a 404 due to the wrong user."""
other_user = self.create_user()
other_token = self.generate_jwt_token_header(other_user)
response = self.client.get(self.url, headers={"authorization": other_token})
response = self.client.get(self.url, HTTP_AUTHORIZATION=other_token)
self.assertEqual(response.status_code, 404)


Expand Down
14 changes: 7 additions & 7 deletions ecommerce/extensions/api/v2/tests/views/test_baskets.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def test_sku_missing(self):
self.PATH,
data=json.dumps(request_data),
content_type=JSON_CONTENT_TYPE,
headers={"authorization": self.generate_jwt_token_header(self.user)}
HTTP_AUTHORIZATION=self.generate_jwt_token_header(self.user)
)
self.assertEqual(response.status_code, 400)
self.assertEqual(
Expand Down Expand Up @@ -305,13 +305,13 @@ def test_oauth2_authentication(self):
auth_header = 'Bearer {}'.format(self.DEFAULT_TOKEN)

self.mock_user_info_response(username=self.user.username)
response = self.client.get(self.path, headers={"authorization": auth_header})
response = self.client.get(self.path, HTTP_AUTHORIZATION=auth_header)
self.assertEqual(response.status_code, 200)

def test_only_works_for_staff_users(self):
""" Test view only return results when accessed by staff. """
basket = BasketFactory(site=self.site)
response = self.client.get(self.path, headers={"authorization": self.token})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)

self.assertEqual(response.status_code, 200)
content = response.json()
Expand All @@ -331,7 +331,7 @@ def test_basket_information(self):
basket.add_product(product)
PaymentProcessorResponse.objects.create(basket=basket, transaction_id='PAY-123', processor_name='paypal',
response=json.dumps({'state': 'approved'}))
response = self.client.get(self.path, headers={"authorization": self.token})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)

self.assertEqual(response.status_code, 200)
content = response.json()
Expand All @@ -348,11 +348,11 @@ def test_voucher_errors(self):
basket.add_product(product)

with mock.patch('ecommerce.extensions.api.serializers.VoucherSerializer', side_effect=ValueError):
response = self.client.get(self.path, headers={"authorization": self.token})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)
self.assertIsNone(response.json()['results'][0]['vouchers'])

with mock.patch('ecommerce.extensions.api.serializers.VoucherSerializer', side_effect=AttributeError):
response = self.client.get(self.path, headers={"authorization": self.token})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)
self.assertIsNone(response.json()['results'][0]['vouchers'])


Expand All @@ -368,7 +368,7 @@ def test_deleted_basket(self):
url = self.url
self.order.basket.delete()

response = self.client.get(url, headers={"authorization": self.token})
response = self.client.get(url, HTTP_AUTHORIZATION=self.token)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data, self.serialize_order(self.order))

Expand Down
2 changes: 1 addition & 1 deletion ecommerce/extensions/api/v2/tests/views/test_courses.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def test_jwt_authentication(self):

response = self.client.get(
self.list_path,
headers={"authorization": auth_header}
HTTP_AUTHORIZATION=auth_header
)
self.assertEqual(response.status_code, 200)

Expand Down
24 changes: 12 additions & 12 deletions ecommerce/extensions/api/v2/tests/views/test_orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ def test_oauth2_authentication(self):
auth_header = 'Bearer {}'.format(self.DEFAULT_TOKEN)

self.mock_user_info_response(username=self.user.username)
response = self.client.get(self.path, headers={"authorization": auth_header})
response = self.client.get(self.path, HTTP_AUTHORIZATION=auth_header)
self.assert_empty_result_response(response)

def test_no_orders(self):
""" If the user has no orders, the view should return an empty list. """
self.assertFalse(self.user.orders.exists())
response = self.client.get(self.path, headers={"authorization": self.token})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)
self.assert_empty_result_response(response)

def test_with_orders(self):
Expand All @@ -87,7 +87,7 @@ def test_with_orders(self):
order = create_order(site=self.site, user=self.user)
site = SiteConfigurationFactory().site
create_order(site=site, user=self.user)
response = self.client.get(self.path, headers={"authorization": self.token})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)
self.assertEqual(response.status_code, 200)
content = json.loads(response.content.decode('utf-8'))

Expand All @@ -97,7 +97,7 @@ def test_with_orders(self):

# Test ordering
order_2 = create_order(site=self.site, user=self.user)
response = self.client.get(self.path, headers={"authorization": self.token})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)
self.assertEqual(response.status_code, 200)
content = json.loads(response.content.decode('utf-8'))

Expand All @@ -110,7 +110,7 @@ def test_enable_hoist_order_history(self, enable_hoist_order_history_flag):
""" Verify that orders contain the Order History flag value """
with override_flag(ENABLE_HOIST_ORDER_HISTORY, active=enable_hoist_order_history_flag):
create_order(site=self.site, user=self.user)
response = self.client.get(self.path, headers={"authorization": self.token})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)
self.assertEqual(response.status_code, 200)
content = json.loads(response.content.decode('utf-8'))

Expand Down Expand Up @@ -174,7 +174,7 @@ def test_orders_api_attributes_for_receipt_mfe(
Applicator().apply(basket, user=basket.owner, request=self.request)
order = factories.create_order(basket=basket, user=self.user)

response = self.client.get(self.path, headers={"authorization": self.token})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)
self.assertEqual(response.status_code, 200)

content = json.loads(response.content.decode('utf-8'))
Expand Down Expand Up @@ -244,11 +244,11 @@ def test_with_other_users_orders(self):
""" The view should only return orders for the authenticated users. """
other_user = self.create_user()
create_order(site=self.site, user=other_user)
response = self.client.get(self.path, headers={"authorization": self.token})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)
self.assert_empty_result_response(response)

order = create_order(site=self.site, user=self.user)
response = self.client.get(self.path, headers={"authorization": self.token})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)
content = json.loads(response.content.decode('utf-8'))
self.assertEqual(content['count'], 1)
self.assertEqual(content['results'][0]['number'], str(order.number))
Expand All @@ -263,7 +263,7 @@ def test_staff_superuser(self, is_staff, is_superuser):
admin_user = self.create_user(is_staff=is_staff, is_superuser=is_superuser)
order = create_order(site=self.site, user=self.user)

response = self.client.get(self.path, headers={"authorization": self.generate_jwt_token_header(admin_user)})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.generate_jwt_token_header(admin_user))
content = json.loads(response.content.decode('utf-8'))
self.assertEqual(content['count'], 1)
self.assertEqual(content['results'][0]['number'], str(order.number))
Expand All @@ -273,7 +273,7 @@ def test_user_information(self):
admin_user = self.create_user(is_staff=True, is_superuser=True)
order = create_order(site=self.site, user=admin_user)

response = self.client.get(self.path, headers={"authorization": self.generate_jwt_token_header(admin_user)})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.generate_jwt_token_header(admin_user))
content = json.loads(response.content.decode('utf-8'))
self.assertEqual(content['count'], 1)
self.assertEqual(content['results'][0]['number'], str(order.number))
Expand Down Expand Up @@ -319,7 +319,7 @@ def test_orders_with_multiple_sites(self):
"""
order = create_order(site=self.site, user=self.user)
second_order = create_order(site=self.site, user=self.user)
response = self.client.get(self.path, headers={"authorization": self.token})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)
self.assertEqual(response.status_code, 200)
content = json.loads(response.content.decode('utf-8'))

Expand All @@ -345,7 +345,7 @@ def test_orders_with_multiple_sites(self):
self.request.site = site_configuration.site
self.client = self.client_class(SERVER_NAME=domain)

response = self.client.get(self.path, headers={"authorization": self.token})
response = self.client.get(self.path, HTTP_AUTHORIZATION=self.token)
self.assertEqual(response.status_code, 200)
content = json.loads(response.content.decode('utf-8'))

Expand Down
2 changes: 1 addition & 1 deletion ecommerce/extensions/api/v2/tests/views/test_payments.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def reset_site_config():

def assert_processor_list_matches(self, expected):
""" DRY helper. """
response = self.client.get(reverse('api:v2:payment:list_processors'), headers={"authorization": self.token})
response = self.client.get(reverse('api:v2:payment:list_processors'), HTTP_AUTHORIZATION=self.token)
self.assertEqual(response.status_code, 200)
self.assertSetEqual(set(response.json()), set(expected))

Expand Down
4 changes: 2 additions & 2 deletions ecommerce/extensions/api/v2/tests/views/test_refunds.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ def test_jwt_authentication(self):
data = self._get_data(self.user.username, self.course_id)
auth_header = self.generate_jwt_token_header(self.user)

response = self.client.post(self.path, data, JSON_CONTENT_TYPE, headers={"authorization": auth_header})
response = self.client.post(self.path, data, JSON_CONTENT_TYPE, HTTP_AUTHORIZATION=auth_header)
self.assert_ok_response(response)

@responses.activate
Expand All @@ -118,7 +118,7 @@ def test_oauth2_authentication(self):
auth_header = 'Bearer ' + self.DEFAULT_TOKEN
self.mock_user_info_response(username=self.user.username)

response = self.client.post(self.path, data, JSON_CONTENT_TYPE, headers={"authorization": auth_header})
response = self.client.post(self.path, data, JSON_CONTENT_TYPE, HTTP_AUTHORIZATION=auth_header)
self.assert_ok_response(response)

def test_session_authentication(self):
Expand Down

0 comments on commit ba7b3d4

Please sign in to comment.