예제 #1
0
    def it_only_sends_to_unsent_members_and_shows_failed_stat(
            self, mocker, db, db_session, sample_email, sample_member,
            sample_email_provider):
        mocker.patch.dict('app.application.config', {
            'ENVIRONMENT': 'test',
            'EMAIL_RESTRICT': None
        })

        member_1 = create_member(name='Test 1', email='*****@*****.**')
        member_2 = create_member(name='Test 2', email='*****@*****.**')
        create_member(name='Test 2', email='*****@*****.**', active=False)

        create_email_to_member(sample_email.id,
                               sample_member.id,
                               status_code=500)

        # respond with 201 on 2nd call
        mock_send_email = mocker.patch('app.na_celery.email_tasks.send_email',
                                       side_effect=[
                                           (200, sample_email_provider.id),
                                           (201, sample_email_provider.id)
                                       ])
        send_emails(sample_email.id)

        assert mock_send_email.call_count == 2
        assert mock_send_email.call_args_list[0][0][0] == member_1.email
        assert mock_send_email.call_args_list[1][0][0] == member_2.email
        assert sample_email.serialize()['emails_sent_counts'] == {
            'success': 2,
            'failed': 1,
            'total_active_members': 3
        }
예제 #2
0
    def it_gets_all_emails_count_for_chosen_provider(self, db, db_session):
        email = create_email()
        member = create_member(email='*****@*****.**', name='Test1')
        create_email_to_member(email_id=email.id, member_id=member.id)

        email_to_member = create_email_to_member()

        assert dao_get_todays_email_count_for_provider(
            email_to_member.email_provider_id) == 2
예제 #3
0
    def it_gets_emails_count_only_for_today_only(self, db, db_session):
        email = create_email()
        member = create_member(email='*****@*****.**', name='Test1')
        created_at = datetime.now() - timedelta(days=1)
        create_email_to_member(created_at=created_at,
                               email_id=email.id,
                               member_id=member.id)

        email_to_member = create_email_to_member()

        assert dao_get_todays_email_count_for_provider(
            email_to_member.email_provider_id) == 1
예제 #4
0
    def it_gets_past_hour_emails_for_provider(self, db, db_session,
                                              sample_member, sample_email,
                                              sample_email_provider):
        email = create_email(send_starts_at="2020-10-30",
                             send_after="2020-10-30T20:30:00",
                             expires="2020-11-07",
                             email_state=APPROVED)
        member = create_member(email="*****@*****.**")
        email_to_member = create_email_to_member(
            email_id=email.id, created_at="2020-10-31T12:00:00")
        create_email_to_member(
            member_id=sample_member.id,
            email_id=email.id,
            created_at="2020-10-31T10:00:00",
            email_provider_id=email_to_member.email_provider_id)
        create_email_to_member(
            member_id=member.id,
            email_id=email.id,
            created_at="2020-10-31T11:31:00",
            email_provider_id=email_to_member.email_provider_id)

        # use another provider to show that it doesn't get that count
        email_provider = create_email_provider(name="Another email provider")
        create_email_to_member(
            member_id=sample_member.id,
            email_id=sample_email.id,
            email_provider_id=email_provider.id,
            created_at="2020-10-31T11:31:00",
        )

        count = dao_get_past_hour_email_count_for_provider(
            email_to_member.email_provider_id)
        assert count == 2
예제 #5
0
    def it_get_emails_sent_count_for_specified_month(self, db, db_session,
                                                     sample_member,
                                                     sample_email):
        email = create_email(send_starts_at="2020-11-30",
                             send_after="2020-11-30T20:30:00",
                             expires="2020-12-20",
                             email_state=APPROVED)
        member = create_member(email="*****@*****.**")
        # counted
        create_email_to_member(email_id=email.id,
                               created_at="2020-11-30T12:00:00")
        # not counted
        create_email_to_member(member_id=sample_member.id,
                               email_id=email.id,
                               created_at="2020-12-11T12:30:00")
        create_email_to_member(member_id=member.id,
                               email_id=email.id,
                               created_at="2020-12-12T12:00:00")

        count = dao_get_emails_sent_count(month=11, year=2020)
        assert count == 1
예제 #6
0
    def it_get_todays_emails_count(self, db_session):
        email_to_member = create_email_to_member()

        assert dao_get_todays_email_count_for_provider(
            email_to_member.email_provider_id) == 1