Skip to content

Commit 3e3a843

Browse files
refactor(tests): Rename vars and clean up code
- Rename `signup_url` → `company_signup_url` and `user_signup` → `user_signup_url` - Replace unused variables with `_` placeholder - Remove unused imports
1 parent 3ec8a5d commit 3e3a843

19 files changed

+88
-70
lines changed

promo_code/business/tests/auth/base.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,12 @@ def setUpTestData(cls):
1515
'api-business:company-token-refresh',
1616
)
1717
cls.protected_url = django.urls.reverse('api-core:protected')
18-
cls.signup_url = django.urls.reverse('api-business:company-sign-up')
19-
cls.signin_url = django.urls.reverse('api-business:company-sign-in')
18+
cls.company_signup_url = django.urls.reverse(
19+
'api-business:company-sign-up',
20+
)
21+
cls.company_signin_url = django.urls.reverse(
22+
'api-business:company-sign-in',
23+
)
2024
cls.valid_data = {
2125
'name': 'Digital Marketing Solutions Inc.',
2226
'email': '[email protected]',

promo_code/business/tests/auth/test_authentication.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def test_signin_success(self):
2020
)
2121

2222
response = self.client.post(
23-
self.signin_url,
23+
self.company_signin_url,
2424
{
2525
'email': registration_data['email'],
2626
'password': registration_data['password'],

promo_code/business/tests/auth/test_registration.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TestCompanyRegistration(
1111
def test_registration_success(self):
1212
registration_data = {**self.valid_data, 'email': '[email protected]'}
1313
response = self.client.post(
14-
self.signup_url,
14+
self.company_signup_url,
1515
registration_data,
1616
format='json',
1717
)

promo_code/business/tests/auth/test_tokens.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def setUp(self):
2323

2424
def test_access_protected_view_with_valid_token(self):
2525
response = self.client.post(
26-
self.signin_url,
26+
self.company_signin_url,
2727
self.user_data,
2828
format='json',
2929
)
@@ -45,7 +45,7 @@ def test_registration_token_invalid_after_login(self):
4545
'name': 'Digital Marketing Solutions Inc.',
4646
}
4747
response = self.client.post(
48-
self.signup_url,
48+
self.company_signup_url,
4949
data,
5050
format='json',
5151
)
@@ -62,7 +62,7 @@ def test_registration_token_invalid_after_login(self):
6262

6363
login_data = {'email': data['email'], 'password': data['password']}
6464
response = self.client.post(
65-
self.signin_url,
65+
self.company_signin_url,
6666
login_data,
6767
format='json',
6868
)
@@ -214,14 +214,14 @@ def test_company_not_found(self):
214214

215215
def test_refresh_token_invalidation_after_new_login(self):
216216
first_login_response = self.client.post(
217-
self.signin_url,
217+
self.company_signin_url,
218218
self.company_data,
219219
format='json',
220220
)
221221
refresh_token_v1 = first_login_response.data['refresh']
222222

223223
second_login_response = self.client.post(
224-
self.signin_url,
224+
self.company_signin_url,
225225
self.company_data,
226226
format='json',
227227
)

promo_code/business/tests/auth/test_validation.py

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def test_duplicate_email_registration(self):
2222
)
2323

2424
response = self.client.post(
25-
self.signup_url,
25+
self.company_signup_url,
2626
self.valid_data,
2727
format='json',
2828
)
@@ -46,7 +46,11 @@ def test_duplicate_email_registration(self):
4646
)
4747
def test_invalid_password_cases(self, _, invalid_password):
4848
test_data = {**self.valid_data, 'password': invalid_password}
49-
response = self.client.post(self.signup_url, test_data, format='json')
49+
response = self.client.post(
50+
self.company_signup_url,
51+
test_data,
52+
format='json',
53+
)
5054
self.assertEqual(
5155
response.status_code,
5256
rest_framework.status.HTTP_400_BAD_REQUEST,
@@ -64,7 +68,11 @@ def test_invalid_password_cases(self, _, invalid_password):
6468
)
6569
def test_invalid_email_cases(self, _, invalid_email):
6670
test_data = {**self.valid_data, 'email': invalid_email}
67-
response = self.client.post(self.signup_url, test_data, format='json')
71+
response = self.client.post(
72+
self.company_signup_url,
73+
test_data,
74+
format='json',
75+
)
6876
self.assertEqual(
6977
response.status_code,
7078
rest_framework.status.HTTP_400_BAD_REQUEST,
@@ -73,7 +81,11 @@ def test_invalid_email_cases(self, _, invalid_email):
7381

7482
def test_short_company_name(self):
7583
test_data = {**self.valid_data, 'name': 'A'}
76-
response = self.client.post(self.signup_url, test_data, format='json')
84+
response = self.client.post(
85+
self.company_signup_url,
86+
test_data,
87+
format='json',
88+
)
7789
self.assertEqual(
7890
response.status_code,
7991
rest_framework.status.HTTP_400_BAD_REQUEST,
@@ -90,8 +102,12 @@ class InvalidCompanyAuthenticationTestCase(
90102
('empty_data', {}, ['email', 'password']),
91103
],
92104
)
93-
def test_missing_required_fields(self, case_name, data, expected_fields):
94-
response = self.client.post(self.signin_url, data, format='json')
105+
def test_missing_required_fields(self, _, data, expected_fields):
106+
response = self.client.post(
107+
self.company_signin_url,
108+
data,
109+
format='json',
110+
)
95111
self.assertEqual(
96112
response.status_code,
97113
rest_framework.status.HTTP_400_BAD_REQUEST,
@@ -109,7 +125,7 @@ def test_signin_invalid_password(self):
109125
'password': 'SuperInvalidPassword2000!',
110126
}
111127
response = self.client.post(
112-
self.signin_url,
128+
self.company_signin_url,
113129
data,
114130
format='json',
115131
)

promo_code/business/tests/promocodes/base.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import django.urls
2-
import rest_framework
3-
import rest_framework.status
42
import rest_framework.test
53

64
import business.models
@@ -14,8 +12,12 @@ def setUpTestData(cls):
1412
cls.promo_list_create_url = django.urls.reverse(
1513
'api-business:promo-list-create',
1614
)
17-
cls.signup_url = django.urls.reverse('api-business:company-sign-up')
18-
cls.signin_url = django.urls.reverse('api-business:company-sign-in')
15+
cls.company_signup_url = django.urls.reverse(
16+
'api-business:company-sign-up',
17+
)
18+
cls.company_signin_url = django.urls.reverse(
19+
'api-business:company-sign-in',
20+
)
1921

2022
cls.company1_data = {
2123
'name': 'Digital Marketing Solutions Inc.',
@@ -38,7 +40,7 @@ def setUpTestData(cls):
3840
)
3941

4042
response1 = cls.client.post(
41-
cls.signin_url,
43+
cls.company_signin_url,
4244
{
4345
'email': cls.company1_data['email'],
4446
'password': cls.company1_data['password'],
@@ -48,7 +50,7 @@ def setUpTestData(cls):
4850
cls.company1_token = response1.data['access']
4951

5052
response2 = cls.client.post(
51-
cls.signin_url,
53+
cls.company_signin_url,
5254
{
5355
'email': cls.company2_data['email'],
5456
'password': cls.company2_data['password'],

promo_code/business/tests/promocodes/validations/test_create_validation.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def test_create_promo_with_old_token(self):
2121
'password': 'SuperStrongPassword2000!',
2222
}
2323
reg_response = self.client.post(
24-
self.signup_url,
24+
self.company_signup_url,
2525
registration_data,
2626
format='json',
2727
)
2828
old_token = reg_response.data.get('token')
2929
self.client.post(
30-
self.signin_url,
30+
self.company_signin_url,
3131
{
3232
'email': registration_data['email'],
3333
'password': registration_data['password'],
@@ -94,7 +94,7 @@ def test_create_promo_with_old_token(self):
9494
),
9595
],
9696
)
97-
def test_missing_fields(self, name, payload):
97+
def test_missing_fields(self, _, payload):
9898
response = self.client.post(
9999
self.promo_list_create_url,
100100
payload,
@@ -349,7 +349,7 @@ def test_too_short_promo_common(self):
349349
),
350350
],
351351
)
352-
def test_invalid_type_payloads(self, name, payload):
352+
def test_invalid_type_payloads(self, _, payload):
353353
response = self.client.post(
354354
self.promo_list_create_url,
355355
payload,

promo_code/business/tests/promocodes/validations/test_detail_validation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def test_old_token_invalid_after_reauthentication(self):
5656
'password': self.company1_data['password'],
5757
}
5858
response = self.client.post(
59-
self.signin_url,
59+
self.company_signin_url,
6060
signin_payload,
6161
format='json',
6262
)

promo_code/business/tests/promocodes/validations/test_list_validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def test_get_promos_without_token(self):
4646
),
4747
],
4848
)
49-
def test_invalid_query_string_parameters(self, name, params):
49+
def test_invalid_query_string_parameters(self, _, params):
5050
response = self.client.get(self.promo_list_create_url, params)
5151
self.assertEqual(
5252
response.status_code,
@@ -65,7 +65,7 @@ def test_invalid_query_string_parameters(self, name, params):
6565
('empty_string_offset', {'offset': ''}),
6666
],
6767
)
68-
def test_invalid_numeric_parameters(self, name, params):
68+
def test_invalid_numeric_parameters(self, _, params):
6969
response = self.client.get(self.promo_list_create_url, params)
7070
self.assertEqual(
7171
response.status_code,

promo_code/user/tests/auth/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ def setUpTestData(cls):
1212
cls.client = rest_framework.test.APIClient()
1313
cls.protected_url = django.urls.reverse('api-core:protected')
1414
cls.refresh_url = django.urls.reverse('api-user:user-token-refresh')
15-
cls.signup_url = django.urls.reverse('api-user:sign-up')
16-
cls.signin_url = django.urls.reverse('api-user:sign-in')
15+
cls.user_signup_url = django.urls.reverse('api-user:user-sign-up')
16+
cls.user_signin_url = django.urls.reverse('api-user:user-sign-in')
1717

1818
def tearDown(self):
1919
user.models.User.objects.all().delete()

0 commit comments

Comments
 (0)