Skip to content

Commit 9b6074d

Browse files
Merge pull request #13 from RandomProgramm3r/develop
test: Add tests to the business app for creating promo codes. - Add tests for creating promo codes, validating input data, and for permissions - Separate tests into folders for future scaling - Add several fields to PromoCreateSerializer for better input data validation
2 parents 4e08396 + fc7324d commit 9b6074d

20 files changed

+722
-25
lines changed

.flake8

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[flake8]
22
max-line-length = 79
3-
application_import_names = promo_code, user, core
3+
application_import_names = promo_code, user, core, business
44
import-order-style = google
55
exclude = */migrations/, venv/, verdict.py, .venv/, env/, venv, .git, __pycache__
66
max-complexity = 10

.isort.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[settings]
22
profile = black
33
skip = migrations, venv/, venv
4-
known_first_party = promo_code, user, core
4+
known_first_party = promo_code, user, core, business
55
default_section = THIRDPARTY
66
force_sort_within_sections = true
77
line_length = 79

promo_code/business/permissions.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import business.models
21
import rest_framework.permissions
32

3+
import business.models
4+
45

56
class IsCompanyUser(rest_framework.permissions.BasePermission):
67
def has_permission(self, request, view):

promo_code/business/serializers.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import business.models as business_models
2-
import business.validators
31
import django.contrib.auth.password_validation
42
import django.core.exceptions
53
import django.core.validators
@@ -12,6 +10,9 @@
1210
import rest_framework_simplejwt.tokens
1311
import rest_framework_simplejwt.views
1412

13+
import business.models as business_models
14+
import business.validators
15+
1516

1617
class CompanySignUpSerializer(rest_framework.serializers.ModelSerializer):
1718
password = rest_framework.serializers.CharField(
@@ -147,6 +148,8 @@ class TargetSerializer(rest_framework.serializers.Serializer):
147148
allow_null=True,
148149
)
149150
country = rest_framework.serializers.CharField(
151+
max_length=2,
152+
min_length=2,
150153
required=False,
151154
allow_null=True,
152155
allow_blank=True,
@@ -173,7 +176,6 @@ def validate(self, data):
173176
{'age_until': 'Must be greater than or equal to age_from.'},
174177
)
175178

176-
# change validation
177179
country = data.get('country')
178180
if country:
179181
country = country.strip().upper()
@@ -189,6 +191,18 @@ def validate(self, data):
189191

190192

191193
class PromoCreateSerializer(rest_framework.serializers.ModelSerializer):
194+
description = rest_framework.serializers.CharField(
195+
min_length=10,
196+
max_length=300,
197+
required=True,
198+
)
199+
image_url = rest_framework.serializers.CharField(
200+
required=False,
201+
max_length=350,
202+
validators=[
203+
django.core.validators.URLValidator(schemes=['http', 'https']),
204+
],
205+
)
192206
target = TargetSerializer(required=True)
193207
promo_common = rest_framework.serializers.CharField(
194208
min_length=5,
@@ -220,10 +234,6 @@ class Meta:
220234
'promo_common',
221235
'promo_unique',
222236
)
223-
extra_kwargs = {
224-
'description': {'min_length': 10, 'max_length': 300},
225-
'image_url': {'max_length': 350},
226-
}
227237

228238
def validate(self, data):
229239
mode = data.get('mode')

promo_code/business/tests/auth/base.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import business.models
21
import django.urls
32
import rest_framework
43
import rest_framework.status
54
import rest_framework.test
65

6+
import business.models
7+
78

89
class BaseBusinessAuthTestCase(rest_framework.test.APITestCase):
910
@classmethod

promo_code/business/tests/auth/test_authentication.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import business.models
2-
import business.tests.auth.base
31
import rest_framework.status
42
import rest_framework.test
53

4+
import business.models
5+
import business.tests.auth.base
6+
67

78
class AuthenticationTests(business.tests.auth.base.BaseBusinessAuthTestCase):
89
def test_signin_success(self):

promo_code/business/tests/auth/test_registration.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import business.models
2-
import business.tests.auth.base
31
import rest_framework.status
42
import rest_framework.test
53

4+
import business.models
5+
import business.tests.auth.base
6+
67

78
class TestCompanyRegistration(
89
business.tests.auth.base.BaseBusinessAuthTestCase,

promo_code/business/tests/auth/test_tokens.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import business.models
2-
import business.tests.auth.base
31
import rest_framework.status
42
import rest_framework.test
53
import rest_framework_simplejwt.tokens
64

5+
import business.models
6+
import business.tests.auth.base
77
import user.models
88

99

promo_code/business/tests/auth/test_validation.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1-
import business.models
2-
import business.tests.auth.base
31
import parameterized
42
import rest_framework.status
53
import rest_framework.test
64

5+
import business.models
6+
import business.tests.auth.base
7+
78

89
class InvalidCompanyRegistrationTestCase(
910
business.tests.auth.base.BaseBusinessAuthTestCase,

promo_code/business/tests/promocodes/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)