Example #1
0
 def test_submission_banned_user(self):
     """Check that banned users' content is marked as not allowed."""
     user = UserFactory()
     user.ban()
     submission = SubmissionFactory(author=user)
     self.assertFalse(submission.is_erased)
     self.assertTrue(submission.is_rejected)
Example #2
0
 def setUp(self):
     self.client = Client()
     self.user1 = UserFactory.create()
     self.user2 = UserFactory.create()
     self.user3 = UserFactory.create()
     self.text = 'Test post'
     self.post = Post.objects.create(text=self.text, author=self.user3)
Example #3
0
    def test_link_failure(self, create_link):
        """If creating a link fails, still return a 200 OK."""
        create_link.return_value = None
        self.client.fb_login(self.user)
        UserFactory.create(email='*****@*****.**')

        response = self.client.post(self.url,
                                    {'affiliates_email': '*****@*****.**'})
        eq_(response.status_code, 200)
Example #4
0
 def test_submission_zone_private_perv(self):
     """Private submissions don't show up in the zone page for
     perv users.
     """
     user = UserFactory()
     user.set_perv(True)
     do_login(self.client, user)
     submission = SubmissionFactory()
     submission.hide()
     response = self.client.get(submission.zone.get_absolute_url())
     self.assertContains(response, submission.title, status_code=200)
Example #5
0
 def test_submission_subscribed_private_perv(self):
     """Private submissions show up in the subscribed page for pervs.
     """
     user = UserFactory()
     user.set_perv(True)
     do_login(self.client, user)
     submission = SubmissionFactory()
     submission.hide()
     submission.zone.subscribe(submission.author)
     response = self.client.get(submission.author.get_subscribed_url())
     self.assertContains(response, submission.title, status_code=200)
Example #6
0
 def setUp(self):
     self.client = Client()
     self.user1 = UserFactory.create()
     self.user2 = UserFactory.create()
     self.old_text = 'Тестовая запись'
     self.edited_text = 'Отредактированная тестовоая запись'
     self.post = Post.objects.create(text=self.old_text, author=self.user1)
     self.context = {
         'username': self.user1.username,
         'post_id': self.post.pk
     }
Example #7
0
 def test_submission_index_private_perv(self):
     """Private submissions don't show up in the front page for
     perv users.
     """
     user = UserFactory()
     user.set_perv(True)
     do_login(self.client, user)
     submission = SubmissionFactory()
     submission.hide()
     response = self.client.get(reverse('submissions:global'))
     self.assertContains(response, submission.title, status_code=200)
Example #8
0
    def test_add_default_permissions(self):
        """
        Test that the default set of permissions are assigned when a new user is
        created.
        """
        user = UserFactory()
        ok_(user.has_perm('users.can_share_website'))

        # Ensure permissions aren't overwritten for existing users.
        user.user_permissions = []
        user.save()
        user = refresh_model(user)
        eq_(list(user.user_permissions.all()), [])
Example #9
0
    def test_add_default_permissions_does_not_overwrite(self):
        """
        If a newly created user has some permissions already specified, do not
        overwrite them when adding the default permissions.
        """
        permission = PermissionFactory.create()
        user = UserFactory()
        user.user_permissions = [permission]
        user.save()
        user = refresh_model(user)

        app_label = permission.content_type.app_label
        codename = permission.codename
        ok_(user.has_perm('%s.%s' % (app_label, codename)))
Example #10
0
    def test_link_success(self, create_link, send_activation_email):
        """
        If creating a link succeeds, send an activation email and return a 200
        OK.
        """
        link = FacebookAccountLinkFactory.create()
        create_link.return_value = link
        self.client.fb_login(self.user)
        UserFactory.create(email='*****@*****.**')

        response = self.client.post(self.url,
                                    {'affiliates_email': '*****@*****.**'})
        eq_(response.status_code, 200)
        ok_(send_activation_email.called)
        eq_(send_activation_email.call_args[0][1], link)
Example #11
0
 def setUp(self):
     self.client = Client()
     self.user = UserFactory.create()
     self.comment = 'Test comment'
     self.post = Post.objects.create(text='Test post', author=self.user)
     self.context = {
         'username': self.user.username,
         'post_id': self.post.pk
     }
Example #12
0
    def test_affiliates_email_validation(self):
        """
        The affiliates_email field is only valid if an Affiliates user exists
        with the specified email address.
        """
        form = FacebookAccountLinkForm({'affiliates_email': '*****@*****.**'})
        eq_(form.is_valid(), False)

        user = UserFactory.create()
        form = FacebookAccountLinkForm({'affiliates_email': user.email})
        eq_(form.is_valid(), True)
Example #13
0
    def test_create_link_active_link(self):
        """If an active link already exists, create_link should return False."""
        link = FacebookAccountLinkFactory.create(is_active=True)
        result = self.manager.create_link(link.facebook_user,
                                          link.affiliates_user.email)
        eq_(result, False)

        # Test an active link with a different email address.
        user = UserFactory.create()
        result = self.manager.create_link(link.facebook_user, user.email)
        eq_(result, False)
Example #14
0
    def test_create_link_active_link(self):
        """If an active link already exists, create_link should return False."""
        link = FacebookAccountLinkFactory.create(is_active=True)
        result = self.manager.create_link(link.facebook_user,
                                          link.affiliates_user.email)
        eq_(result, False)

        # Test an active link with a different email address.
        user = UserFactory.create()
        result = self.manager.create_link(link.facebook_user, user.email)
        eq_(result, False)
Example #15
0
    def test_affiliates_email_validation(self):
        """
        The affiliates_email field is only valid if an Affiliates user exists
        with the specified email address.
        """
        form = FacebookAccountLinkForm({'affiliates_email': '*****@*****.**'})
        eq_(form.is_valid(), False)

        user = UserFactory.create()
        form = FacebookAccountLinkForm({'affiliates_email': user.email})
        eq_(form.is_valid(), True)
Example #16
0
 def test_create_link_success(self):
     """
     If no link exists, create_link should create one and save it to the
     database.
     """
     fb_user = FacebookUserFactory.create()
     user = UserFactory.create()
     link = self.manager.create_link(fb_user, user.email)
     eq_(link.affiliates_user, user)
     eq_(link.facebook_user, fb_user)
     eq_(link.is_active, False)
     ok_(self.manager.filter(pk=link.pk).exists())
Example #17
0
 def test_create_link_success(self):
     """
     If no link exists, create_link should create one and save it to the
     database.
     """
     fb_user = FacebookUserFactory.create()
     user = UserFactory.create()
     link = self.manager.create_link(fb_user, user.email)
     eq_(link.affiliates_user, user)
     eq_(link.facebook_user, fb_user)
     eq_(link.is_active, False)
     ok_(self.manager.filter(pk=link.pk).exists())
Example #18
0
    def test_purge_delete_everything(self):
        """Ensure that purge deletes all relevant database entries."""
        fb_user = FacebookUserFactory.create()
        user = UserFactory.create()
        link = FacebookAccountLinkFactory.create(affiliates_user=user,
                                                 facebook_user=fb_user)
        instance = FacebookBannerInstanceFactory.create(user=fb_user)
        personal_items = [(item.__class__, item.id)
                          for item in (fb_user, link, instance)]

        self.manager.purge_user_data(fb_user)
        for klass, id in personal_items:
            eq_(klass.objects.filter(id=id).exists(), False)
Example #19
0
    def test_purge_delete_everything(self):
        """Ensure that purge deletes all relevant database entries."""
        fb_user = FacebookUserFactory.create()
        user = UserFactory.create()
        link = FacebookAccountLinkFactory.create(affiliates_user=user,
                                                 facebook_user=fb_user)
        instance = FacebookBannerInstanceFactory.create(user=fb_user)
        personal_items = [(item.__class__, item.id) for item in
                          (fb_user, link, instance)]

        self.manager.purge_user_data(fb_user)
        for klass, id in personal_items:
            eq_(klass.objects.filter(id=id).exists(), False)
Example #20
0
 def setUp(self):
     self.client = Client()
     self.user = UserFactory.create()
     self.client.force_login(self.user)
     self.group = Group.objects.create(title='Test Group',
                                       slug='testgroup',
                                       description='test group')
     self.post = Post.objects.create(text='Test post', author=self.user)
     self.context = {
         'username': self.user.username,
         'post_id': self.post.pk
     }
     self.path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
     img = Image.new("RGB", (100, 100), (0, 0, 0))
     img.save('testimg.jpg')
     f = open('testfile.txt', 'tw', encoding='utf-8')
     f.write('Test')
     f.close()
Example #21
0
    def test_add_default_permissions(self):
        """
        Test that the default set of permissions are assigned when a new user is
        created.
        """
        user = UserFactory()
        ok_(user.has_perm('users.can_share_website'))

        # Ensure permissions aren't overwritten for existing users.
        user.user_permissions = []
        user.save()
        user = refresh_model(user)
        eq_(list(user.user_permissions.all()), [])
Example #22
0
    def test_add_default_permissions_does_not_overwrite(self):
        """
        If a newly created user has some permissions already specified, do not
        overwrite them when adding the default permissions.
        """
        permission = PermissionFactory.create()
        user = UserFactory()
        user.user_permissions = [permission]
        user.save()
        user = refresh_model(user)

        app_label = permission.content_type.app_label
        codename = permission.codename
        ok_(user.has_perm('%s.%s' % (app_label, codename)))
Example #23
0
 def setUp(self):
     self.client = Client()
     self.user = UserFactory.create()
     self.client.force_login(self.user)
Example #24
0
 def setUp(self):
     self.client = Client()
     self.new_text = 'Новая тестовая запись'
     self.user = UserFactory.create()
Example #25
0
 def setUp(self):
     self.user = UserFactory.create()
     self.browserid_login(self.user.email)
 def setUp(self):
     self.user = UserFactory.create()
     self.browserid_login(self.user.email)