Skip to content

Commit

Permalink
Merge pull request #800 from Studio-Yandex-Practicum/bugfix/hide_unpu…
Browse files Browse the repository at this point in the history
…blished_plays_in-plays_block

Do not serialize unpublished plays
  • Loading branch information
AntonZelinsky authored Sep 9, 2024
2 parents d8f182a + baf7f4b commit 7446bdc
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def test_blog_item_detail_plays_block_content_fields(client, complex_blog_item):

assert playsblock_content_item.get("title"), "У блока с пьесами должен быть заголовок."
assert playsblock_content_item.get("items"), "У блока с пьесами должен быть массив элементов (пьес)."
assert len(playsblock_content_item.get("items")) == 3, "Ожидалось 3 пьесы в блоке с пьесами."
assert len(playsblock_content_item.get("items")) == 3, "Ожидалось 3 опубликованные пьесы в блоке с пьесами."

first_play = playsblock_content_item.get("items")[0]
expected_play_fields_in_order = (
Expand Down
3 changes: 2 additions & 1 deletion apps/content_pages/factories/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from apps.content_pages.factories.content_array_items import (
ContentPersonRoleFactory,
ExtendedPersonFactory,
NonpublishedOrderedPlayFactory,
OrderedEventFactory,
OrderedImageFactory,
OrderedPlayFactory,
OrderedVideoFactory,
PublishedOrderedPlayFactory,
)
from apps.content_pages.factories.content_arrays import (
EventsBlockFactory,
Expand Down
21 changes: 19 additions & 2 deletions apps/content_pages/factories/content_array_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def item(self):


@restrict_factory(general=(Play,))
class OrderedPlayFactory(factory.django.DjangoModelFactory):
class PublishedOrderedPlayFactory(factory.django.DjangoModelFactory):
"""Create Play with order for block.
Order in factory assume that there are not more than 3 ordered plays in a block.
Expand All @@ -126,7 +126,24 @@ class Meta:

@factory.lazy_attribute
def item(self):
return get_random_objects_by_queryset(Play.objects.filter(other_play=False))
return get_random_objects_by_queryset(Play.objects.filter(other_play=False, published=True))


@restrict_factory(general=(Play,))
class NonpublishedOrderedPlayFactory(factory.django.DjangoModelFactory):
"""Create Play with order for block.
Order in factory assume that there are not more than 3 ordered plays in a block.
"""

class Meta:
model = OrderedPlay

order = factory.Sequence(lambda n: (n % 3 + 1))

@factory.lazy_attribute
def item(self):
return get_random_objects_by_queryset(Play.objects.filter(other_play=False, published=False))


class OrderedVideoFactory(factory.django.DjangoModelFactory):
Expand Down
8 changes: 5 additions & 3 deletions apps/content_pages/factories/content_arrays.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

from apps.content_pages.factories import (
ExtendedPersonFactory,
NonpublishedOrderedPlayFactory,
OrderedEventFactory,
OrderedImageFactory,
OrderedPlayFactory,
OrderedVideoFactory,
PublishedOrderedPlayFactory,
)
from apps.content_pages.models import EventsBlock, ImagesBlock, PersonsBlock, PlaysBlock, VideosBlock

Expand Down Expand Up @@ -64,7 +65,7 @@ def add_person(self, created, extracted, **kwargs):
class PlaysBlockFactory(factory.django.DjangoModelFactory):
"""Create content block Play for blog, news or projects.
Block creates with 3 ordered plays.
Block creates with 5 ordered plays.
"""

class Meta:
Expand All @@ -75,7 +76,8 @@ class Meta:
@factory.post_generation
def add_play(self, created, extracted, **kwargs):
if created:
OrderedPlayFactory.create_batch(3, block=self)
PublishedOrderedPlayFactory.create_batch(3, block=self)
NonpublishedOrderedPlayFactory.create_batch(2, block=self)


class VideosBlockFactory(factory.django.DjangoModelFactory):
Expand Down
7 changes: 7 additions & 0 deletions apps/content_pages/models/content_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,13 @@ class Meta:
verbose_name = "Блок пьес"
verbose_name_plural = "Блоки пьес"

def published_ordered_plays(self):
"""Filter published plays.
ordered_plays attribute is a related name added from OrderedPlay model
"""
return self.ordered_plays.filter(item__published=True)


class VideosBlock(AbstractItemWithTitle):
"""Model to store and organize OrderedVideos objects."""
Expand Down
2 changes: 1 addition & 1 deletion apps/content_pages/serializers/content_blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class Meta:

class PlaysBlockSerializer(serializers.ModelSerializer):
items = OrderedPlaySerializer(
source="ordered_plays",
source="published_ordered_plays",
many=True,
)

Expand Down
2 changes: 1 addition & 1 deletion apps/main/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def play_in_short_list(authors, festival):

@pytest.fixture
def plays(authors, festival):
return PlayFactory.create_batch(4, year=festival.year)
return PlayFactory.create_batch(10, year=festival.year)


@pytest.fixture
Expand Down
88 changes: 31 additions & 57 deletions poetry.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pip = "^24.0"
werkzeug = "^3.0.4"
urllib3 = "^2.2.2"
requests = "^2.32.3"
cryptography = "^42.0.5"
cryptography = "^43.0.1"
sqlparse = "^0.5.0"
easy-thumbnails = "^2.8.5"
idna = "^3.7"
Expand Down
2 changes: 1 addition & 1 deletion requirements/dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ charset-normalizer==3.3.2 ; python_version >= "3.9" and python_version < "4.0"
click==8.1.7 ; python_version >= "3.9" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.9" and python_version < "4.0" and (sys_platform == "win32" or platform_system == "Windows")
coverage==5.5 ; python_version >= "3.9" and python_version < "4"
cryptography==42.0.5 ; python_version >= "3.9" and python_version < "4.0"
cryptography==43.0.1 ; python_version >= "3.9" and python_version < "4.0"
cssselect2==0.7.0 ; python_version >= "3.9" and python_version < "4.0"
decorator==5.1.1 ; python_version >= "3.9" and python_version < "4.0"
distlib==0.3.7 ; python_version >= "3.9" and python_version < "4.0"
Expand Down
2 changes: 1 addition & 1 deletion requirements/prod.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ cffi==1.16.0 ; python_version >= "3.9" and python_version < "4.0" and platform_p
charset-normalizer==3.3.2 ; python_version >= "3.9" and python_version < "4.0"
click==8.1.7 ; python_version >= "3.9" and python_version < "4.0"
colorama==0.4.6 ; python_version >= "3.9" and python_version < "4.0" and (sys_platform == "win32" or platform_system == "Windows")
cryptography==42.0.5 ; python_version >= "3.9" and python_version < "4.0"
cryptography==43.0.1 ; python_version >= "3.9" and python_version < "4.0"
cssselect2==0.7.0 ; python_version >= "3.9" and python_version < "4.0"
django-admin-sortable2==1.0.4 ; python_version >= "3.9" and python_version < "4.0"
django-anymail[mailjet]==8.6 ; python_version >= "3.9" and python_version < "4.0"
Expand Down

0 comments on commit 7446bdc

Please sign in to comment.