Skip to content

Commit 05bf57d

Browse files
committed
Linter refactoring
1 parent 76224ee commit 05bf57d

File tree

1 file changed

+27
-54
lines changed

1 file changed

+27
-54
lines changed

oscarapi/tests/unit/testbasket.py

+27-54
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ def test_basket_api_create_not_possible(self):
5151

5252
# authenticated
5353
self.login("nobody", "nobody")
54-
data = {"owner": "http://testserver%s" %
55-
reverse("user-detail", args=[2])}
54+
data = {"owner": "http://testserver%s" % reverse("user-detail", args=[2])}
5655

5756
self.response = self.client.post(
5857
url, json.dumps(data), content_type="application/json"
@@ -64,8 +63,7 @@ def test_basket_api_create_not_possible(self):
6463
# admin
6564
self.login("admin", "admin")
6665

67-
data = {"owner": "http://testserver%s" %
68-
reverse("user-detail", args=[1])}
66+
data = {"owner": "http://testserver%s" % reverse("user-detail", args=[1])}
6967
self.response = self.client.post(
7068
url, json.dumps(data), content_type="application/json"
7169
)
@@ -128,27 +126,23 @@ def test_retrieve_basket_header(self):
128126

129127
# authenticated
130128
self.hlogin("nobody", "nobody", session_id="nobody")
131-
self.response = self.get(
132-
"api-basket", session_id="nobody", authenticated=True)
129+
self.response = self.get("api-basket", session_id="nobody", authenticated=True)
133130
self.response.assertStatusEqual(200)
134131
self.response.assertObjectIdEqual("owner", 2)
135132
basket_id = self.response["id"]
136133

137-
self.response = self.get(
138-
"api-basket", session_id="nobody", authenticated=True)
134+
self.response = self.get("api-basket", session_id="nobody", authenticated=True)
139135
self.response.assertStatusEqual(200)
140136
self.response.assertValueEqual("id", basket_id)
141137

142138
# admin
143139
self.hlogin("admin", "admin", session_id="admin")
144-
self.response = self.get(
145-
"api-basket", session_id="admin", authenticated=True)
140+
self.response = self.get("api-basket", session_id="admin", authenticated=True)
146141
self.response.assertStatusEqual(200)
147142
self.response.assertObjectIdEqual("owner", 1)
148143
basket_id = self.response["id"]
149144

150-
self.response = self.get(
151-
"api-basket", session_id="admin", authenticated=True)
145+
self.response = self.get("api-basket", session_id="admin", authenticated=True)
152146
self.response.assertStatusEqual(200)
153147
self.response.assertValueEqual("id", basket_id)
154148

@@ -242,8 +236,7 @@ def test_basket_read_permissions(self):
242236

243237
url = reverse("basket-lines-list", args=(1,))
244238
self.response = self.client.get(url)
245-
self.response.assertStatusEqual(
246-
403, "Users not access other peoples baskets.")
239+
self.response.assertStatusEqual(403, "Users not access other peoples baskets.")
247240

248241
self.assertEqual(
249242
Basket.objects.count(),
@@ -295,8 +288,7 @@ def test_basket_read_permissions_header(self):
295288

296289
# now try for authenticated user.
297290
self.hlogin("nobody", "nobody", session_id="nobody")
298-
self.response = self.get(
299-
"api-basket", session_id="nobody", authenticated=True)
291+
self.response = self.get("api-basket", session_id="nobody", authenticated=True)
300292
self.response.assertStatusEqual(200)
301293

302294
# try to access the urls in the response.
@@ -331,8 +323,7 @@ def test_basket_read_permissions_header(self):
331323
)
332324

333325
self.hlogin("admin", "admin", session_id="admin")
334-
self.response = self.get(
335-
"api-basket", session_id="admin", authenticated=True)
326+
self.response = self.get("api-basket", session_id="admin", authenticated=True)
336327
self.response.assertStatusEqual(200)
337328

338329
# try to access the urls in the response.
@@ -571,8 +562,7 @@ def test_basket_write_permissions_header_authenticated(self):
571562

572563
# now try for authenticated user.
573564
self.hlogin("nobody", "nobody", session_id="nobody")
574-
self.response = self.get(
575-
"api-basket", session_id="nobody", authenticated=True)
565+
self.response = self.get("api-basket", session_id="nobody", authenticated=True)
576566
self.response.assertStatusEqual(200)
577567

578568
# try to access the urls in the response.
@@ -618,13 +608,11 @@ def test_basket_write_permissions_header_authenticated(self):
618608
self.response.assertStatusEqual(201)
619609

620610
# throw the basket away
621-
self.response = self.delete(
622-
url, session_id="nobody", authenticated=True)
611+
self.response = self.delete(url, session_id="nobody", authenticated=True)
623612
self.response.assertStatusEqual(204)
624613

625614
# now lets start messing around
626-
self.response = self.get(
627-
"api-basket", session_id="nobody", authenticated=True)
615+
self.response = self.get("api-basket", session_id="nobody", authenticated=True)
628616
self.response.assertStatusEqual(200)
629617
basket_id = self.response["id"]
630618

@@ -664,8 +652,7 @@ def test_basket_write_permissions_header_authenticated(self):
664652
self.response.assertStatusEqual(403)
665653

666654
# try to delete someone else's basket
667-
self.response = self.delete(
668-
url, session_id="nobody", authenticated=True)
655+
self.response = self.delete(url, session_id="nobody", authenticated=True)
669656
self.response.assertStatusEqual(403)
670657

671658
# try adding lines to someone else's basket
@@ -754,8 +741,7 @@ def test_basket_write_permissions_admin(self):
754741

755742
# try to write to someone else's basket by sending the primary key
756743
# along.
757-
self.response = self.put(
758-
url, status="Saved", id=somebody_basket_id)
744+
self.response = self.put(url, status="Saved", id=somebody_basket_id)
759745
self.response.assertStatusEqual(200)
760746
self.response.assertValueEqual(
761747
"id", basket_id, "Primary key value can not be changed."
@@ -791,8 +777,7 @@ def test_basket_write_permissions_header_admin(self):
791777

792778
# now try for authenticated user.
793779
self.hlogin("admin", "admin", session_id="admin")
794-
self.response = self.get(
795-
"api-basket", session_id="admin", authenticated=True)
780+
self.response = self.get("api-basket", session_id="admin", authenticated=True)
796781
self.response.assertStatusEqual(200)
797782

798783
# try to access the urls in the response.
@@ -838,13 +823,11 @@ def test_basket_write_permissions_header_admin(self):
838823
self.response.assertStatusEqual(201)
839824

840825
# throw the basket away
841-
self.response = self.delete(
842-
url, session_id="admin", authenticated=True)
826+
self.response = self.delete(url, session_id="admin", authenticated=True)
843827
self.response.assertStatusEqual(204)
844828

845829
# now lets start messing around
846-
self.response = self.get(
847-
"api-basket", session_id="admin", authenticated=True)
830+
self.response = self.get("api-basket", session_id="admin", authenticated=True)
848831
self.response.assertStatusEqual(200)
849832
basket_id = self.response["id"]
850833

@@ -901,8 +884,7 @@ def test_basket_write_permissions_header_admin(self):
901884
self.response.assertStatusEqual(403)
902885

903886
# try to delete someone else's basket
904-
self.response = self.delete(
905-
url, session_id="admin", authenticated=True)
887+
self.response = self.delete(url, session_id="admin", authenticated=True)
906888
self.response.assertStatusEqual(403)
907889

908890
def test_add_product_anonymous(self):
@@ -949,8 +931,7 @@ def test_add_product_basket_addition_signal_send(self, mock):
949931
self.assertTrue(mock.called)
950932

951933
signal_arguments = mock.call_args[1]
952-
self.assertEqual(
953-
signal_arguments["product"], Product.objects.get(pk=1))
934+
self.assertEqual(signal_arguments["product"], Product.objects.get(pk=1))
954935
self.assertEqual(signal_arguments["user"].username, "nobody")
955936

956937
# see if we can get the basket from the request
@@ -974,8 +955,7 @@ def test_basket_line_permissions(self):
974955

975956
self.response = self.get(line0url)
976957
self.response.assertStatusEqual(200)
977-
self.response.assertValueEqual(
978-
"product", "http://testserver/api/products/1/")
958+
self.response.assertValueEqual("product", "http://testserver/api/products/1/")
979959
self.response.assertValueEqual("quantity", 5)
980960

981961
# now let's try to cheat
@@ -986,8 +966,7 @@ def test_basket_line_permissions(self):
986966
def test_basket_line_permissions_header(self):
987967
"A user's Basket lines can not be viewed by another user in any way, even with header authentication"
988968
self.hlogin("nobody", "nobody", session_id="nobody")
989-
self.response = self.get(
990-
"api-basket", session_id="nobody", authenticated=True)
969+
self.response = self.get("api-basket", session_id="nobody", authenticated=True)
991970
self.response.assertStatusEqual(200)
992971

993972
self.response = self.post(
@@ -1004,17 +983,14 @@ def test_basket_line_permissions_header(self):
1004983
line0 = self.response.body[0]
1005984
line0url = line0["url"]
1006985

1007-
self.response = self.get(
1008-
line0url, session_id="nobody", authenticated=True)
986+
self.response = self.get(line0url, session_id="nobody", authenticated=True)
1009987
self.response.assertStatusEqual(200)
1010-
self.response.assertValueEqual(
1011-
"product", "http://testserver/api/products/1/")
988+
self.response.assertValueEqual("product", "http://testserver/api/products/1/")
1012989
self.response.assertValueEqual("quantity", 5)
1013990

1014991
# now let's try to cheat
1015992
self.hlogin("somebody", "somebody", session_id="somebody")
1016-
self.response = self.get(
1017-
line0url, session_id="somebody", authenticated=True)
993+
self.response = self.get(line0url, session_id="somebody", authenticated=True)
1018994
self.response.assertStatusEqual(404)
1019995

1020996
def test_frozen_basket_can_not_be_accessed(self):
@@ -1035,8 +1011,7 @@ def test_frozen_basket_can_not_be_accessed(self):
10351011
def test_frozen_basket_can_not_be_accessed_header(self):
10361012
"Prove that frozen baskets can no longer be accessed by the user, even with header authentication"
10371013
self.hlogin("nobody", "nobody", session_id="nobody")
1038-
self.response = self.get(
1039-
"api-basket", session_id="nobody", authenticated=True)
1014+
self.response = self.get("api-basket", session_id="nobody", authenticated=True)
10401015
self.response.assertStatusEqual(200)
10411016
self.response.assertValueEqual("status", "Open")
10421017

@@ -1377,17 +1352,15 @@ def test_basket_login_logout(self):
13771352
self.client.cookies,
13781353
"An basket cookie should have been created",
13791354
)
1380-
self.assertStartsWith(
1381-
self.client.cookies["oscar_open_basket"].value, "1")
1355+
self.assertStartsWith(self.client.cookies["oscar_open_basket"].value, "1")
13821356

13831357
# retrieve the basket with oscarapi.
13841358
self.response = self.get("api-basket")
13851359
self.response.assertValueEqual(
13861360
"owner", None, "The basket should not have an owner"
13871361
)
13881362
self.response.assertValueEqual("id", 1)
1389-
self.assertStartsWith(
1390-
self.client.cookies["oscar_open_basket"].value, "1")
1363+
self.assertStartsWith(self.client.cookies["oscar_open_basket"].value, "1")
13911364

13921365
# now lets log in with oscarapi
13931366
response = self.post("api-login", username="nobody", password="nobody")

0 commit comments

Comments
 (0)