Esempio n. 1
0
    def test_build(self):
        attachment_name = 'build.json'
        attachment_path = os.path.join(settings.MEDIA_ROOT, 'test_attachment')
        copyfile(os.path.join(FILES_PATH, 'archive.zip'), attachment_path)
        attachment = Attachment(name=attachment_name, buildable=True)
        attachment.file = os.path.join('..', attachment_path)
        attachment.save()

        kwargs = {
            'key': TRACKER_ATTACHMENT_EXECUTED,
            'campaign_id': 1,
            'target_id': 1,
            'value': 'tracker: not opened',
        }
        tracker = Tracker.objects.create(**kwargs)

        res = attachment.build(tracker)
        received = json.loads(res.read().decode())

        tracker_url = 'http://localhost/en/tracker/%s.png' % tracker.pk
        self.assertEqual(received['tracker_url'], tracker_url)
        self.assertEqual(received['target_email'], '*****@*****.**')
        self.assertEqual(received['target_first_name'], 'John')
        self.assertEqual(received['target_last_name'], 'Doe')

        # Clean media dir after test
        os.remove(attachment_path)
Esempio n. 2
0
    def test_build_invalid_zip(self):
        attachment_name = 'build.json'
        attachment_path = os.path.join(settings.MEDIA_ROOT, 'test_attachment')
        copyfile(os.path.join(FILES_PATH, 'invalid_archive.zip'),
                 attachment_path)
        attachment = Attachment(name=attachment_name, buildable=True)
        attachment.file = os.path.join('..', attachment_path)
        attachment.save()

        kwargs = {
            'key': TRACKER_ATTACHMENT_EXECUTED,
            'campaign_id': 1,
            'target_id': 1,
            'value': 'tracker: not opened',
        }
        tracker = Tracker.objects.create(**kwargs)
        with self.assertRaises(SuspiciousOperation):
            attachment.build(tracker)
Esempio n. 3
0
    def test_build_static(self):
        attachment_name = 'b64.png'
        attachment_path = os.path.join(settings.MEDIA_ROOT, 'test_attachment')
        copyfile(os.path.join(FILES_PATH, 'image.png'), attachment_path)
        attachment = Attachment(name=attachment_name, buildable=False)
        attachment.file = os.path.join('..', attachment_path)
        attachment.save()

        kwargs = {
            'key': TRACKER_ATTACHMENT_EXECUTED,
            'campaign_id': 1,
            'target_id': 1,
            'value': 'tracker: not opened',
        }
        tracker = Tracker.objects.create(**kwargs)

        res = attachment.build(tracker)
        self.assertEqual(res, attachment.file)

        # Clean media dir after test
        os.remove(attachment_path)