コード例 #1
0
ファイル: test_utils.py プロジェクト: thenewguy/connect
    def test_open(self):
        """Test a full open creation"""
        initial_count = EmailOpen.objects.count()
        utils.create_open(OPEN_DATA, self.headers)
        new_count = EmailOpen.objects.count()

        self.assertEqual(new_count, initial_count + 1)

        new_open = EmailOpen.objects.latest('pk')
        self.assertEqual(new_open.email, '*****@*****.**')
        self.assertEqual(new_open.timestamp,
                         parse_datetime('2014-04-07 17:01:12+00:00'))
        self.assertEqual(new_open.notification, 10)
        self.assertEqual(new_open.ip_address, '127.0.0.1')
        self.assertEqual(
            new_open.user_agent,
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2)'
            ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152'
            ' Safari/537.36')
        self.assertEqual(new_open.referrer_netloc, 'mail.google.com')
        self.assertEqual(new_open.referrer,
                         'https://mail.google.com/mail/u/1/')
        self.assertEqual(new_open.operating_system, 'Mac OS X 10.9.2')
        self.assertEqual(new_open.browser, 'Chrome 33.0.1750')
        self.assertEqual(new_open.device_family, 'Other')
コード例 #2
0
    def test_open(self):
        """Test a full open creation"""
        initial_count = EmailOpen.objects.count()
        utils.create_open(OPEN_DATA, self.headers)
        new_count = EmailOpen.objects.count()

        self.assertEqual(new_count, initial_count + 1)

        new_open = EmailOpen.objects.latest('pk')
        self.assertEqual(new_open.email, '*****@*****.**')
        self.assertEqual(
            new_open.timestamp,
            parse_datetime('2014-04-07 17:01:12+00:00')
        )
        self.assertEqual(new_open.notification, 10)
        self.assertEqual(new_open.ip_address, '127.0.0.1')
        self.assertEqual(
            new_open.user_agent,
            'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_2)'
            ' AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.152'
            ' Safari/537.36'
        )
        self.assertEqual(new_open.referrer_netloc, 'mail.google.com')
        self.assertEqual(
            new_open.referrer, 'https://mail.google.com/mail/u/1/')
        self.assertEqual(new_open.operating_system, 'Mac OS X 10.9.2')
        self.assertEqual(new_open.browser, 'Chrome 33.0.1750')
        self.assertEqual(new_open.device_family, 'Other')
コード例 #3
0
ファイル: test_utils.py プロジェクト: thenewguy/connect
    def test_multiple_ip_addresses(self):
        """X_FORWARDED_FOR can sometimes send multiple IPs, should use first."""
        initial_count = EmailOpen.objects.count()
        headers = self.headers.copy()
        headers['HTTP_X_FORWARDED_FOR'] = '1.1.1.1, 2.2.2.2, 3.3.3.3'
        utils.create_open(OPEN_DATA, headers)
        new_count = EmailOpen.objects.count()

        self.assertEqual(new_count, initial_count + 1)

        new_open = EmailOpen.objects.latest('pk')
        self.assertEqual(new_open.ip_address, '1.1.1.1')
コード例 #4
0
ファイル: test_utils.py プロジェクト: thenewguy/connect
    def test_open_no_notification(self):
        """Test creating an open without a notification id"""
        initial_count = EmailOpen.objects.count()
        data = OPEN_DATA.copy()
        del data['n']
        utils.create_open(data, self.headers)
        new_count = EmailOpen.objects.count()

        self.assertEqual(new_count, initial_count + 1)

        new_open = EmailOpen.objects.latest('pk')
        self.assertIsNone(new_open.notification)
コード例 #5
0
    def test_multiple_ip_addresses(self):
        """X_FORWARDED_FOR can sometimes send multiple IPs, should use first."""
        initial_count = EmailOpen.objects.count()
        headers = self.headers.copy()
        headers['HTTP_X_FORWARDED_FOR'] = '1.1.1.1, 2.2.2.2, 3.3.3.3'
        utils.create_open(OPEN_DATA, headers)
        new_count = EmailOpen.objects.count()

        self.assertEqual(new_count, initial_count + 1)

        new_open = EmailOpen.objects.latest('pk')
        self.assertEqual(new_open.ip_address, '1.1.1.1')
コード例 #6
0
    def test_open_no_notification(self):
        """Test creating an open without a notification id"""
        initial_count = EmailOpen.objects.count()
        data = OPEN_DATA.copy()
        del data['n']
        utils.create_open(data, self.headers)
        new_count = EmailOpen.objects.count()

        self.assertEqual(new_count, initial_count + 1)

        new_open = EmailOpen.objects.latest('pk')
        self.assertIsNone(new_open.notification)
コード例 #7
0
ファイル: test_utils.py プロジェクト: thenewguy/connect
    def test_open_no_referrer(self):
        """Test creating an open without a referrer"""
        initial_count = EmailOpen.objects.count()
        headers = self.headers.copy()
        del headers['HTTP_REFERER']
        utils.create_open(OPEN_DATA, headers)
        new_count = EmailOpen.objects.count()

        self.assertEqual(new_count, initial_count + 1)

        new_open = EmailOpen.objects.latest('pk')
        self.assertIsNone(new_open.referrer_netloc)
        self.assertIsNone(new_open.referrer)
コード例 #8
0
    def test_open_no_referrer(self):
        """Test creating an open without a referrer"""
        initial_count = EmailOpen.objects.count()
        headers = self.headers.copy()
        del headers['HTTP_REFERER']
        utils.create_open(OPEN_DATA, headers)
        new_count = EmailOpen.objects.count()

        self.assertEqual(new_count, initial_count + 1)

        new_open = EmailOpen.objects.latest('pk')
        self.assertIsNone(new_open.referrer_netloc)
        self.assertIsNone(new_open.referrer)
コード例 #9
0
ファイル: test_utils.py プロジェクト: thenewguy/connect
    def test_open_no_user_agent(self):
        """Test creating an open without a user agent"""
        initial_count = EmailOpen.objects.count()
        headers = self.headers.copy()
        del headers['HTTP_USER_AGENT']
        utils.create_open(OPEN_DATA, headers)
        new_count = EmailOpen.objects.count()

        self.assertEqual(new_count, initial_count + 1)

        new_open = EmailOpen.objects.latest('pk')
        self.assertIsNone(new_open.operating_system)
        self.assertIsNone(new_open.browser)
        self.assertIsNone(new_open.device_family)
コード例 #10
0
    def test_open_no_user_agent(self):
        """Test creating an open without a user agent"""
        initial_count = EmailOpen.objects.count()
        headers = self.headers.copy()
        del headers['HTTP_USER_AGENT']
        utils.create_open(OPEN_DATA, headers)
        new_count = EmailOpen.objects.count()

        self.assertEqual(new_count, initial_count + 1)

        new_open = EmailOpen.objects.latest('pk')
        self.assertIsNone(new_open.operating_system)
        self.assertIsNone(new_open.browser)
        self.assertIsNone(new_open.device_family)
コード例 #11
0
    def get(self, request, *args, **kwargs):
        """Handler for all GET requests"""
        result, verification_hash = url_representation_decode(
            self.kwargs['encoded_data'])

        # Bail if our hash of the data doesn't match the hash in the name
        if verification_hash != self.kwargs['request_hash']:
            raise Http404

        # Require an email (e), unique key (k) and timestamp (t) in the url
        necessary_keys = ['e', 'k', 't']
        if not all([key in result for key in necessary_keys]):
            raise Http404

        create_open(result, request.META)

        return HttpResponse(BASE64_TRANS_GIF.decode('base64'),
                            content_type='image/gif')
コード例 #12
0
ファイル: views.py プロジェクト: lpatmo/actionify_the_news
    def get(self, request, *args, **kwargs):
        """Handler for all GET requests"""
        result, verification_hash = url_representation_decode(
            self.kwargs['encoded_data'])

        # Bail if our hash of the data doesn't match the hash in the name
        if verification_hash != self.kwargs['request_hash']:
            raise Http404

        # Require an email (e), unique key (k) and timestamp (t) in the url
        necessary_keys = ['e', 'k', 't']
        if not all([key in result for key in necessary_keys]):
            raise Http404

        create_open(result, request.META)

        return HttpResponse(
            BASE64_TRANS_GIF.decode('base64'), content_type='image/gif'
        )