Beispiel #1
0
    def setUpTestData(cls):
        cls.user = VerifiedUserFactory()
        cls.other_user = VerifiedUserFactory()
        cls.non_verified_user = UserFactory()
        cls.group = GroupFactory(
            members=[cls.user, cls.other_user, cls.non_verified_user])
        cls.place = PlaceFactory(
            group=cls.group,
            subscribers=[cls.user, cls.other_user, cls.non_verified_user])

        cls.declined_place = PlaceFactory(group=cls.group,
                                          status=PlaceStatus.DECLINED.value)

        # unsubscribe other_user from notifications
        GroupMembership.objects.filter(
            group=cls.group, user=cls.other_user).update(notification_types=[])

        # add some random inactive users, to make sure we don't send to them
        inactive_users = [
            VerifiedUserFactory(language='en')
            for _ in list(range(randint(2, 5)))
        ]
        for user in inactive_users:
            membership = cls.group.add_member(user)
            membership.inactive_at = timezone.now()
            membership.save()
Beispiel #2
0
    def setUpTestData(cls):
        cls.group = GroupFactory()

        cls.user_without_notifications = VerifiedUserFactory(language='en')
        cls.group.add_member(cls.user_without_notifications)
        m = GroupMembership.objects.get(group=cls.group,
                                        user=cls.user_without_notifications)
        m.notification_types = []
        m.save()

        # it should ignore unverified and inactive users so adding a random number
        # of them here should not change anything

        unverified_users = [
            UserFactory(language='en') for _ in list(range(randint(2, 5)))
        ]
        for user in unverified_users:
            cls.group.add_member(user)

        inactive_users = [
            VerifiedUserFactory(language='en')
            for _ in list(range(randint(2, 5)))
        ]
        for user in inactive_users:
            membership = cls.group.add_member(user)
            membership.inactive_at = timezone.now()
            membership.save()
Beispiel #3
0
    def test_creates_one_email_per_person_with_different_languages(self):
        n = 5

        for _ in list(range(n)):
            self.group.add_member(VerifiedUserFactory(language='en'))

        for _ in list(range(n)):
            self.group.add_member(VerifiedUserFactory(language='de'))

        for _ in list(range(n)):
            self.group.add_member(VerifiedUserFactory(language='fr'))

        from_date, to_date = group_emails.calculate_group_summary_dates(
            self.group)
        context = group_emails.prepare_group_summary_data(
            self.group, from_date, to_date)
        emails = group_emails.prepare_group_summary_emails(self.group, context)
        self.assertEqual(len(emails), 15)

        to = []
        for email in emails:
            to.extend(email.to)

        expected_members = self.group.members.filter(
            groupmembership__in=GroupMembership.objects.active(
            ).with_notification_type(GroupNotificationType.WEEKLY_SUMMARY)
        ).exclude(groupmembership__user__in=get_user_model().objects.
                  unverified_or_ignored())

        self.assertEqual(sorted(to),
                         sorted([member.email for member in expected_members]))

        self.assertNotIn(self.user_without_notifications.email, to)
Beispiel #4
0
 def setUp(self):
     self.user = VerifiedUserFactory()
     self.user2 = VerifiedUserFactory()
     self.group = GroupFactory(members=[self.user, self.user2])
     self.conversation = self.group.conversation
     self.thread = self.conversation.messages.create(author=self.user,
                                                     content='yay')
Beispiel #5
0
 def setUp(self):
     self.user = VerifiedUserFactory()
     self.author = VerifiedUserFactory()
     self.conversation = Conversation.objects.get_or_create_for_two_users(self.author, self.user)
     with suppressed_notifications():
         self.message = self.conversation.messages.create(author=self.author, content='initial message')
     mail.outbox = []
Beispiel #6
0
 def setUp(self):
     self.user = VerifiedUserFactory()
     self.author = VerifiedUserFactory()
     self.group = GroupFactory(members=[self.author, self.user])
     mail.outbox = []
     with suppressed_notifications():
         self.message = self.group.conversation.messages.create(author=self.author, content='initial message')
Beispiel #7
0
 def setUp(self):
     self.user = VerifiedUserFactory()
     self.user2 = VerifiedUserFactory()
     self.group = GroupFactory(members=[self.user, self.user2])
     self.place = PlaceFactory(subscribers=[self.user, self.user2])
     self.conversation = self.place.conversation
     mail.outbox = []
Beispiel #8
0
 def setUp(self):
     self.applicant = VerifiedUserFactory()
     self.member = VerifiedUserFactory()
     self.group = GroupFactory(members=[self.member])
     self.application = ApplicationFactory(group=self.group, user=self.applicant)
     self.conversation = Conversation.objects.get_for_target(self.application)
     mail.outbox = []
class TestApplicationConversationModel(APITestCase):
    def setUp(self):
        self.applicant = VerifiedUserFactory()
        self.member = VerifiedUserFactory()
        self.group = GroupFactory(members=[self.member])
        self.application = ApplicationFactory(group=self.group, user=self.applicant)
        self.conversation = Conversation.objects.get_for_target(self.application)

    def test_member_leaves_group(self):
        GroupMembership.objects.filter(user=self.member, group=self.group).delete()
        self.assertNotIn(
            self.member,
            self.conversation.participants.all(),
        )

    def test_user_erased(self):
        self.applicant.refresh_from_db()  # otherwise user.photo.name is None
        self.applicant.erase()

        self.application.refresh_from_db()
        self.assertEqual(self.application.status, ApplicationStatus.WITHDRAWN.value)

    def test_deleting_application_deletes_conversation(self):
        Application.objects.filter(user=self.applicant, group=self.group).delete()
        self.assertIsNone(Conversation.objects.get_for_target(self.application))

    def test_sets_group(self):
        self.assertEqual(self.conversation.group, self.group)

    def test_withdraw_pending_application_when_user_joins_group(self):
        self.group.add_member(self.applicant)

        self.application.refresh_from_db()
        self.assertEqual(self.application.status, ApplicationStatus.WITHDRAWN.value)
Beispiel #10
0
 def setUp(self):
     self.verified_user = VerifiedUserFactory()
     self.another_user = VerifiedUserFactory()
     self.old_email = self.verified_user.email
     self.new_email = faker.email()
     self.password = self.verified_user.display_name
     self.url = '/api/auth/email/'
     self.url_patch = '/api/auth/user/'
     mail.outbox = []
Beispiel #11
0
 def test_can_create_issue_in_open_group(self):
     member = VerifiedUserFactory()
     member2 = VerifiedUserFactory()
     open_group = GroupFactory(members=[member, member2], is_open=True)
     self.client.force_login(user=member)
     response = self.create_issue_via_API(group=open_group,
                                          affected_user=member2)
     self.assertEqual(response.status_code, status.HTTP_201_CREATED,
                      response.data)
Beispiel #12
0
 def setUp(self):
     self.user = VerifiedUserFactory()
     self.other_user = VerifiedUserFactory()
     self.group = GroupFactory(members=[self.user, self.other_user])
     self.place = PlaceFactory(group=self.group, subscribers=[self.user, self.other_user])
     self.activity = ActivityFactory(place=self.place)
     self.subscriptions = [
         PushSubscription.objects.create(user=self.user, token='', platform=PushSubscriptionPlatform.ANDROID.value)
     ]
Beispiel #13
0
    def setUp(self):
        self.applicant = VerifiedUserFactory()
        self.member = VerifiedUserFactory()
        self.group = GroupFactory(members=[self.member])
        mail.outbox = []

        # effectively disable throttling
        from karrot.applications.api import ApplicationsPerDayThrottle
        ApplicationsPerDayThrottle.rate = '1000/min'
Beispiel #14
0
    def setUp(self):
        self.member = VerifiedUserFactory()
        self.affected_member = VerifiedUserFactory()
        self.group = GroupFactory(members=[self.member],
                                  newcomers=[self.affected_member])

        # effectively disable throttling
        from karrot.issues.api import IssuesCreateThrottle
        IssuesCreateThrottle.rate = '1000/min'
Beispiel #15
0
 def setUp(self):
     self.user = VerifiedUserFactory()
     self.more_users = [VerifiedUserFactory() for _ in range(2)]
     self.group = GroupFactory(members=[self.user, *self.more_users])
     for membership in self.group.groupmembership_set.all():
         membership.add_notification_types([GroupNotificationType.CONFLICT_RESOLUTION])
         membership.save()
     self.issue = IssueFactory(group=self.group, created_by=self.user)
     self.conversation = self.issue.conversation
     mail.outbox = []
Beispiel #16
0
    def setUp(self):
        settings.CONFLICT_RESOLUTION_ACTIVE_EDITORS_REQUIRED_FOR_CREATION = 1
        self.member = VerifiedUserFactory()
        self.affected_member = VerifiedUserFactory()
        self.group = GroupFactory(members=[self.member],
                                  newcomers=[self.affected_member])

        # effectively disable throttling
        from karrot.issues.api import IssuesCreateThrottle
        IssuesCreateThrottle.rate = '1000/min'
Beispiel #17
0
    def test_new_members_are_not_in_existing_issue_conversations(self):
        # create a new member and a new editor
        self.group.groupmembership_set.create(user=VerifiedUserFactory(),
                                              roles=[roles.GROUP_EDITOR])
        self.group.groupmembership_set.create(user=VerifiedUserFactory())

        # ...they shouldn't become part of existing issue conversations
        expected_ids = sorted([self.member.id, self.affected_member.id])
        conversation_participant_ids = sorted(
            self.issue.conversation.participants.values_list('id', flat=True))
        self.assertEqual(conversation_participant_ids, expected_ids)
Beispiel #18
0
    def setUpTestData(cls):
        cls.member = VerifiedUserFactory()
        cls.newcomer = VerifiedUserFactory()
        cls.affected_member = VerifiedUserFactory()
        cls.group = GroupFactory(
            members=[cls.member, cls.affected_member],
            newcomers=[cls.newcomer],
        )

        # effectively disable throttling
        from karrot.issues.api import IssuesCreateThrottle
        IssuesCreateThrottle.rate = '1000/min'
Beispiel #19
0
    def test_issue_created(self):
        member = VerifiedUserFactory()
        member2 = VerifiedUserFactory()
        group = GroupFactory(members=[member, member2])

        client = self.connect_as(member)
        IssueFactory(group=group, affected_user=member2, created_by=member)

        messages = client.messages_by_topic
        self.assertIn('issues:issue', messages)
        self.assertIn('conversations:conversation', messages)

        self.assertEqual(len(messages['issues:issue']), 1)
Beispiel #20
0
    def setUp(self):
        self.member = VerifiedUserFactory()
        self.affected_member = VerifiedUserFactory()
        self.group = GroupFactory(members=[self.member, self.affected_member])
        self.issue = IssueFactory(group=self.group,
                                  created_by=self.member,
                                  affected_user=self.affected_member)

        # add notification type to send out emails
        for membership in self.group.groupmembership_set.all():
            membership.add_notification_types(
                [GroupNotificationType.CONFLICT_RESOLUTION])
            membership.save()
Beispiel #21
0
    def test_vote(self):
        member = VerifiedUserFactory()
        member2 = VerifiedUserFactory()
        group = GroupFactory(members=[member, member2])
        issue = IssueFactory(group=group,
                             affected_user=member2,
                             created_by=member)

        client = self.connect_as(member)
        vote_for_further_discussion(voting=issue.latest_voting(), user=member)

        messages = client.messages_by_topic
        self.assertEqual(len(client.messages), 1)
        self.assertEqual(len(messages['issues:issue']), 1)
Beispiel #22
0
    def test_no_summary_email_if_no_activity_in_group(self, write_points):
        group = GroupFactory(members=[VerifiedUserFactory()])

        with freeze_time(
                datetime.datetime(2018, 8, 19, 6, 0, 0, tzinfo=pytz.utc)):
            write_points.reset_mock()
            mail.outbox = []
            send_summary_emails()

        self.assertEqual(len(mail.outbox), 0)
        write_points.assert_called_with([{
            'measurement': 'karrot.email.group_summary',
            'tags': {
                'group': str(group.id),
                'group_status': 'active',
            },
            'fields': {
                'value': 1,
                'new_user_count': 0,
                'email_recipient_count': 0,
                'feedback_count': 0,
                'activities_missed_count': 0,
                'message_count': 0,
                'activities_done_count': 0,
                'has_activity': False,
            },
        }])
Beispiel #23
0
    def make_activity_in_group(self, group):
        place = PlaceFactory(group=group)
        new_users = [VerifiedUserFactory() for _ in range(self.new_user_count)]
        user = new_users[0]

        a_few_days_ago = timezone.now() - relativedelta(days=4)
        with freeze_time(a_few_days_ago, tick=True):
            [group.add_member(u) for u in new_users]

            # a couple of messages
            [
                group.conversation.messages.create(author=user,
                                                   content='hello')
                for _ in range(self.message_count)
            ]

            # missed activities
            [
                ActivityFactory(place=place)
                for _ in range(self.activities_missed_count)
            ]

            # fullfilled activities
            activities = [
                ActivityFactory(place=place,
                                max_participants=1,
                                participants=[user])
                for _ in range(self.activities_done_count)
            ]

            # activity feedback
            [
                FeedbackFactory(about=activity, given_by=user)
                for activity in activities[:self.feedback_count]
            ]
Beispiel #24
0
    def test_email_notification_reply_to_has_thread_id(self):
        user = VerifiedUserFactory()
        user2 = VerifiedUserFactory()
        group = GroupFactory(members=[user, user2])
        conversation = Conversation.objects.get_or_create_for_target(group)
        mail.outbox = []

        with execute_scheduled_tasks_immediately():
            message = ConversationMessage.objects.create(author=user, conversation=conversation, content='asdf')

        reply_to = parseaddr(mail.outbox[0].reply_to[0])[1]
        local_part = reply_to.split('@')[0]
        conversation_id, user_id, thread_id = parse_local_part(local_part)
        self.assertEqual(conversation_id, conversation.id)
        self.assertEqual(user_id, user2.id)
        self.assertEqual(thread_id, message.id)
Beispiel #25
0
    def setUpTestData(cls):
        cls.applicant = VerifiedUserFactory()
        cls.member = VerifiedUserFactory()
        cls.newcomer = VerifiedUserFactory()
        cls.group = GroupFactory(members=[cls.member],
                                 newcomers=[cls.newcomer])
        cls.application = ApplicationFactory(group=cls.group,
                                             user=cls.applicant)
        cls.conversation = Conversation.objects.get_for_target(cls.application)

        def make_application():
            applicant = VerifiedUserFactory()
            group = GroupFactory(members=[cls.member])
            ApplicationFactory(group=group, user=applicant)

        [make_application() for _ in range(5)]
Beispiel #26
0
    def setUp(self):
        self.applicant = VerifiedUserFactory()
        self.member = VerifiedUserFactory()
        self.newcomer = VerifiedUserFactory()
        self.group = GroupFactory(members=[self.member], newcomers=[self.newcomer])
        self.application = ApplicationFactory(group=self.group, user=self.applicant)
        self.conversation = Conversation.objects.get_for_target(self.application)

        def make_application():
            applicant = VerifiedUserFactory()
            group = GroupFactory(members=[self.member])
            ApplicationFactory(group=group, user=applicant)

        [make_application() for _ in range(5)]

        mail.outbox = []
Beispiel #27
0
 def setUp(self):
     self.user = VerifiedUserFactory()
     self.group = GroupFactory(members=[self.user])
     self.place = PlaceFactory(group=self.group)
     self.pickup = PickupDateFactory(place=self.place,
                                     collectors=[self.user])
     self.conversation = self.pickup.conversation
Beispiel #28
0
 def test_cannot_retrieve_issue_conversation_as_nonmember(self):
     issue = self.create_issue()
     self.client.force_login(user=VerifiedUserFactory())
     response = self.get_results('/api/issues/{}/conversation/'.format(
         issue.id))
     self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND,
                      response.data)
Beispiel #29
0
 def test_cannot_list_issues_as_nonmember(self):
     self.create_issue()
     self.client.force_login(user=VerifiedUserFactory())
     response = self.get_results('/api/issues/?group={}'.format(
         self.group.id))
     self.assertEqual(response.status_code, status.HTTP_200_OK,
                      response.data)
     self.assertEqual(len(response.data), 0)
 def setUp(self):
     self.verified_user = VerifiedUserFactory(email='*****@*****.**')
     self.url_request_password_reset = '/api/auth/password/request_reset/'
     self.url_password_reset = '/api/auth/password/reset/'
     self.type = VerificationCode.PASSWORD_RESET
     self.old_password = self.verified_user.display_name
     self.new_password = '******'
     mail.outbox = []