From 37ac966d28ebd4259c08cc769ab9d176fcb06927 Mon Sep 17 00:00:00 2001 From: Julian Dehm Date: Tue, 22 Oct 2024 10:32:27 +0200 Subject: [PATCH] remove unneeded tests --- tests/conftest.py | 9 --- tests/factories.py | 6 -- tests/organisations/__init__.py | 0 tests/organisations/factories.py | 28 -------- tests/organisations/test_models.py | 101 ----------------------------- tests/organisations/test_views.py | 20 ------ tests/users/test_models.py | 33 ---------- 7 files changed, 197 deletions(-) delete mode 100644 tests/organisations/__init__.py delete mode 100644 tests/organisations/factories.py delete mode 100644 tests/organisations/test_models.py delete mode 100644 tests/organisations/test_views.py delete mode 100644 tests/users/test_models.py diff --git a/tests/conftest.py b/tests/conftest.py index acd3cb082..6d8aedfd1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -4,9 +4,7 @@ from pytest_factoryboy import register from rest_framework.test import APIClient -from adhocracy4.test import factories as a4_factories from adhocracy4.test import helpers -from tests.organisations import factories as org_factories from . import factories @@ -15,13 +13,6 @@ register(factories.AdminFactory, 'admin') register(factories.ContentTypeFactory) -register(org_factories.OrganisationFactory) -register(org_factories.OrganisationFactory, 'other_organisation') -register(a4_factories.GroupFactory) -register(a4_factories.ProjectFactory) -register(a4_factories.ModuleFactory) -register(factories.PhaseFactory) - def pytest_configure(config): # Patch email background_task decorators for all tests diff --git a/tests/factories.py b/tests/factories.py index b58be0034..111a8528b 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -7,8 +7,6 @@ from django.core.files import images from PIL import Image -from adhocracy4.test import factories - class UserFactory(factory.django.DjangoModelFactory): @@ -36,10 +34,6 @@ class Meta: name = factory.Faker('name') -class PhaseFactory(factories.PhaseFactory): - type = 'blog:phase' - - class ImageFactory(): """ Create a django file object containg an image. diff --git a/tests/organisations/__init__.py b/tests/organisations/__init__.py deleted file mode 100644 index e69de29bb..000000000 diff --git a/tests/organisations/factories.py b/tests/organisations/factories.py deleted file mode 100644 index 51b078163..000000000 --- a/tests/organisations/factories.py +++ /dev/null @@ -1,28 +0,0 @@ -import factory - -from tests.factories import UserFactory - - -class OrganisationFactory(factory.django.DjangoModelFactory): - - class Meta: - model = 'euth_organisations.Organisation' - - name = factory.Faker('company') - slug = factory.Sequence(lambda n: 'organisation%d' % n) - description_why = factory.Faker('text') - description_how = factory.Faker('text') - description = factory.Faker('text') - country = factory.Faker('country_code') - place = factory.Faker('city') - - @factory.post_generation - def initiators(self, create, extracted, **kwargs): - if not extracted: - user = UserFactory() - self.initiators.add(user) - return - - if extracted: - for user in extracted: - self.initiators.add(user) diff --git a/tests/organisations/test_models.py b/tests/organisations/test_models.py deleted file mode 100644 index ec919e209..000000000 --- a/tests/organisations/test_models.py +++ /dev/null @@ -1,101 +0,0 @@ -import os - -import pytest -from django.conf import settings -from django.urls import reverse - -from euth.organisations import models -from tests import helpers - - -@pytest.mark.django_db -def test_absolute_url(organisation): - url = reverse('organisation-detail', kwargs={'slug': organisation.slug}) - assert organisation.get_absolute_url() == url - - -@pytest.mark.django_db -def test_natural_keys(organisation): - assert models.Organisation.objects.get_by_natural_key( - organisation.name) == organisation - - -@pytest.mark.django_db -def test_image_validation_image_too_small(organisation_factory, smallImage): - organisation = organisation_factory(image=smallImage, logo=smallImage) - with pytest.raises(Exception) as e: - organisation.full_clean() - assert 'Image must be at least 600 pixels high' in str(e.value) - - -@pytest.mark.django_db -def test_image_big_enough(organisation_factory, bigImage): - organisation = organisation_factory(image=bigImage, logo=bigImage) - assert organisation.full_clean() is None - - -@pytest.mark.django_db -def test_image_validation_type_not_allowed(organisation_factory, ImageBMP): - organisation = organisation_factory(image=ImageBMP, logo=ImageBMP) - 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, logo=ImagePNG) - assert organisation.full_clean() is None - - -@pytest.mark.django_db -def test_delete_organisation(organisation_factory, ImagePNG): - organisation = organisation_factory(image=ImagePNG, logo=ImagePNG) - 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 = helpers.createThumbnail(organisation.image) - thumbnail_logo_path = helpers.createThumbnail(organisation.logo) - - assert os.path.isfile(thumbnail_image_path) - assert os.path.isfile(thumbnail_logo_path) - assert os.path.isfile(image_path) - assert os.path.isfile(logo_path) - count = models.Organisation.objects.all().count() - assert count == 1 - - organisation.delete() - assert not os.path.isfile(thumbnail_image_path) - assert not os.path.isfile(thumbnail_logo_path) - assert not os.path.isfile(image_path) - assert not os.path.isfile(logo_path) - count = models.Organisation.objects.all().count() - assert count == 0 - - -@pytest.mark.django_db -def test_image_deleted_after_update(organisation_factory, ImagePNG): - organisation = organisation_factory(image=ImagePNG, logo=ImagePNG) - 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 = helpers.createThumbnail(organisation.image) - thumbnail_logo_path = helpers.createThumbnail(organisation.logo) - - assert os.path.isfile(thumbnail_image_path) - assert os.path.isfile(thumbnail_logo_path) - assert os.path.isfile(image_path) - assert os.path.isfile(logo_path) - - new_image_path = os.path.join( - settings.MEDIA_ROOT, - os.path.dirname(organisation.image.path) + '/new.png' - ) - os.rename(organisation.image.path, new_image_path) - organisation.image = new_image_path - organisation.logo = None - organisation.save() - - assert os.path.isfile(new_image_path) - assert not os.path.isfile(thumbnail_image_path) - assert not os.path.isfile(thumbnail_logo_path) - assert not os.path.isfile(image_path) - assert not os.path.isfile(logo_path) diff --git a/tests/organisations/test_views.py b/tests/organisations/test_views.py deleted file mode 100644 index cada151c5..000000000 --- a/tests/organisations/test_views.py +++ /dev/null @@ -1,20 +0,0 @@ -import pytest -from django.urls import reverse - - -@pytest.mark.django_db -def test_detail_view(client, organisation): - url = reverse('organisation-detail', kwargs={'slug': organisation.slug}) - response = client.get(url) - assert response.status_code == 200 - - -@pytest.mark.django_db -def test_list_view(client, organisation_factory): - for i in range(20): - organisation_factory() - url = reverse('organisation-list') - response = client.get(url) - assert len(response.context_data['object_list']) == 12 - assert response.context['is_paginated'] - assert response.status_code == 200 diff --git a/tests/users/test_models.py b/tests/users/test_models.py deleted file mode 100644 index 530fbcd89..000000000 --- a/tests/users/test_models.py +++ /dev/null @@ -1,33 +0,0 @@ -import os - -import pytest -from django.conf import settings - -from tests import helpers - - -@pytest.mark.django_db -def test_delete_user_signal(user_factory, ImagePNG): - user = user_factory(_avatar=ImagePNG) - image_path = os.path.join(settings.MEDIA_ROOT, user._avatar.path) - - assert os.path.isfile(image_path) - - user.delete() - assert not os.path.isfile(image_path) - - -@pytest.mark.django_db -def test_image_deleted_after_update(user_factory, ImagePNG): - user = user_factory(_avatar=ImagePNG) - image_path = os.path.join(settings.MEDIA_ROOT, user._avatar.path) - thumbnail_path = helpers.createThumbnail(user._avatar) - - assert os.path.isfile(image_path) - assert os.path.isfile(thumbnail_path) - - user._avatar = None - user.save() - - assert not os.path.isfile(image_path) - assert not os.path.isfile(thumbnail_path)