Exemplo n.º 1
0
    def setUpClass(cls):
        super(GraphsTestCase, cls).setUpClass()
        cls.factory = RequestFactory()

        Request(path="/admin/", ip="127.0.0.1").save()
        Request(path="/admin/", ip="127.0.0.1").save()
        Request(path="/admin/login/", ip="127.0.0.1").save()

        staff_user = User.objects.create_user(username="******", password="******")
        staff_user.is_staff = True
        staff_user.save()
        cls.staff_user = staff_user

        cls.coordinator = EditorFactory(user__email="*****@*****.**").user
        coordinators = get_coordinators()
        coordinators.user_set.add(cls.coordinator)

        user = UserFactory()
        cls.user = user

        cls.partner = PartnerFactory()

        cls.app = ApplicationFactory(partner=cls.partner)
        cls.app.status = Application.APPROVED
        cls.app.save()

        cls.dashboard_url = reverse("dashboard")
Exemplo n.º 2
0
    def test_user_renewal_notice_future_date(self):
        """
        If we have multiple authorizations to send emails for, let's make
        sure we send distinct emails to the right places.
        """
        editor2 = EditorFactory(user__email='*****@*****.**')

        authorization2 = Authorization()
        authorization2.authorized_user = editor2.user
        authorization2.authorizer = self.coordinator
        authorization2.partner = self.partner
        authorization2.date_expires = datetime.today() + timedelta(weeks=1)
        authorization2.save()

        call_command('user_renewal_notice')

        self.assertEqual(len(mail.outbox), 2)

        # Make sure that the two emails went to the two expected
        # email addresses.
        # This looks a little complicated because mail.outbox[0].to is a
        # (one element) list, and we need to compare sets to ensure we've
        # got 1 of each email.
        self.assertEqual(set([mail.outbox[0].to[0], mail.outbox[1].to[0]]),
                         set(['*****@*****.**', '*****@*****.**']))
Exemplo n.º 3
0
    def setUp(self):
        super(ApplicationCommentTest, self).setUp()
        self.editor = EditorFactory(user__email="*****@*****.**").user

        coordinators = get_coordinators()

        self.coordinator1 = EditorFactory(
            user__email="*****@*****.**", user__username="******"
        ).user
        self.coordinator2 = EditorFactory(
            user__email="*****@*****.**", user__username="******"
        ).user
        coordinators.user_set.add(self.coordinator1)
        coordinators.user_set.add(self.coordinator2)

        self.partner = PartnerFactory()
Exemplo n.º 4
0
    def setUpTestData(cls):
        super().setUpTestData()
        editor = EditorFactory(user__email="*****@*****.**")
        cls.user = editor.user

        cls.coordinator = EditorFactory().user
        coordinators = get_coordinators()
        coordinators.user_set.add(cls.coordinator)

        cls.partner = PartnerFactory()

        cls.authorization = Authorization()
        cls.authorization.user = cls.user
        cls.authorization.authorizer = cls.coordinator
        cls.authorization.date_expires = datetime.today() + timedelta(weeks=1)
        cls.authorization.save()
        cls.authorization.partners.add(cls.partner)
Exemplo n.º 5
0
    def test_project_page_2021_launch_email_2(self):
        """
        Adding an inactive user shouldn't send another email.
        """
        _ = EditorFactory(user__email="*****@*****.**")
        call_command("project_page_2021_launch")

        self.assertEqual(len(mail.outbox), 1)
Exemplo n.º 6
0
    def setUp(self):
        super(UserRenewalNoticeTest, self).setUp()
        editor = EditorFactory(user__email="*****@*****.**")
        self.user = editor.user

        self.coordinator = EditorFactory().user
        coordinators = get_coordinators()
        coordinators.user_set.add(self.coordinator)

        self.partner = PartnerFactory()

        self.authorization = Authorization()
        self.authorization.user = self.user
        self.authorization.authorizer = self.coordinator
        self.authorization.partner = self.partner
        self.authorization.date_expires = datetime.today() + timedelta(weeks=2)
        self.authorization.save()
Exemplo n.º 7
0
    def test_proxy_bundle_launch_email_2(self):
        """
        Adding another user should result in two sent emails.
        """
        _ = EditorFactory(user__email="*****@*****.**")
        call_command("proxy_bundle_launch")

        self.assertEqual(len(mail.outbox), 2)
Exemplo n.º 8
0
    def handle(self, *args, **options):
        num_editors = options['num'][0]
        fake = Faker()

        existing_users = User.objects.all()

        # Superuser the only user, per twlight_vagrant README instructions.
        if existing_users.count() == 0:
            raise CommandError('No users present to Superuser. '
                               'Please login first.')
        elif existing_users.count() > 1:
            raise CommandError('More than one user present. '
                               'Please ensure that only one user is present.')
        else:
            user = existing_users[0]
            user.is_superuser = True
            user.is_staff = True
            user.save()

        for _ in range(num_editors):
            user = UserFactory(email=fake.word() + "@example.com")
            editor = EditorFactory(
                user=user,
                real_name=fake.name(),
                country_of_residence=fake.country(),
                occupation=fake.job(),
                affiliation=fake.company(),
                wp_editcount=random.randint(50, 2000),
                wp_registered=fake.date_time_between(start_date="-10y",
                                                     end_date="now",
                                                     tzinfo=None),
                contributions=fake.paragraph(nb_sentences=4))

        # All users who aren't the superuser
        all_users = User.objects.exclude(is_superuser=True)

        # Flag wp_valid correctly if user is valid
        for user in all_users:
            date_valid = datetime.today().date() - timedelta(
                days=182) >= user.editor.wp_registered

            if user.editor.wp_editcount > 500 and date_valid:
                user.editor.wp_valid = True
                user.editor.save()

        # Make 5 random users coordinators
        coordinators = get_coordinators()
        for user in random.sample(all_users, 5):
            user.groups.add(coordinators)
            user.save()

        # Set 5 random non-coordinator users to have restricted data processing
        restricted = get_restricted()
        non_coordinators = all_users.exclude(groups__name='coordinators')
        for user in random.sample(non_coordinators, 5):
            user.groups.add(restricted)
            user.save()
Exemplo n.º 9
0
    def test_editors_only_1(self):
        """
        EditorsOnly allows editors.
        """
        user = UserFactory()
        _ = EditorFactory(user=user)

        req = RequestFactory()
        req.user = user

        test = TestEditorsOnly()
        test.dispatch(req)
Exemplo n.º 10
0
    def test_visibility_of_not_available_1(self):
        """Regular users shouldn't see NOT_AVAILABLE partner pages."""
        partner = PartnerFactory(status=Partner.NOT_AVAILABLE)
        detail_url = partner.get_absolute_url()

        editor = EditorFactory()

        request = RequestFactory().get(detail_url)
        request.user = editor.user
        with self.assertRaises(Http404):
            # We must explicitly pass kwargs to the view even though they are
            # implied by the URL.
            _ = PartnersDetailView.as_view()(request, pk=partner.pk)
Exemplo n.º 11
0
    def test_self_only_2(self):
        """
        SelfOnly allows users who own the object returned by get_object.
        """
        user = UserFactory()
        editor = EditorFactory(user=user)

        req = RequestFactory()
        req.user = user

        test = TestSelfOnly(obj=editor)

        test.dispatch(req)
Exemplo n.º 12
0
    def test_coordinators_or_self_4(self):
        """
        CoordinatorOrSelf should users who own the object returned by the
        view's get_object.
        """
        user = UserFactory()
        editor = EditorFactory(user=user)

        req = RequestFactory()
        req.user = user

        test = TestCoordinatorOrSelf(obj=editor)

        test.dispatch(req)
Exemplo n.º 13
0
    def setUpTestData(cls):
        super().setUpTestData()
        editor = EditorFactory(user__email="*****@*****.**")
        cls.user = editor.user

        # The user logged in:
        request = RequestFactory().get("/login")
        signals.user_logged_in.send(sender=cls.user.__class__,
                                    request=request,
                                    user=cls.user)

        cls.coordinator = EditorFactory().user
        coordinators = get_coordinators()
        coordinators.user_set.add(cls.coordinator)

        cls.partner = PartnerFactory()

        cls.authorization = Authorization()
        cls.authorization.user = cls.user
        cls.authorization.authorizer = cls.coordinator
        cls.authorization.date_expires = datetime.today() + timedelta(weeks=1)
        cls.authorization.save()
        cls.authorization.partners.add(cls.partner)
Exemplo n.º 14
0
    def setUp(self):
        super(ProjectPage2021LaunchTest, self).setUp()
        editor = EditorFactory(user__email="*****@*****.**")
        self.user = editor.user

        # The user logged in:
        request = RequestFactory().get("/login")
        signals.user_logged_in.send(sender=self.user.__class__,
                                    request=request,
                                    user=self.user)

        self.coordinator = EditorFactory().user
        coordinators = get_coordinators()
        coordinators.user_set.add(self.coordinator)

        self.partner = PartnerFactory()

        self.authorization = Authorization()
        self.authorization.user = self.user
        self.authorization.authorizer = self.coordinator
        self.authorization.date_expires = datetime.today() + timedelta(weeks=1)
        self.authorization.save()
        self.authorization.partners.add(self.partner)
Exemplo n.º 15
0
    def test_proxy_auth_renewals_csv(self):
        """
        Test that the CSVProxyAuthAndRenewals csv download works
        """
        partner1 = PartnerFactory(authorization_method=Partner.PROXY)
        partner2 = PartnerFactory(authorization_method=Partner.PROXY)

        editor1 = EditorFactory()
        editor2 = EditorFactory()

        parent_app = ApplicationFactory(
            status=Application.SENT,
            partner=partner1,
            editor=editor1,
            sent_by=self.coordinator,
        )
        ApplicationFactory(
            status=Application.SENT,
            partner=partner1,
            editor=editor1,
            parent=parent_app,
            sent_by=self.coordinator,
        )
        ApplicationFactory(
            status=Application.SENT,
            partner=partner2,
            editor=editor2,
            sent_by=self.coordinator,
        )

        request = self.factory.get(reverse("csv:proxy_authorizations"))
        request.user = self.user

        response = views.CSVProxyAuthRenewalRate.as_view()(request)

        expected_data = [[str(date.today()), "2", "1", "50.0%"]]
        self._verify_equal(response, expected_data)
Exemplo n.º 16
0
    def test_visibility_of_not_available_2(self):
        """
        Regular users shouldn't be able to see NOT_AVAILABLE partners in the
        listview.
        """
        partner = PartnerFactory(status=Partner.NOT_AVAILABLE)
        list_url = reverse('partners:list')

        editor = EditorFactory()

        request = RequestFactory().get(list_url)
        request.user = editor.user
        response = PartnersListView.as_view()(request)

        self.assertNotContains(response, partner.get_absolute_url())
Exemplo n.º 17
0
    def test_visibility_of_not_available_4(self):
        """
        Staff users *should* see NOT_AVAILABLE partner pages in the list view.
        """
        partner = PartnerFactory(status=Partner.NOT_AVAILABLE)
        list_url = reverse('partners:list')

        editor = EditorFactory()
        editor.user.is_staff = True
        editor.user.save()

        request = RequestFactory().get(list_url)
        request.user = editor.user
        response = PartnersListView.as_view()(request)

        self.assertContains(response, partner.get_absolute_url())
Exemplo n.º 18
0
    def setUpClass(cls):
        super(PartnerModelTests, cls).setUpClass()
        cls.lang_en, _ = Language.objects.get_or_create(language='en')
        cls.lang_fr, _ = Language.objects.get_or_create(language='fr')

        editor = EditorFactory()
        coordinators = get_coordinators()
        coordinators.user_set.add(editor.user)
        UserProfileFactory(user=editor.user, terms_of_use=True)

        cls.coordinator = editor.user

        # We should mock out any call to messages call in the view, since
        # RequestFactory (unlike Client) doesn't run middleware. If you
        # actually want to test that messages are displayed, use Client(),
        # and stop/restart the patcher.
        cls.message_patcher = patch('TWLight.applications.views.messages.add_message')
        cls.message_patcher.start()
Exemplo n.º 19
0
    def test_request_application_view_context_1(self):
        """
        The any_waitlisted context on RequestApplicationView should True if
        there are waitlisted Partners.
        """
        # Set up request.
        req_url = reverse('applications:request')

        editor = EditorFactory()
        request = RequestFactory().get(req_url)
        request.user = editor.user

        # Ensure there is at least one waitlisted partner.
        partner = PartnerFactory(status=Partner.WAITLIST)

        # Test response.
        resp = RequestApplicationView.as_view()(request)
        self.assertEqual(resp.context_data['any_waitlisted'], True)
Exemplo n.º 20
0
 def test_contact_us_emails(self, mock_email):
     factory = RequestFactory()
     request = factory.post(get_form_target())
     request.user = UserFactory()
     editor = EditorFactory()
     reply_to = ['*****@*****.**']
     cc = ['*****@*****.**']
     
     self.assertEqual(len(mail.outbox), 0)
     
     mail_instance = MagicMailBuilder(template_mail_cls=InlineCSSTemplateMail)
     email = mail_instance.contact_us_email('*****@*****.**', 
         {'editor_wp_username': editor.wp_username,
          'body': 'This is a test email'})
     email.extra_headers["Reply-To"] = ", ".join(reply_to)
     email.extra_headers["Cc"] = ", ".join(cc)
     email.send()
     
     self.assertEqual(len(mail.outbox), 1)
Exemplo n.º 21
0
    def test_request_application_view_context_2(self):
        """
        The any_waitlisted context on RequestApplicationView should False if
        there are not waitlisted Partners.
        """
        # Set up request.
        req_url = reverse('applications:request')

        editor = EditorFactory()
        request = RequestFactory().get(req_url)
        request.user = editor.user

        # Ensure there are no waitlisted partners.
        for partner in Partner.objects.filter(status=Partner.WAITLIST):
            partner.delete()

        # Test response.
        resp = RequestApplicationView.as_view()(request)
        self.assertEqual(resp.context_data['any_waitlisted'], False)
Exemplo n.º 22
0
    def test_visibility_of_not_available_3(self):
        """
        Staff users *should* see NOT_AVAILABLE partner pages.
        We won't test to see if they include the message, because RequestFactory
        doesn't include message middleware, but we can't use the Django test
        client to log in users without passwords (which is our normal user).
        """
        partner = PartnerFactory(status=Partner.NOT_AVAILABLE)
        detail_url = partner.get_absolute_url()

        editor = EditorFactory()
        editor.user.is_staff = True
        editor.user.save()

        request = RequestFactory().get(detail_url)
        request.user = editor.user

        # This should not raise Http404.
        response = PartnersDetailView.as_view()(request, pk=partner.pk)
        self.assertEqual(response.status_code, 200)
Exemplo n.º 23
0
    def test_toggle_waitlist_2(self):
        """
        Posting to the toggle waitlist view sets a WAITLIST partner to
        AVAILABLE.
        """
        # Create needed objects.
        editor = EditorFactory()
        coordinators = get_coordinators()
        coordinators.user_set.add(editor.user)
        UserProfileFactory(user=editor.user, terms_of_use=True)

        partner = PartnerFactory(status=Partner.WAITLIST)

        # Set up request.
        url = reverse('partners:toggle_waitlist', kwargs={'pk': partner.pk})

        request = RequestFactory().post(url)
        request.user = editor.user

        _ = PartnersToggleWaitlistView.as_view()(request, pk=partner.pk)
        partner.refresh_from_db()
        self.assertEqual(partner.status, Partner.AVAILABLE)
Exemplo n.º 24
0
    def test_toggle_waitlist_access(self):
        """
        Only coordinators can post to the toggle waitlist view.
        """
        # Create needed objects.
        editor = EditorFactory()
        coordinators = get_coordinators()
        coordinators.user_set.add(editor.user)
        UserProfileFactory(user=editor.user, terms_of_use=True)

        partner = PartnerFactory(status=Partner.AVAILABLE)

        # Set up request.
        url = reverse('partners:toggle_waitlist', kwargs={'pk': partner.pk})

        request = RequestFactory().post(url)
        request.user = editor.user

        # This should work and not throw an error.
        resp = PartnersToggleWaitlistView.as_view()(request, pk=partner.pk)

        coordinators.user_set.remove(editor.user)
        with self.assertRaises(PermissionDenied):
            _ = PartnersToggleWaitlistView.as_view()(request, pk=partner.pk)
Exemplo n.º 25
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.partner1 = PartnerFactory(
         authorization_method=Partner.PROXY,
         status=Partner.AVAILABLE,
         featured=True,
         new_tags={"tags": ["music_tag"]},
     )
     cls.partner2 = PartnerFactory(
         authorization_method=Partner.PROXY,
         status=Partner.AVAILABLE,
         requested_access_duration=True,
         new_tags={"tags": ["art_tag"]},
     )
     cls.partner3 = PartnerFactory(
         authorization_method=Partner.CODES,
         status=Partner.AVAILABLE,
         featured=True,
         new_tags={"tags": ["music_tag"]},
     )
     cls.partner4 = PartnerFactory(
         authorization_method=Partner.PROXY,
         status=Partner.AVAILABLE,
         featured=True,
         new_tags={"tags": ["art_tag"]},
     )
     cls.partner5 = PartnerFactory(
         authorization_method=Partner.PROXY,
         status=Partner.AVAILABLE,
         specific_stream=True,
         new_tags={"tags": ["multidisciplinary_tag"]},
     )
     cls.user_editor = UserFactory(username="******")
     cls.editor1 = EditorFactory(user=cls.user_editor)
     cls.editor1.wp_bundle_eligible = True
     cls.editor1.save()
Exemplo n.º 26
0
 def setUpTestData(cls):
     super().setUpTestData()
     editor1 = EditorFactory(user__email="*****@*****.**")
     editor2 = EditorFactory(user__email="*****@*****.**")
Exemplo n.º 27
0
 def setUp(self):
     super(ProxyBundleLaunchTest, self).setUp()
     editor = EditorFactory(user__email="*****@*****.**")
     self.user = editor.user
Exemplo n.º 28
0
 def setUp(self):
     super(ContactUsTest, self).setUp()
     self.editor = EditorFactory(user__email="*****@*****.**").user
Exemplo n.º 29
0
 def setUp(self):
     super(ApplicationStatusTest, self).setUp()
     self.coordinator = EditorFactory().user
     coordinators = get_coordinators()
     coordinators.user_set.add(self.coordinator)
Exemplo n.º 30
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.editor = EditorFactory(user__email="*****@*****.**").user