Skip to content

Commit

Permalink
Add tests for filtering unpublished plays in API
Browse files Browse the repository at this point in the history
  • Loading branch information
FinemechanicPub committed Sep 9, 2024
1 parent f397a2b commit 209d7f4
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 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

0 comments on commit 209d7f4

Please sign in to comment.