Example #1
0
    def test_download_csv_anonymous_email_notification(self):
        anonymous_email_notification = AnonymousEmailNotificationFactory()

        data = {
            'action': 'download_csv',
            '_selected_action': AnonymousEmailNotification.objects.all(
            ).values_list('pk', flat=True)
        }
        response = self.client.post(
            reverse(
                'admin:notifications_anonymousemailnotification_changelist'
            ),
            data,
            follow=True
        )

        expected_data = OrderedDict([
            ('category', str(anonymous_email_notification.category)),
            ('date_sent', str(anonymous_email_notification.date_sent)),
            ('email', str(anonymous_email_notification.email)),
            ('id', str(anonymous_email_notification.id)),
        ])
        actual = str(response.content, 'utf-8').split('\r\n')

        assert actual[0] == ','.join(expected_data.keys())
        assert actual[1] == ','.join(expected_data.values())
Example #2
0
def test_new_companies_in_sector_exclude_already_sent_recently(
        mock_task, settings):
    settings.NEW_COMPANIES_IN_SECTOR_FREQUENCY_DAYS = 3
    settings.NEW_COMPANIES_IN_SECTOR_SUBJECT = 'test subject'

    days_ago_three = datetime.utcnow() - timedelta(days=3)
    buyer_one = BuyerFactory.create(sector='AEROSPACE')
    buyer_two = BuyerFactory.create(sector='AEROSPACE')

    notification = AnonymousEmailNotificationFactory(email=buyer_two.email)
    notification.date_sent = days_ago_three
    notification.save()
    CompanyFactory(sectors=['AEROSPACE'], date_published=days_ago_three)
    notifications.new_companies_in_sector()

    assert len(mock_task.delay.call_args_list) == 1
    assert mock_task.delay.call_args[1]['recipient_email'] == buyer_one.email
def test_new_companies_in_sector_include_already_sent_long_time_ago(settings):
    settings.NEW_COMPANIES_IN_SECTOR_FREQUENCY_DAYS = 3
    settings.NEW_COMPANIES_IN_SECTOR_SUBJECT = 'test subject'

    days_ago_three = datetime.utcnow() - timedelta(days=3)
    days_ago_four = datetime.utcnow() - timedelta(days=4)
    buyer_one = BuyerFactory.create(sector='AEROSPACE')
    notification = AnonymousEmailNotificationFactory(email=buyer_one.email)
    notification.date_sent = days_ago_four
    notification.save()

    CompanyFactory(sectors=['AEROSPACE'], date_published=days_ago_three)

    mail.outbox = []  # reset after emails sent by signals
    notifications.new_companies_in_sector()

    assert len(mail.outbox) == 1

    assert mail.outbox[0].to == [buyer_one.email]
Example #4
0
def test_anonymous_email_notification_str_method():
    instance = AnonymousEmailNotificationFactory.build(
        email='*****@*****.**',
        category='new_companies_in_sector'
    )
    assert str(instance) == '[email protected]: new_companies_in_sector'