Example #1
0
    def test_stat_to_list(self):
        expected_list = [
            {
                u'Bounces': u'0',
                u'Complaints': u'2',
                u'DeliveryAttempts': u'8',
                u'Rejects': u'0',
                u'Timestamp': u'2011-02-24T16:35:00Z',
            },
            {
                u'Bounces': u'1',
                u'Complaints': u'0',
                u'DeliveryAttempts': u'3',
                u'Rejects': u'0',
                u'Timestamp': u'2011-02-24T23:35:00Z',
            },
            {
                u'Bounces': u'0',
                u'Complaints': u'2',
                u'DeliveryAttempts': u'33',
                u'Rejects': u'0',
                u'Timestamp': u'2011-02-25T20:35:00Z',
            },
            {
                u'Bounces': u'0',
                u'Complaints': u'0',
                u'DeliveryAttempts': u'2',
                u'Rejects': u'3',
                u'Timestamp': u'2011-02-25T22:50:00Z',
            },
            {
                u'Bounces': u'1',
                u'Complaints': u'0',
                u'DeliveryAttempts': u'11',
                u'Rejects': u'0',
                u'Timestamp': u'2011-02-28T13:50:00Z',
            },
            {
                u'Bounces': u'0',
                u'Complaints': u'0',
                u'DeliveryAttempts': u'3',
                u'Rejects': u'3',
                u'Timestamp': u'2011-02-28T23:35:00Z',
            },
            {
                u'Bounces': u'0',
                u'Complaints': u'0',
                u'DeliveryAttempts': u'6',
                u'Rejects': u'0',
                u'Timestamp': u'2011-03-01T13:20:00Z',
            },
        ]
        actual = stats_to_list(self.stats_dict, localize=False)

        self.assertEqual(len(actual), len(expected_list))
        self.assertEqual(actual, expected_list)
Example #2
0
    def test_stat_to_list(self):
        expected_list = [
            {
                u'Bounces': 0,
                u'Complaints': 2,
                u'DeliveryAttempts': 8,
                u'Rejects': 0,
                u'Timestamp': datetime(2011, 2, 24, 16, 35, tzinfo=pytz.utc),
            },
            {
                u'Bounces': 1,
                u'Complaints': 0,
                u'DeliveryAttempts': 3,
                u'Rejects': 0,
                u'Timestamp': datetime(2011, 2, 24, 23, 35, tzinfo=pytz.utc),
            },
            {
                u'Bounces': 0,
                u'Complaints': 2,
                u'DeliveryAttempts': 33,
                u'Rejects': 0,
                u'Timestamp': datetime(2011, 2, 25, 20, 35, tzinfo=pytz.utc),
            },
            {
                u'Bounces': 0,
                u'Complaints': 0,
                u'DeliveryAttempts': 2,
                u'Rejects': 3,
                u'Timestamp': datetime(2011, 2, 25, 22, 50, tzinfo=pytz.utc),
            },
            {
                u'Bounces': 1,
                u'Complaints': 0,
                u'DeliveryAttempts': 11,
                u'Rejects': 0,
                u'Timestamp': datetime(2011, 2, 28, 13, 50, tzinfo=pytz.utc),
            },
            {
                u'Bounces': 0,
                u'Complaints': 0,
                u'DeliveryAttempts': 3,
                u'Rejects': 3,
                u'Timestamp': datetime(2011, 2, 28, 23, 35, tzinfo=pytz.utc),
            },
            {
                u'Bounces': 0,
                u'Complaints': 0,
                u'DeliveryAttempts': 6,
                u'Rejects': 0,
                u'Timestamp': datetime(2011, 3, 1, 13, 20, tzinfo=pytz.utc),
            },
        ]
        actual = stats_to_list(self.stats_dict, localize=False)

        self.assertEqual(len(actual), len(expected_list))
        self.assertEqual(actual, expected_list)
Example #3
0
    def test_stat_to_list(self):
        expected_list = [
            {
                u'Bounces': u'0',
                u'Complaints': u'2',
                u'DeliveryAttempts': u'8',
                u'Rejects': u'0',
                u'Timestamp': u'2011-02-24T16:35:00Z',
            },
            {
                u'Bounces': u'1',
                u'Complaints': u'0',
                u'DeliveryAttempts': u'3',
                u'Rejects': u'0',
                u'Timestamp': u'2011-02-24T23:35:00Z',
            },
            {
                u'Bounces': u'0',
                u'Complaints': u'2',
                u'DeliveryAttempts': u'33',
                u'Rejects': u'0',
                u'Timestamp': u'2011-02-25T20:35:00Z',
            },
            {
                u'Bounces': u'0',
                u'Complaints': u'0',
                u'DeliveryAttempts': u'2',
                u'Rejects': u'3',
                u'Timestamp': u'2011-02-25T22:50:00Z',
            },
            {
                u'Bounces': u'1',
                u'Complaints': u'0',
                u'DeliveryAttempts': u'11',
                u'Rejects': u'0',
                u'Timestamp': u'2011-02-28T13:50:00Z',
            },
            {
                u'Bounces': u'0',
                u'Complaints': u'0',
                u'DeliveryAttempts': u'3',
                u'Rejects': u'3',
                u'Timestamp': u'2011-02-28T23:35:00Z',
            },
            {
                u'Bounces': u'0',
                u'Complaints': u'0',
                u'DeliveryAttempts': u'6',
                u'Rejects': u'0',
                u'Timestamp': u'2011-03-01T13:20:00Z',
            },
        ]
        actual = stats_to_list(self.stats_dict, localize=False)

        self.assertEqual(len(actual), len(expected_list))
        self.assertEqual(actual, expected_list)
Example #4
0
    def test_sum_stats(self):
        expected = {
            'Bounces': 2,
            'Complaints': 4,
            'DeliveryAttempts': 66,
            'Rejects': 6,
        }

        stats = stats_to_list(self.stats_dict)
        actual = sum_stats(stats)

        self.assertEqual(actual, expected)
Example #5
0
    def test_sum_stats(self):
        expected = {
            'Bounces': 2,
            'Complaints': 4,
            'DeliveryAttempts': 66,
            'Rejects': 6,
        }

        stats = stats_to_list(self.stats_dict)
        actual = sum_stats(stats)

        self.assertEqual(actual, expected)
Example #6
0
    def handle(self, *args, **options):

        connection = boto3.client(
            'ses',
            aws_access_key_id=settings.ACCESS_KEY,
            aws_secret_access_key=settings.SECRET_KEY,
            region_name=settings.AWS_SES_REGION_NAME,
            endpoint_url=settings.AWS_SES_REGION_ENDPOINT_URL,
            config=settings.AWS_SES_CONFIG,
        )
        stats = connection.get_send_statistics()
        data_points = stats_to_list(stats, localize=False)
        stats_dict = defaultdict(stat_factory)

        for data in data_points:
            attempts = int(data['DeliveryAttempts'])
            bounces = int(data['Bounces'])
            complaints = int(data['Complaints'])
            rejects = int(data['Rejects'])
            date = data['Timestamp'].date()
            stats_dict[date]['delivery_attempts'] += attempts
            stats_dict[date]['bounces'] += bounces
            stats_dict[date]['complaints'] += complaints
            stats_dict[date]['rejects'] += rejects

        for k, v in stats_dict.items():
            stat, created = SESStat.objects.get_or_create(
                date=k,
                defaults={
                    'delivery_attempts': v['delivery_attempts'],
                    'bounces': v['bounces'],
                    'complaints': v['complaints'],
                    'rejects': v['rejects'],
                })

            # If statistic is not new, modify data if values are different
            if not created and stat.delivery_attempts != v['delivery_attempts']:
                stat.delivery_attempts = v['delivery_attempts']
                stat.bounces = v['bounces']
                stat.complaints = v['complaints']
                stat.rejects = v['rejects']
                stat.save()
    def handle(self, *args, **options):

        connection = SESConnection(
            aws_access_key_id=settings.ACCESS_KEY,
            aws_secret_access_key=settings.SECRET_KEY,
            proxy=settings.AWS_SES_PROXY,
            proxy_port=settings.AWS_SES_PROXY_PORT,
            proxy_user=settings.AWS_SES_PROXY_USER,
            proxy_pass=settings.AWS_SES_PROXY_PASS,
        )
        stats = connection.get_send_statistics()
        data_points = stats_to_list(stats, localize=False)
        stats_dict = defaultdict(stat_factory)

        for data in data_points:
            attempts = int(data['DeliveryAttempts'])
            bounces = int(data['Bounces'])
            complaints = int(data['Complaints'])
            rejects = int(data['Rejects'])
            date = data['Timestamp'].split('T')[0]
            stats_dict[date]['delivery_attempts'] += attempts
            stats_dict[date]['bounces'] += bounces
            stats_dict[date]['complaints'] += complaints
            stats_dict[date]['rejects'] += rejects

        for k, v in stats_dict.items():
            stat, created = SESStat.objects.get_or_create(
                date=k,
                defaults={
                    'delivery_attempts': v['delivery_attempts'],
                    'bounces': v['bounces'],
                    'complaints': v['complaints'],
                    'rejects': v['rejects'],
            })

            # If statistic is not new, modify data if values are different
            if not created and stat.delivery_attempts != v['delivery_attempts']:
                stat.delivery_attempts = v['delivery_attempts']
                stat.bounces = v['bounces']
                stat.complaints = v['complaints']
                stat.rejects = v['rejects']
                stat.save()
Example #8
0
    def handle(self, *args, **options):

        connection = SESConnection(
            aws_access_key_id=settings.ACCESS_KEY,
            aws_secret_access_key=settings.SECRET_KEY,
            proxy=settings.AWS_SES_PROXY,
            proxy_port=settings.AWS_SES_PROXY_PORT,
            proxy_user=settings.AWS_SES_PROXY_USER,
            proxy_pass=settings.AWS_SES_PROXY_PASS,
        )
        stats = connection.get_send_statistics()
        data_points = stats_to_list(stats, localize=False)
        stats_dict = defaultdict(stat_factory)

        for data in data_points:
            attempts = int(data['DeliveryAttempts'])
            bounces = int(data['Bounces'])
            complaints = int(data['Complaints'])
            rejects = int(data['Rejects'])
            date = data['Timestamp'].split('T')[0]
            stats_dict[date]['delivery_attempts'] += attempts
            stats_dict[date]['bounces'] += bounces
            stats_dict[date]['complaints'] += complaints
            stats_dict[date]['rejects'] += rejects

        for k, v in stats_dict.items():
            stat, created = SESStat.objects.get_or_create(
                date=k,
                defaults={
                    'delivery_attempts': v['delivery_attempts'],
                    'bounces': v['bounces'],
                    'complaints': v['complaints'],
                    'rejects': v['rejects'],
                })

            # If statistic is not new, modify data if values are different
            if not created and stat.delivery_attempts != v['delivery_attempts']:
                stat.delivery_attempts = v['delivery_attempts']
                stat.bounces = v['bounces']
                stat.complaints = v['complaints']
                stat.rejects = v['rejects']
                stat.save()
    def handle(self, *args, **options):

        connection = SESConnection(
            aws_access_key_id=getattr(settings, "AWS_ACCESS_KEY_ID", None),
            aws_secret_access_key=getattr(settings, "AWS_SECRET_ACCESS_KEY", None),
        )
        stats = connection.get_send_statistics()
        data_points = stats_to_list(stats, localize=False)
        stats_dict = defaultdict(stat_factory)

        for data in data_points:
            attempts = int(data["DeliveryAttempts"])
            bounces = int(data["Bounces"])
            complaints = int(data["Complaints"])
            rejects = int(data["Rejects"])
            date = data["Timestamp"].split("T")[0]
            stats_dict[date]["delivery_attempts"] += attempts
            stats_dict[date]["bounces"] += bounces
            stats_dict[date]["complaints"] += complaints
            stats_dict[date]["rejects"] += rejects

        for k, v in stats_dict.items():
            stat, created = SESStat.objects.get_or_create(
                date=k,
                defaults={
                    "delivery_attempts": v["delivery_attempts"],
                    "bounces": v["bounces"],
                    "complaints": v["complaints"],
                    "rejects": v["rejects"],
                },
            )

            # If statistic is not new, modify data if values are different
            if not created and stat.delivery_attempts != v["delivery_attempts"]:
                stat.delivery_attempts = v["delivery_attempts"]
                stat.bounces = v["bounces"]
                stat.complaints = v["complaints"]
                stat.rejects = v["rejects"]
                stat.save()