Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Little css for search page, solve validation problems #367

Merged
merged 3 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ const CompanyCard = ({ companyData, isAuthorized, userData }) => {
<div className={styles['company-card__block']}>
<div className={styles['company-card__image-frame']}>
{companyData.banner_image ? (
<img src={companyData.banner_image} alt="Company Banner" />
<img src={companyData.banner_image} alt="Company Banner" className={styles['company-card__image']}/>
) : (
<img
className={styles['company-card__image']}
className={styles['company-card__empty-image']}
src={`${process.env.REACT_APP_PUBLIC_URL}/svg/profile-view-image-empty.svg`}
alt={companyData.name}
/>
Expand Down Expand Up @@ -171,11 +171,15 @@ const CompanyCard = ({ companyData, isAuthorized, userData }) => {
</div>
<div className={styles['company-card__logo']}>
<div className={styles['company-card__logo-ellipse']}>
<img
{companyData.logo_image ? (
<img src={companyData.logo_image} alt="Logo" className={styles['company-card__logo-image']}/>
) : (
<img
className={styles['company-card__logo-image']}
src={`${process.env.REACT_APP_PUBLIC_URL}/companies-logos/1.png`}
alt=""
/>
)}
</div>
</div>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
width: 360px;
height: 220px;
}
.company-card__image {
.company-card__empty-image {
width: 103px;
height: 80px;
flex-shrink: 0;
Expand All @@ -30,6 +30,15 @@
object-fit: cover;
opacity: 0.7;
}
.company-card__image {
width: 360px;
height: 220px;
border-top-left-radius: 11px;
border-top-right-radius: 11px;
flex-shrink: 0;
object-fit: cover;
opacity: 0.7;
}
.company-card__text-block {
display: flex;
padding: 20px 16.02px;
Expand Down
Binary file added images/tests/img/img_2mb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tests/img/img_300kb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/tests/img/img_7mb.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 12 additions & 21 deletions images/tests/test_banner.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from rest_framework.test import APITestCase

import os
from io import BytesIO
from PIL import Image

from authentication.factories import UserFactory
from profiles.factories import (
Expand All @@ -14,20 +12,15 @@


class TestBannerChange(APITestCase):
@staticmethod
def _generate_image(ext, size=(100, 100)):
"""for mocking png and jpeg files"""
file = BytesIO()
image = Image.new("RGB", size=size)
formatext = ext.upper()
image.save(file, formatext)
file.name = f"test.{formatext}"
file.seek(0)
return file

def setUp(self) -> None:
self.right_image = self._generate_image("jpeg", (100, 100))
self.wrong_image = self._generate_image("png", (8000, 10000))
self.right_image = open(
os.path.join(os.getcwd(), "images", "tests", "img", "img_2mb.png"),
"rb",
)
self.wrong_image = open(
os.path.join(os.getcwd(), "images", "tests", "img", "img_7mb.png"),
"rb",
)

self.user = UserFactory(email="[email protected]")
self.company_dnipro = ProfileStartupFactory.create(
Expand All @@ -39,10 +32,8 @@ def setUp(self) -> None:
self.company_kyiv = ProfileCompanyFactory(name="Kyivbud")

def tearDown(self) -> None:
if os.path.exists(self.right_image.name):
os.remove(self.right_image.name)
if os.path.exists(self.wrong_image.name):
os.remove(self.wrong_image.name)
self.right_image.close()
self.wrong_image.close()

def test_get_empty_banner_unauthorized(self):
response = self.client.get(path=f"/api/banner/{self.company_kyiv.id}/")
Expand All @@ -56,7 +47,7 @@ def test_get_banner_unauthorized(self):
self.assertEqual(200, response.status_code)
self.assertEqual(
{
"banner_image": f"http://testserver/media/banners/{self.right_image.name}"
"banner_image": f"http://testserver/media/banners{self.right_image.name}"
},
response.json(),
)
Expand All @@ -69,7 +60,7 @@ def test_get_banner_authorized(self):
self.assertEqual(200, response.status_code)
self.assertEqual(
{
"banner_image": f"http://testserver/media/banners/{self.right_image.name}"
"banner_image": f"http://testserver/media/banners{self.right_image.name}"
},
response.json(),
)
Expand Down
36 changes: 14 additions & 22 deletions images/tests/test_logo.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from rest_framework.test import APITestCase

import os
from io import BytesIO
from PIL import Image

from authentication.factories import UserFactory
from profiles.factories import (
Expand All @@ -14,21 +12,17 @@


class TestLogoChange(APITestCase):
@staticmethod
def _generate_image(ext, size=(100, 100)):
"""for mocking png and jpeg files"""
file = BytesIO()
image = Image.new("RGB", size=size)
formatext = ext.upper()
image.save(file, formatext)
file.name = f"test.{formatext}"
file.seek(0)
return file

def setUp(self) -> None:
self.right_image = self._generate_image("jpeg", (100, 100))
self.wrong_image = self._generate_image("png", (8000, 10000))

self.right_image = open(
os.path.join(
os.getcwd(), "images", "tests", "img", "img_300kb.png"
),
"rb",
)
self.wrong_image = open(
os.path.join(os.getcwd(), "images", "tests", "img", "img_7mb.png"),
"rb",
)
self.user = UserFactory(email="[email protected]")
self.company_dnipro = ProfileStartupFactory.create(
person=self.user,
Expand All @@ -39,10 +33,8 @@ def setUp(self) -> None:
self.company_kyiv = ProfileCompanyFactory(name="Kyivbud")

def tearDown(self) -> None:
if os.path.exists(self.right_image.name):
os.remove(self.right_image.name)
if os.path.exists(self.wrong_image.name):
os.remove(self.wrong_image.name)
self.right_image.close()
self.wrong_image.close()

def test_get_empty_logo_unauthorized(self):
response = self.client.get(path=f"/api/logo/{self.company_kyiv.id}/")
Expand All @@ -54,7 +46,7 @@ def test_get_logo_unauthorized(self):
self.assertEqual(200, response.status_code)
self.assertEqual(
{
"logo_image": f"http://testserver/media/logos/{self.right_image.name}"
"logo_image": f"http://testserver/media/logos{self.right_image.name}"
},
response.json(),
)
Expand All @@ -65,7 +57,7 @@ def test_get_logo_authorized(self):
self.assertEqual(200, response.status_code)
self.assertEqual(
{
"logo_image": f"http://testserver/media/logos/{self.right_image.name}"
"logo_image": f"http://testserver/media/logos{self.right_image.name}"
},
response.json(),
)
Expand Down
40 changes: 18 additions & 22 deletions profiles/tests/test_crud_profile.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import os
from io import BytesIO

from PIL import Image
from rest_framework import status
from rest_framework.test import APITestCase

Expand All @@ -17,21 +15,22 @@


class TestProfileDetailAPIView(APITestCase):
@staticmethod
def _generate_image(ext, size=(100, 100)):
"""for mocking png and jpeg files"""
file = BytesIO()
image = Image.new("RGB", size=size)
formatext = ext.upper()
image.save(file, formatext)
file.name = f"test.{formatext}"
file.seek(0)
return file

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.right_image = open(
os.path.join(os.getcwd(), "images", "tests", "img", "img_2mb.png"),
"rb",
)
self.wrong_image = open(
os.path.join(os.getcwd(), "images", "tests", "img", "img_7mb.png"),
"rb",
)
self.right_image_logo = open(
os.path.join(
os.getcwd(), "images", "tests", "img", "img_300kb.png"
),
"rb",
)

self.user = UserFactory(email="[email protected]")
self.profile = ProfileStartupFactory.create(
person=self.user,
Expand All @@ -41,12 +40,9 @@ def setUp(self) -> None:
)

def tearDown(self) -> None:
if os.path.exists(self.right_image.name):
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)
self.right_image.close()
self.wrong_image.close()
self.right_image_logo.close()

# GET requests section
def test_get_profile_nonexistent(self):
Expand Down
11 changes: 6 additions & 5 deletions validation/validate_image.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
from django.core.exceptions import ValidationError
from PIL import Image
import sys

MAX_ALLOWED_BANNER_IMAGE_SIZE = 50 * 1024
MAX_ALLOWED_LOGO_IMAGE_SIZE = 10 * 1024
Image.MAX_IMAGE_PIXELS = None

MAX_ALLOWED_BANNER_IMAGE_SIZE = 5 * 1024 * 1024
MAX_ALLOWED_LOGO_IMAGE_SIZE = 1 * 1024 * 1024
# ToDo: discuss problem with MB-sized pictures with mentors, experts and BAs


Expand All @@ -18,12 +19,12 @@ def validate_image_format(image: Image):


def validate_image_size(image_file):
max_size = sys.getsizeof(image_file.file)
max_size = image_file.size
if max_size > MAX_ALLOWED_BANNER_IMAGE_SIZE:
raise ValidationError("Image size exceeds the maximum allowed (50MB).")


def validate_logo_size(image_file):
max_size = sys.getsizeof(image_file.file)
max_size = image_file.size
if max_size > MAX_ALLOWED_LOGO_IMAGE_SIZE:
raise ValidationError("Image size exceeds the maximum allowed (10MB).")
Loading