Example #1
0
 def test_nonlocal_redirect(self):
     t = self.new_tracker('url1')
     v = self.new_visitor('trackee1')
     i = t.add_visitor(v)
     
     url = urlex.hashedurl_redirect_http(i.uuid, domain='www.google.com')
     
     # Limitation of Django testing framework: non-local urls will not be 
     # accessed.  So, in this case, www.google.com is NOT actually accessed.  
     # Instead, a 404 error is produced.  This code tests that the url was 
     # correct, not that it was accessed.
     
     # This uses a custom view function to handle 404 errors.  So, there may 
     # be differences from what Django would return by default.
     response = self.client.get(url, follow=True)
     chain = response.redirect_chain
     
     self.assertEquals(len(chain), 1)
     self.assertEquals(chain[0], (u'http://www.google.com/', 302))
     
     # reload the instance so its fields represent its current state
     i = TrackedInstance.objects.filter(uuid=i.uuid)[0]
     
     self.assertEquals(i.first_access.date(), datetime.date.today())
     self.assertEquals(i.recent_access.date(), datetime.date.today())
     self.assertEquals(i.access_count, 1)
Example #2
0
 def test_url(self):
     templtxt = """\
         {{% load tracked_links %}}
         {{% trackedurl linkid "{0}" %}}
         """.format("linkanalytics/http/www.example.com/path/file.html")
     templtxt = textwrap.dedent(templtxt)
     t = Template(templtxt)
     uuid = '0'*32
     urlbase = 'http://example.com'
     c = Context({'linkid':uuid, 'urlbase':urlbase})
     s = t.render(c)
     url = urlex.hashedurl_redirect_http(uuid, domain='www.example.com', 
                                         filepath='path/file.html')
     self.assertEquals(s, '\n{0}{1}\n'.format(urlbase,url))