def test_incoming_url_redirect(self, task_mock): campaign = models.Campaign.objects.get(pk=1) response = self.client.get( reverse('targetshare:incoming-encoded', args=[encryptedslug.make_slug(campaign, 1)]) ) self.assertStatusCode(response, 302) self.assertTrue( models.Event.objects.filter(event_type='incoming_redirect').exists() ) self.assertEqual( response['Location'], 'http://local.edgeflip.com:8080/mocks/guncontrol_share?efcmpgslug=uV8JNec7DxI' ) self.assertEqual(encryptedslug.get_params('uV8JNec7DxI'), (1, 1, 1)) self.assertFalse(task_mock.delay.called)
def __call__(self, request, api=None, campaign_id=None, content_id=None, encrypted_slug=None, **kws): if not encrypted_slug and not (api and campaign_id and content_id): raise TypeError( "{}() requires keyword argument 'encrypted_slug' or arguments " "'api', 'campaign_id' and 'content_id'".format(self.__name__) ) try: if encrypted_slug: params = encryptedslug.get_params(encrypted_slug) else: params = encryptedslug.clean_params(api, campaign_id, content_id) except (ValueError, TypeError): LOG.exception('Failed to parse encoded endpoint params') raise http.Http404 else: (api, campaign_id, content_id) = params return self._view(request, api=api, campaign_id=campaign_id, content_id=content_id, **kws)