Skip to content

Commit

Permalink
tests: renames image fixtures
Browse files Browse the repository at this point in the history
  • Loading branch information
hklarner committed Sep 28, 2023
1 parent 1a6ba62 commit dfac03a
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 38 deletions.
8 changes: 4 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,22 @@ def apiclient():


@pytest.fixture
def ImagePNG():
def image_png():
return factory.django.ImageField(width=1500, height=1400, format="PNG")


@pytest.fixture
def ImageBMP():
def image_bmp():
return factory.django.ImageField(width=1500, height=1400, format="BMP")


@pytest.fixture
def smallImage():
def small_image():
return factory.django.ImageField(width=200, height=200)


@pytest.fixture
def bigImage():
def big_image():
return factory.django.ImageField(width=1500, height=1400)


Expand Down
8 changes: 4 additions & 4 deletions tests/contrib/test_mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,22 @@ class Meta:


@pytest.mark.django_db
def test_add_default(module, idea_factory, ImagePNG):
def test_add_default(module, idea_factory, image_png):
idea_no_image = idea_factory()
form = IdeaForm(module=module, instance=idea_no_image)
assert "right_of_use" in form.fields
assert "right_of_use" not in form.initial

idea_with_image = idea_factory(image=ImagePNG)
idea_with_image = idea_factory(image=image_png)
form = IdeaForm(module=module, instance=idea_with_image)
assert "right_of_use" in form.fields
assert "right_of_use" in form.initial
assert form.initial["right_of_use"]


@pytest.mark.django_db
def test_clean(module, idea_factory, ImagePNG):
idea_with_image = idea_factory(image=ImagePNG)
def test_clean(module, idea_factory, image_png):
idea_with_image = idea_factory(image=image_png)
data = {
"right_of_use": False,
}
Expand Down
2 changes: 1 addition & 1 deletion tests/ideas/test_idea_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ def test_user_cannot_update_idea_after_phase(apiclient, phase_factory, idea_fact

@pytest.mark.django_db
def test_user_can_add_and_delete_idea_image_during_phase(
apiclient, bigImage, phase_factory, idea_factory
apiclient, big_image, phase_factory, idea_factory
):
phase, _, project, idea = setup_phase(
phase_factory, idea_factory, phases.CollectPhase
Expand Down
8 changes: 4 additions & 4 deletions tests/ideas/test_idea_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ def test_project(idea):


@pytest.mark.django_db
def test_delete_idea(idea_factory, comment_factory, rating_factory, ImagePNG):
idea = idea_factory(image=ImagePNG)
def test_delete_idea(idea_factory, comment_factory, rating_factory, image_png):
idea = idea_factory(image=image_png)
image_path = os.path.join(settings.MEDIA_ROOT, idea.image.path)
thumbnail_path = create_thumbnail(idea.image)

Expand Down Expand Up @@ -72,8 +72,8 @@ def test_delete_idea(idea_factory, comment_factory, rating_factory, ImagePNG):


@pytest.mark.django_db
def test_image_deleted_after_update(idea_factory, ImagePNG):
idea = idea_factory(image=ImagePNG)
def test_image_deleted_after_update(idea_factory, image_png):
idea = idea_factory(image=image_png)
image_path = os.path.join(settings.MEDIA_ROOT, idea.image.path)
thumbnail_path = create_thumbnail(idea.image)

Expand Down
28 changes: 14 additions & 14 deletions tests/organisations/test_organisation_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,44 +23,44 @@ def test_string_representation(organisation):


@pytest.mark.django_db
def test_image_validation_image_too_small(organisation_factory, smallImage):
organisation = organisation_factory(image=smallImage, logo=smallImage)
def test_image_validation_image_too_small(organisation_factory, small_image):
organisation = organisation_factory(image=small_image, logo=small_image)
with pytest.raises(Exception) as e:
organisation.full_clean()
assert "Image must be at least 500 pixels high" in str(e.value)


@pytest.mark.django_db
def test_image_big_enough(organisation_factory, bigImage, smallImage):
organisation = organisation_factory(image=bigImage, logo=smallImage)
def test_image_big_enough(organisation_factory, big_image, small_image):
organisation = organisation_factory(image=big_image, logo=small_image)
assert organisation.full_clean() is None


@pytest.mark.django_db
def test_image_validation_logo_too_big(organisation_factory, bigImage):
organisation = organisation_factory(logo=bigImage)
def test_image_validation_logo_too_big(organisation_factory, big_image):
organisation = organisation_factory(logo=big_image)
with pytest.raises(Exception) as e:
organisation.full_clean()
assert "Image must be at most 800 pixels high" in str(e.value)


@pytest.mark.django_db
def test_image_validation_type_not_allowed(organisation_factory, ImageBMP):
organisation = organisation_factory(image=ImageBMP, logo=ImageBMP)
def test_image_validation_type_not_allowed(organisation_factory, image_bmp):
organisation = organisation_factory(image=image_bmp, logo=image_bmp)
with pytest.raises(Exception) as e:
organisation.full_clean()
assert "Unsupported file format." in str(e.value)


@pytest.mark.django_db
def test_image_validation_image_type_allowed(organisation_factory, ImagePNG):
organisation = organisation_factory(image=ImagePNG)
def test_image_validation_image_type_allowed(organisation_factory, image_png):
organisation = organisation_factory(image=image_png)
assert organisation.full_clean() is None


@pytest.mark.django_db
def test_delete_organisation(organisation_factory, ImagePNG):
organisation = organisation_factory(image=ImagePNG, logo=ImagePNG)
def test_delete_organisation(organisation_factory, image_png):
organisation = organisation_factory(image=image_png, logo=image_png)
image_path = os.path.join(settings.MEDIA_ROOT, organisation.image.path)
logo_path = os.path.join(settings.MEDIA_ROOT, organisation.logo.path)
thumbnail_image_path = create_thumbnail(organisation.image)
Expand All @@ -83,8 +83,8 @@ def test_delete_organisation(organisation_factory, ImagePNG):


@pytest.mark.django_db
def test_image_deleted_after_update(organisation_factory, ImagePNG):
organisation = organisation_factory(image=ImagePNG, logo=ImagePNG)
def test_image_deleted_after_update(organisation_factory, image_png):
organisation = organisation_factory(image=image_png, logo=image_png)
image_path = os.path.join(settings.MEDIA_ROOT, organisation.image.path)
logo_path = os.path.join(settings.MEDIA_ROOT, organisation.logo.path)
thumbnail_image_path = create_thumbnail(organisation.image)
Expand Down
6 changes: 3 additions & 3 deletions tests/projects/test_serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ def test_project_serializer(
client,
project_factory,
phase_factory,
ImagePNG,
image_png,
):
project_active = project_factory(
name="active",
image=ImagePNG,
image=image_png,
image_copyright="copyright",
image_alt_text="img_alt",
)
project_future = project_factory(name="future")
project_active_and_future = project_factory(name="active and future")
project_past = project_factory(
name="past",
tile_image=ImagePNG,
tile_image=image_png,
tile_image_copyright="copyright",
tile_image_alt_text="img_alt",
)
Expand Down
8 changes: 4 additions & 4 deletions tests/topicprio/test_topic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def test_reference_number(topic):


@pytest.mark.django_db
def test_delete_idea(topic_factory, comment_factory, rating_factory, ImagePNG):
idea = topic_factory(image=ImagePNG)
def test_delete_idea(topic_factory, comment_factory, rating_factory, image_png):
idea = topic_factory(image=image_png)
image_path = os.path.join(settings.MEDIA_ROOT, idea.image.path)
thumbnail_path = create_thumbnail(idea.image)

Expand Down Expand Up @@ -77,8 +77,8 @@ def test_delete_idea(topic_factory, comment_factory, rating_factory, ImagePNG):


@pytest.mark.django_db
def test_image_deleted_after_update(topic_factory, ImagePNG):
idea = topic_factory(image=ImagePNG)
def test_image_deleted_after_update(topic_factory, image_png):
idea = topic_factory(image=image_png)
image_path = os.path.join(settings.MEDIA_ROOT, idea.image.path)
thumbnail_path = create_thumbnail(idea.image)

Expand Down
8 changes: 4 additions & 4 deletions tests/users/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@


@pytest.mark.django_db
def test_delete_user_signal(user_factory, ImagePNG):
user = user_factory(_avatar=ImagePNG)
def test_delete_user_signal(user_factory, image_png):
user = user_factory(_avatar=image_png)
image_path = os.path.join(settings.MEDIA_ROOT, user._avatar.path)

assert os.path.isfile(image_path)
Expand All @@ -18,8 +18,8 @@ def test_delete_user_signal(user_factory, ImagePNG):


@pytest.mark.django_db
def test_image_deleted_after_update(user_factory, ImagePNG):
user = user_factory(_avatar=ImagePNG)
def test_image_deleted_after_update(user_factory, image_png):
user = user_factory(_avatar=image_png)
image_path = os.path.join(settings.MEDIA_ROOT, user._avatar.path)
thumbnail_path = create_thumbnail(user._avatar)

Expand Down

0 comments on commit dfac03a

Please sign in to comment.