Skip to content

Commit

Permalink
[POLA-3] Rozszerzony opis firmy - Dodanie pola website_url do modelu … (
Browse files Browse the repository at this point in the history
#4010)

* [POLA-3] Rozszerzony opis firmy - Dodanie pola website_url do modelu Brand

* [POLA-3] Tests development

---------

Co-authored-by: piemar <m.pieczynski@macopedia.com>
  • Loading branch information
piemar1 and piemar authored Nov 15, 2024
1 parent 781d07a commit 0a22ad1
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 6 deletions.
18 changes: 18 additions & 0 deletions pola/company/migrations/0033_brand_website_url.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.16 on 2024-06-21 10:26

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('company', '0032_alter_brand_logotype'),
]

operations = [
migrations.AddField(
model_name='brand',
name='website_url',
field=models.CharField(default='example.pl', max_length=128, verbose_name='URL marki'),
),
]
3 changes: 3 additions & 0 deletions pola/company/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,9 @@ class Brand(TimeStampedModel):
region_name='eu-central-1',
),
)
website_url = models.CharField(
max_length=128, null=False, blank=False, verbose_name=_("URL marki"), default="example.pl"
)

def __str__(self):
return self.common_name or self.name
Expand Down
3 changes: 2 additions & 1 deletion pola/logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@ def get_result_from_code(code, multiple_company_supported=False, report_as_objec

def serialize_brand(brand):
logotype_url = brand.logotype.url if brand.logotype else None
return {'name': str(brand), 'logotype_url': logotype_url}
website_url = brand.website_url if brand.website_url else None
return {'name': str(brand), 'logotype_url': logotype_url, 'website_url': website_url}


def handle_companies_when_multiple_companies_are_not_supported(
Expand Down
2 changes: 2 additions & 0 deletions pola/rpc_api/openapi-v1.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,8 @@ components:
logotype_url:
type: string
nullable: true
website_url:
type: string
required:
- name
- logotype_url
Expand Down
4 changes: 3 additions & 1 deletion pola/rpc_api/tests/test_views_v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,9 @@ def test_should_return_200_when_one_comand_in_brand_and_product(self):
self.maxDiff = None
self.assertEqual(
{
'all_company_brands': [{'logotype_url': None, 'name': p.brand.common_name}],
'all_company_brands': [
{'logotype_url': None, 'name': p.brand.common_name, 'website_url': p.brand.website_url}
],
'altText': None,
'card_type': 'type_white',
'code': '5900049011829',
Expand Down
1 change: 1 addition & 0 deletions pola/rpc_api/tests/test_views_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def test_should_return_200_when_product_with_brand_and_image(self):
'all_company_brands': [
{
'name': b.common_name,
'website_url': 'example.pl',
}
],
'product_id': p.pk,
Expand Down
10 changes: 6 additions & 4 deletions pola/tests/test_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,21 +404,23 @@ def test_display_brand_when_enabled_on_company(self):
company = CompanyFactory.create(description='test-description', display_brands_in_description=True)
product = ProductFactory.create(code=current_ean, company=company, brand=None)
BrandFactory.create(common_name="brand-1", company=company)
BrandFactory.create(common_name="brand-2", company=company)
BrandFactory.create(common_name="brand-2", company=company, website_url="test.pl")
BrandFactory.create(common_name="brand-3", company=company, website_url="moja_domena_testowa_123.com")

with mock.patch("pola.logic.get_by_code", return_value=product):
response = get_result_from_code(current_ean)

expected_response = (
{
'all_company_brands': [
{'logotype_url': None, 'name': 'brand-2'},
{'logotype_url': None, 'name': 'brand-1'},
{'logotype_url': None, 'name': 'brand-3', 'website_url': 'moja_domena_testowa_123.com'},
{'logotype_url': None, 'name': 'brand-2', 'website_url': 'test.pl'},
{'logotype_url': None, 'name': 'brand-1', 'website_url': 'example.pl'},
],
'altText': None,
'card_type': 'type_grey',
'code': TEST_EAN13,
'description': ('test-description\n' 'Ten producent psoiada marki: brand-1, brand-2.'),
'description': ('test-description\n' 'Ten producent psoiada marki: brand-1, brand-2, brand-3.'),
'is_friend': False,
'name': company.official_name,
'plCapital': None,
Expand Down

0 comments on commit 0a22ad1

Please sign in to comment.