diff --git a/euth/users/adapters.py b/euth/users/adapters.py index 93039690f..543fd4f27 100644 --- a/euth/users/adapters.py +++ b/euth/users/adapters.py @@ -1,23 +1,10 @@ import re -from urllib.parse import quote from allauth.account.adapter import DefaultAccountAdapter -from django.utils.http import url_has_allowed_host_and_scheme -from adhocracy4.emails import Email -from adhocracy4.emails.mixins import SyncEmailMixin from euth.users import USERNAME_REGEX -class EuthAccountEmail(SyncEmailMixin, Email): - def get_receivers(self): - return [self.object] - - @property - def template_name(self): - return self.kwargs['template_name'] - - class EuthAccountAdapter(DefaultAccountAdapter): username_regex = re.compile(USERNAME_REGEX) @@ -31,27 +18,3 @@ def is_open_for_signup(self, request): (Comment reproduced from the overridden method.) """ return False - - def get_email_confirmation_url(self, request, emailconfirmation): - url = super().get_email_confirmation_url(request, emailconfirmation) - if 'next' in request.POST \ - and url_has_allowed_host_and_scheme(request.POST['next'], - allowed_hosts=None): - return '{}?next={}'.format(url, quote(request.POST['next'])) - else: - return url - - def send_mail(self, template_prefix, email, context): - return EuthAccountEmail.send( - email, - template_name=template_prefix, - **context - ) - - def get_email_confirmation_redirect_url(self, request): - if 'next' in request.GET \ - and url_has_allowed_host_and_scheme(request.GET['next'], - allowed_hosts=None): - return request.GET['next'] - else: - return super().get_email_confirmation_redirect_url(request) diff --git a/euth/users/templates/euth_users/indicator_menu.html b/euth/users/templates/euth_users/indicator_menu.html index d8ff432ba..dbe7d527d 100644 --- a/euth/users/templates/euth_users/indicator_menu.html +++ b/euth/users/templates/euth_users/indicator_menu.html @@ -17,10 +17,6 @@ {% endif %} -
  • - {% trans "Account Settings" %} -
  • -
  • {% csrf_token %} diff --git a/euth/users/templates/euth_users/user_detail.html b/euth/users/templates/euth_users/user_detail.html deleted file mode 100644 index 6103986b4..000000000 --- a/euth/users/templates/euth_users/user_detail.html +++ /dev/null @@ -1,91 +0,0 @@ -{% extends "base.html" %} -{% load i18n thumbnail static avatar %} -{% block title %}{{ object.username }}{% endblock %} - -{% block content %} -
    -
    -
    - -
    - {% if object.has_social_share %} - - {% endif %} -

    - {{ object.username }} -

    -
    - {% if object.city or object.country %} -

    - - {{object.city}} - {% if object.city and object.country %}, {% endif %} - {{object.country.name}} -

    - {% endif %} - {% if object.languages %} -

    {{object.languages}}

    - {% endif %} - {% if object.birthdate %} -

    {{ object.age }} {% trans 'years old' %}

    - {% endif %} -
    -
    -
    - {% if object.description %} -
    - {% trans 'Bio' %} -

    {{ object.description }}

    -
    - {% endif %} -
    -
    - - -
    -
    -
    - {% if object.city or object.country %} -

    - - {{object.city}}{% if object.city and object.country %}, {% endif %} - {{object.country.name}} -

    - {% endif %} - {% if object.languages %} -

    {{object.languages}}

    - {% endif %} - {% if object.birthdate %} -

    {{ object.age }} {% trans 'years old' %}

    - {% endif %} - {% if object.description %} -

    {{ object.description }}

    - {% endif %} -
    -
    - {% if view.get_participated_projects %} -
    - {% for project in view.get_participated_projects %} - {% include 'euth_projects/includes/project_list_item.html' with project=project follow_user=object %} - {% endfor %} -
    - {% else %} -

    - {% blocktrans with username=object.username %}{{ username }} follows no projects at the moment.{% endblocktrans %} -

    - {% endif %} -
    -
    -
    -{% endblock %} diff --git a/euth/users/templates/euth_users/user_search.html b/euth/users/templates/euth_users/user_search.html deleted file mode 100644 index 86edc003c..000000000 --- a/euth/users/templates/euth_users/user_search.html +++ /dev/null @@ -1 +0,0 @@ -{{ input }} diff --git a/euth_wagtail/settings/base.py b/euth_wagtail/settings/base.py index 4c2793899..4cc1be7c3 100644 --- a/euth_wagtail/settings/base.py +++ b/euth_wagtail/settings/base.py @@ -47,7 +47,6 @@ 'widget_tweaks', 'easy_thumbnails', 'parler', - 'background_task', 'django.contrib.sites', 'django.contrib.admin', diff --git a/tests/conftest.py b/tests/conftest.py index acd3cb082..50c175af0 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,61 +1,12 @@ -import factory import pytest from django.urls import reverse 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 register(factories.UserFactory) register(factories.UserFactory, 'user2') 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 - helpers.patch_background_task_decorator('adhocracy4.emails.tasks') - - -@pytest.fixture -def apiclient(): - return APIClient() - - -@pytest.fixture -def smallImage(): - return factory.django.ImageField(width=200, height=200) - - -@pytest.fixture -def bigImage(): - return factory.django.ImageField(width=1400, height=1400) - - -@pytest.fixture -def ImageBMP(): - return factory.django.ImageField(width=1400, height=1400, format='BMP') - - -@pytest.fixture -def ImagePNG(): - return factory.django.ImageField(width=1400, height=1400, format='PNG') - - -@pytest.fixture -def image_factory(): - return factories.ImageFactory() @pytest.fixture diff --git a/tests/contrib/test_middleware.py b/tests/contrib/test_middleware.py deleted file mode 100644 index 203f97e0f..000000000 --- a/tests/contrib/test_middleware.py +++ /dev/null @@ -1,23 +0,0 @@ -import pytest -from django.conf import settings -from django.contrib.auth.models import AnonymousUser -from django.utils import timezone - -from euth.contrib.middleware import TimezoneMiddleware - - -@pytest.mark.django_db -def test_request_processed_user(rf, user): - request = rf.get('/') - request.user = user - TimezoneMiddleware().process_request(request) - assert user.timezone == timezone.get_current_timezone_name() - - -@pytest.mark.django_db -def test_request_processed_default(rf): - request = rf.get('/') - user = AnonymousUser() - request.user = user - TimezoneMiddleware().process_request(request) - assert settings.TIME_ZONE == timezone.get_current_timezone_name() diff --git a/tests/factories.py b/tests/factories.py index b58be0034..6fed0ba25 100644 --- a/tests/factories.py +++ b/tests/factories.py @@ -1,13 +1,6 @@ -from io import BytesIO - import factory from django.conf import settings from django.contrib.auth.hashers import make_password -from django.core.files import base -from django.core.files import images -from PIL import Image - -from adhocracy4.test import factories class UserFactory(factory.django.DjangoModelFactory): @@ -18,39 +11,8 @@ class Meta: username = factory.Sequence(lambda n: 'user{}'.format(n)) password = make_password('password') email = factory.Sequence(lambda n: 'user{}@liqd.net'.format(n)) - timezone = factory.Faker('timezone') class AdminFactory(UserFactory): is_superuser = True is_staff = True - - -class ContentTypeFactory(factory.django.DjangoModelFactory): - - class Meta: - model = 'contenttypes.ContentType' - - app_label = factory.Faker('name') - model = factory.Faker('name') - name = factory.Faker('name') - - -class PhaseFactory(factories.PhaseFactory): - type = 'blog:phase' - - -class ImageFactory(): - """ - Create a django file object containg an image. - """ - - def __call__(self, resolution, image_format='JPEG', name=None): - - filename = name or 'default.{}'.format(image_format.lower()) - color = 'blue' - image = Image.new('RGB', resolution, color) - image_data = BytesIO() - image.save(image_data, image_format) - image_content = base.ContentFile(image_data.getvalue()) - return images.ImageFile(image_content.file, filename) 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)