Esempio n. 1
0
    def test_liberate_fetch_info_user_has_prefered_domain(self):
        domain = factories.DomainFactory()
        profile = self.user.inboxenprofile
        profile.prefered_domain = domain
        profile.save()

        tasks.liberate_fetch_info(None, {
            "user": self.user.id,
            "path": self.mail_dir
        })
        profile_data = json.load(
            open(os.path.join(self.mail_dir, "profile.json")))
        inbox_data = json.load(open(os.path.join(self.mail_dir, "inbox.json")))

        self.assertEqual(inbox_data, {})
        self.assertEqual(
            profile_data, {
                "id": self.user.id,
                "username": self.user.username,
                "is_active": self.user.is_active,
                "join_date": self.user.date_joined.isoformat(),
                "groups": [],
                "errors": [],
                "preferences": {
                    "prefer_html_email": True,
                    "prefered_domain": str(domain),
                    "display_images": 0,
                }
            })
Esempio n. 2
0
    def setUp(self):
        super(HomeViewTestCase, self).setUp()
        self.user = factories.UserFactory()
        domain = factories.DomainFactory()
        self.inboxes = factories.InboxFactory.create_batch(30, domain=domain, user=self.user)

        login = self.client.login(username=self.user.username, password="******", request=MockRequest(self.user))

        if not login:
            raise Exception("Could not log in")
Esempio n. 3
0
    def test_domain_queryset_methods(self):
        user = factories.UserFactory()
        other_user = factories.UserFactory(username="******")

        # all the permutations of Domains
        for args in itertools.product([True, False], [user, other_user, None]):
            factories.DomainFactory(enabled=args[0], owner=args[1])

        self.assertEqual(models.Domain.objects.available(user).count(), 2)
        self.assertEqual(models.Domain.objects.receiving().count(), 3)
Esempio n. 4
0
    def test_inbox_create(self):
        user = factories.UserFactory()
        domain = factories.DomainFactory()

        with self.assertRaises(models.Domain.DoesNotExist):
            models.Inbox.objects.create()

        inbox = models.Inbox.objects.create(domain=domain, user=user)

        self.assertIsInstance(inbox.created, datetime.datetime)
        self.assertEqual(inbox.user, user)
Esempio n. 5
0
    def setUp(self):
        super(SettingsTestCase, self).setUp()
        self.user = factories.UserFactory()
        other_user = factories.UserFactory(username="******")

        for args in itertools.product([True, False], [self.user, other_user, None]):
            factories.DomainFactory(enabled=args[0], owner=args[1])

        login = self.client.login(username=self.user.username, password="******", request=MockRequest(self.user))

        if not login:
            raise Exception("Could not log in")
Esempio n. 6
0
    def test_inbox_create_length(self):
        user = factories.UserFactory()
        domain = factories.DomainFactory()
        default_length = settings.INBOX_LENGTH

        with override_settings(INBOX_LENGTH=default_length + 1):
            inbox = models.Inbox.objects.create(user=user, domain=domain)
            self.assertEqual(len(inbox.inbox), default_length + 1)

            inbox = models.Inbox.objects.create(user=user, domain=domain, length=default_length + 3)
            self.assertEqual(len(inbox.inbox), default_length + 3)

        with self.assertRaises(AssertionError):
            inbox = models.Inbox.objects.create(user=user, domain=domain, length=-1)
Esempio n. 7
0
    def setUp(self):
        """Create the client and grab the user"""
        self.user = factories.UserFactory()
        self.other_user = factories.UserFactory(username="******")

        for args in itertools.product([True, False],
                                      [self.user, self.other_user, None]):
            factories.DomainFactory(enabled=args[0], owner=args[1])

        login = self.client.login(username=self.user.username,
                                  password="******",
                                  request=MockRequest(self.user))

        if not login:
            raise Exception("Could not log in")
Esempio n. 8
0
    def test_inbox_create_reserved(self):
        user = factories.UserFactory()
        domain = factories.DomainFactory()

        def reserved_mock():
            # return True and then False, regardless of input
            ret_vals = [False, True]

            def inner(*args, **kwargs):
                return ret_vals.pop()

            return inner

        with mock.patch("inboxen.managers.is_reserved") as r_mock:
            r_mock.side_effect = reserved_mock()
            models.Inbox.objects.create(domain=domain, user=user)

            self.assertEqual(r_mock.call_count, 2)
Esempio n. 9
0
    def test_inbox_create_integrity_error(self):
        user = factories.UserFactory()
        domain = factories.DomainFactory()
        inbox = models.Inbox.objects.create(domain=domain, user=user)

        def get_random_string_mock():
            # list of inboxes to be returned, in reverse order
            inboxes = ["a" * len(inbox.inbox), inbox.inbox]

            def inner(*args, **kwargs):
                return inboxes.pop()

            return inner

        with mock.patch("inboxen.managers.get_random_string") as r_mock:
            r_mock.side_effect = get_random_string_mock()
            new_inbox = models.Inbox.objects.create(domain=domain, user=user)

            self.assertEqual(new_inbox.inbox, "a" * len(inbox.inbox))
            self.assertEqual(r_mock.call_count, 2)
Esempio n. 10
0
    def test_counts(self):
        # test all the counting is done correctly
        domain = factories.DomainFactory()

        # user 1
        user1 = factories.UserFactory()
        inbox11 = factories.InboxFactory(domain=domain, user=user1)
        inbox12 = factories.InboxFactory(domain=domain, user=user1)
        factories.EmailFactory.create_batch(2, inbox=inbox11)
        factories.EmailFactory.create_batch(2, inbox=inbox12)

        # user 2
        user2 = factories.UserFactory()
        inbox21 = factories.InboxFactory(domain=domain, user=user2)
        inbox22 = factories.InboxFactory(domain=domain, user=user2)
        factories.EmailFactory.create_batch(2, inbox=inbox21)
        factories.EmailFactory.create_batch(2, inbox=inbox22)

        # user 3
        factories.UserFactory()

        tasks.statistics.delay()
        stats = models.Statistic.objects.get()

        self.assertEqual(stats.users["count"], 3)
        self.assertEqual(stats.users["new"], 3)
        self.assertEqual(stats.users["with_inboxes"], 2)

        self.assertEqual(stats.inboxes["inbox_count__sum"], 4)
        self.assertEqual(stats.inboxes["inbox_count__max"], 2)
        self.assertEqual(stats.inboxes["inbox_count__min"], 0)
        self.assertEqual(stats.inboxes["inbox_count__avg"], 4.0 / 3)

        self.assertEqual(stats.emails["email_count__sum"], 8)
        self.assertEqual(stats.emails["email_count__max"], 2)
        self.assertEqual(stats.emails["email_count__min"], 2)
        self.assertEqual(stats.emails["email_count__avg"], 2)
Esempio n. 11
0
 def setUp(self):
     self.user = factories.UserFactory(is_superuser=True)
     self.domain = factories.DomainFactory()
Esempio n. 12
0
 def test_domain_disabled(self):
     factories.DomainFactory(enabled=False)
     self.assertEqual(domains_available_check(None), [Error(DOMAIN_ERROR_MSG)])
Esempio n. 13
0
 def test_domain_enabled(self):
     factories.DomainFactory(enabled=True)
     self.assertEqual(domains_available_check(None), [])