コード例 #1
0
ファイル: profile.py プロジェクト: CosmosTUe/Cosmos
 def setUp(self) -> None:
     self.user = User.objects.create_user(username="******",
                                          email="*****@*****.**",
                                          password="******")
     Profile(
         user=self.user,
         nationality="Dutch",
         terms_confirmed=True,
         subscribed_newsletter=False,
     ).save()
     self.executor = Factory.get_executor()
     self.newsletter_service = Factory.get_newsletter_service(True)
コード例 #2
0
ファイル: newsletter.py プロジェクト: CosmosTUe/Cosmos
 def setUp(self) -> None:
     self.service = Factory.get_newsletter_service(True)
     self.executor = Factory.get_executor()
     self.inst_email = "*****@*****.**"
     self.alt_email = "*****@*****.**"
     self.user = User.objects.create_user(
         username=self.inst_email,
         email=self.alt_email,
     )
     self.user.profile = Profile(user=self.user,
                                 nationality="Dutch",
                                 terms_confirmed=True,
                                 subscribed_newsletter=False)
コード例 #3
0
ファイル: newsletter.py プロジェクト: CosmosTUe/Cosmos
    def _test_update(self,
                     exp_tue,
                     exp_alt,
                     old_sub=False,
                     old_rec="TUE",
                     new_sub=False,
                     new_rec="TUE"):
        """
        Helper function to speed up testing

        :param exp_tue: expected subscription for TUe email
        :param exp_alt: expected subscription for alternative email
        :param old_sub: old subscription state
        :param old_rec: old subscription recipient
        :param new_sub: old subscription state
        :param new_rec: old subscription recipient
        :return:
        """
        # setup
        self.user.profile.subscribed_newsletter = new_sub
        self.user.profile.newsletter_recipient = new_rec

        # act
        self.service.update_newsletter_preferences(
            self.user.profile,
            {
                "subscribed_newsletter": old_sub,
                "subscribed_gmm_invite": False,
                "newsletter_recipient": old_rec
            },
            {
                "subscribed_newsletter": new_sub,
                "subscribed_gmm_invite": False,
                "newsletter_recipient": new_rec
            },
        )
        Factory.get_executor().execute()

        # test
        self.assert_subscription_states(exp_tue, exp_alt)
コード例 #4
0
ファイル: subscribe_command.py プロジェクト: CosmosTUe/Cosmos
    def execute(self):
        from apps.async_requests.factory import Factory

        newsletter_service = Factory.get_newsletter_service()
        newsletter_service.add_subscription(self.contacts, self.list_id)
コード例 #5
0
from django.contrib.auth.models import User
from django.core import mail
from django.test import TestCase

from apps.async_requests.factory import Factory

executor = Factory.get_executor()


class PasswordResetViewTest(TestCase):
    def assert_email_sent(self, recipient):
        # setup
        exp_email_sender = "*****@*****.**"
        exp_email_recipient = recipient
        exp_email_subject = "[Cosmos] Password reset"

        # act
        executor.execute()

        # test
        self.assertEqual(len(mail.outbox), 1, "1 message sent")
        self.assertEqual(mail.outbox[0].to[0], exp_email_recipient)
        self.assertEqual(mail.outbox[0].from_email, exp_email_sender)
        self.assertEqual(mail.outbox[0].subject, exp_email_subject)
        self.assert_working_password_reset_view()

    def assert_working_password_reset_view(self):
        # setup
        link_url = ""
        for line in mail.outbox[0].body.splitlines():
            if line.startswith("http://") or line.startswith("https://"):
コード例 #6
0
import logging
from http.client import HTTPException

from django.contrib import admin, messages
from django.db.models.query import QuerySet
from django.http import FileResponse
from django.urls import path
from python_http_client import UnauthorizedError

from apps.async_requests.factory import Factory
from apps.users.models import Profile
from apps.users.stats import get_nationality_stats

logger = logging.getLogger(__name__)
executor = Factory.get_executor()
newsletter_service = Factory.get_newsletter_service()


@admin.register(Profile)
class ProfileAdmin(admin.ModelAdmin):
    list_display = ("username", "nationality", "terms_confirmed",
                    "subscribed_newsletter")

    search_fields = ["user__username"]

    # Used to extend the default admin page to add a button
    change_list_template = "user/admin_add_stats_button.html"

    # Used to extend the get_urls function to add a getstats url
    def get_urls(self):
        urls = super().get_urls()
コード例 #7
0
 def save(self, commit=True):
     newsletter_service = Factory.get_newsletter_service()
     newsletter_service.update_newsletter_preferences(
         self.instance, self.initial, self.cleaned_data)
     return super(PreferencesUpdateForm, self).save(commit)
コード例 #8
0
ファイル: registration.py プロジェクト: CosmosTUe/Cosmos
 def setUp(self) -> None:
     self.newsletter_service = Factory.get_newsletter_service(True)
コード例 #9
0
    def execute(self):
        from apps.async_requests.factory import Factory

        for email in self.emails:
            Factory.get_newsletter_service().send_mail(email)
コード例 #10
0
ファイル: executor.py プロジェクト: CosmosTUe/Cosmos
 def setUp(self) -> None:
     self.executor = Factory.get_executor()
コード例 #11
0
ファイル: tasks.py プロジェクト: CosmosTUe/Cosmos
def execute_async_requests():
    Factory.get_executor().execute()
コード例 #12
0
ファイル: helpers.py プロジェクト: CosmosTUe/Cosmos
 def setUp(self):
     self.executor = Factory.get_executor()
     self.newsletter_service = Factory.get_newsletter_service(True)
     return super(NewsletterTestCaseMixin, self).setUp()