generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
model, serializers, tests for CRUD and search
- Loading branch information
1 parent
a3c7a8d
commit 4986949
Showing
6 changed files
with
116 additions
and
1 deletion.
There are no files selected for viewing
24 changes: 24 additions & 0 deletions
24
profiles/migrations/0005_profile_logo_image_alter_profile_banner_image.py
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Generated by Django 4.2.4 on 2023-12-09 13:17 | ||
|
||
from django.db import migrations, models | ||
import validation.validate_image | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('profiles', '0004_alter_viewedcompany_unique_together_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='profile', | ||
name='logo_image', | ||
field=models.ImageField(null=True, upload_to='logos', validators=[validation.validate_image.validate_image_format, validation.validate_image.validate_image_size]), | ||
), | ||
migrations.AlterField( | ||
model_name='profile', | ||
name='banner_image', | ||
field=models.ImageField(null=True, upload_to='banners', validators=[validation.validate_image.validate_image_format, validation.validate_image.validate_image_size]), | ||
), | ||
] |
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
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
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 |
---|---|---|
|
@@ -30,6 +30,7 @@ def _generate_image(ext, size=(100, 100)): | |
|
||
def setUp(self) -> None: | ||
self.right_image = self._generate_image("jpeg", (100, 100)) | ||
self.right_image_logo = self._generate_image("jpeg", (80, 80)) | ||
self.wrong_image = self._generate_image("png", (7000, 7000)) | ||
self.user = UserFactory(email="[email protected]") | ||
self.profile = ProfileStartupFactory.create( | ||
|
@@ -44,6 +45,8 @@ def tearDown(self) -> None: | |
os.remove(self.right_image.name) | ||
if os.path.exists(self.wrong_image.name): | ||
os.remove(self.wrong_image.name) | ||
if os.path.exists(self.right_image_logo.name): | ||
os.remove(self.right_image_logo.name) | ||
|
||
# GET requests section | ||
def test_get_profile_nonexistent(self): | ||
|
@@ -128,6 +131,11 @@ def test_get_profile_unauthorized(self): | |
response.data.get("banner_image"), | ||
msg="Banner images do not match.", | ||
) | ||
self.assertEqual( | ||
self.profile.logo_image, | ||
response.data.get("logo_image"), | ||
msg="Logo images do not match.", | ||
) | ||
self.assertFalse( | ||
response.data.get("categories"), msg="Categories do not match." | ||
) | ||
|
@@ -214,6 +222,11 @@ def test_get_profile_authorized_not_owner(self): | |
response.data.get("banner_image"), | ||
msg="Banner images do not match.", | ||
) | ||
self.assertEqual( | ||
self.profile.logo_image, | ||
response.data.get("logo_image"), | ||
msg="Logo images do not match.", | ||
) | ||
self.assertFalse( | ||
response.data.get("categories"), msg="Categories do not match." | ||
) | ||
|
@@ -311,6 +324,11 @@ def test_get_profile_authorized_owner(self): | |
response.data.get("banner_image"), | ||
msg="Banner images do not match.", | ||
) | ||
self.assertEqual( | ||
self.profile.logo_image, | ||
response.data.get("logo_image"), | ||
msg="Logo images do not match.", | ||
) | ||
self.assertEqual( | ||
list(self.profile.categories.all()), | ||
response.data.get("categories"), | ||
|
@@ -462,7 +480,7 @@ def test_partial_update_authorized_not_owner(self): | |
) | ||
self.assertEqual(status.HTTP_403_FORBIDDEN, response.status_code) | ||
|
||
def test_partial_update_profile_with_wrong_image(self): | ||
def test_partial_update_profile_with_wrong_image_banner(self): | ||
self.client.force_authenticate(self.user) | ||
|
||
response = self.client.patch( | ||
|
@@ -476,6 +494,20 @@ def test_partial_update_profile_with_wrong_image(self): | |
) | ||
self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) | ||
|
||
def test_partial_update_profile_with_wrong_image_logo(self): | ||
self.client.force_authenticate(self.user) | ||
|
||
response = self.client.patch( | ||
path="/api/profiles/{profile_id}".format( | ||
profile_id=self.profile.id | ||
), | ||
data={ | ||
"logo_image": f"/Forum/{self.wrong_image}", | ||
"founded": 2005, | ||
}, | ||
) | ||
self.assertEqual(status.HTTP_400_BAD_REQUEST, response.status_code) | ||
|
||
def test_partial_update_profile_unauthorized(self): | ||
response = self.client.patch( | ||
path="/api/profiles/{profile_id}".format( | ||
|
@@ -563,6 +595,7 @@ def test_full_update_profile_authorized_with_full_data(self): | |
"product_info": "Product info from test case", | ||
"address": "Kyiv", | ||
"banner_image": self.right_image, | ||
"logo_image": self.right_image_logo, | ||
"person_position": "director", | ||
"startup_idea": "StartUp idea from test case", | ||
"is_startup": True, | ||
|
@@ -596,6 +629,7 @@ def test_full_update_profile_unauthorized(self): | |
"product_info": "Product info from test case", | ||
"address": "Kyiv", | ||
"banner_image": self.right_image, | ||
"logo_image": self.right_image_logo, | ||
"person_position": "director", | ||
"startup_idea": "StartUp idea from test case", | ||
"is_startup": True, | ||
|
@@ -624,6 +658,7 @@ def test_full_update_profile_not_exist(self): | |
"product_info": "Product info from test case", | ||
"address": "Kyiv", | ||
"banner_image": self.right_image, | ||
"logo_image": self.right_image_logo, | ||
"person_position": "director", | ||
"startup_idea": "StartUp idea from test case", | ||
"is_startup": True, | ||
|
@@ -652,6 +687,7 @@ def test_full_update_profile_wrong_data(self): | |
"product_info": "Product info from test case", | ||
"address": "Kyiv", | ||
"banner_image": self.wrong_image, | ||
"logo_image": self.right_image_logo, | ||
"person_position": "director", | ||
"startup_idea": "StartUp idea from test case", | ||
"is_startup": True, | ||
|
@@ -682,6 +718,7 @@ def test_full_update_authorized_not_owner(self): | |
"product_info": "Product info from test case", | ||
"address": "Kyiv", | ||
"banner_image": self.right_image, | ||
"logo_image": self.right_image_logo, | ||
"person_position": "director", | ||
"startup_idea": "StartUp idea from test case", | ||
"is_startup": True, | ||
|
@@ -754,6 +791,8 @@ def test_create_profile_authorized_full_data(self): | |
"startup_idea": "StartUp idea from test case", | ||
"is_startup": True, | ||
"is_registered": False, | ||
"banner_image": self.right_image, | ||
"logo_image": self.right_image_logo, | ||
"name": "Comp name from test case", | ||
"categories": [category.id], | ||
"activities": [activity.id], | ||
|
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 |
---|---|---|
|
@@ -18,4 +18,5 @@ class Meta: | |
"service_info", | ||
"address", | ||
"banner_image", | ||
"logo_image", | ||
) |
Oops, something went wrong.