Example #1
0
    def test_get_label_exists(self, get_label_info_mock):
        """
        Test the GmailManager on getting the label info from the database.
        """
        with open('lily/messaging/email/tests/data/get_label_info_INBOX.json'
                  ) as infile:
            json_obj = json.load(infile)
            get_label_info_mock.return_value = json_obj

        email_account = EmailAccount.objects.first()
        manager = GmailManager(email_account)
        # Label isn't present in the db, so it will do a mocked API call.
        label = manager.get_label(settings.GMAIL_LABEL_INBOX)

        # Verify that the Inbox label is present in the database.
        self.assertIsNotNone(label)
        self.assertTrue(
            EmailLabel.objects.filter(
                account=email_account,
                label_id=settings.GMAIL_LABEL_INBOX).exists())

        try:
            # Retrieve the same label again.
            manager.get_label(settings.GMAIL_LABEL_INBOX)
        except StopIteration:
            # Because the label is already in the database it should not do a (mocked) API call again.
            self.fail('StopIteration should have been raised.')
Example #2
0
    def test_get_label_exists(self, get_label_info_mock):
        """
        Test the GmailManager on getting the label info from the database.
        """
        with open('lily/messaging/email/tests/data/get_label_info_INBOX.json') as infile:
            json_obj = json.load(infile)
            get_label_info_mock.return_value = json_obj

        email_account = EmailAccount.objects.first()
        manager = GmailManager(email_account)
        # Label isn't present in the db, so it will do a mocked API call.
        label = manager.get_label(settings.GMAIL_LABEL_INBOX)

        # Verify that the Inbox label is present in the database.
        self.assertIsNotNone(label)
        self.assertTrue(EmailLabel.objects.filter(account=email_account, label_id=settings.GMAIL_LABEL_INBOX).exists())

        try:
            # Retrieve the same label again.
            manager.get_label(settings.GMAIL_LABEL_INBOX)
        except StopIteration:
            # Because the label is already in the database it should not do a (mocked) API call again.
            self.fail('StopIteration should have been raised.')
Example #3
0
    def test_get_label(self, get_label_info_mock):
        """
        Test the GmailManager on getting the label info via an API call and that it is stored in the database.
        """
        with open('lily/messaging/email/tests/data/get_label_info_INBOX.json') as infile:
            json_obj = json.load(infile)
            get_label_info_mock.return_value = json_obj

        email_account = EmailAccount.objects.first()
        manager = GmailManager(email_account)
        # Label isn't present in the db, so it will do a mocked API call.
        label = manager.get_label(settings.GMAIL_LABEL_INBOX)

        # Verify that the Inbox label is present in the database.
        self.assertIsNotNone(label)
        self.assertTrue(EmailLabel.objects.filter(account=email_account, label_id=settings.GMAIL_LABEL_INBOX).exists())