Example #1
0
 def test_send_single(self):
     """Sends an email to a single recipient."""
     v = Visitor(username='user', emailaddress='[email protected]')
     v.save()
     de = DraftEmail(fromemail='', subject='Subject', pixelimage=False)
     html = '<html><head></head><body></body></html>'
     de.message = html
     de.save()
     de.pending_recipients.add(v)
     de.save()
     e = de.send()
     
     self.assertTrue(de.sent)
     self.assertEquals(e.subject, 'Subject')
     self.assertEquals(e.txtmsg, '')
     self.assertEqualsHtml(e.htmlmsg, html)
     
     # There's only one Tracker object so far
     self.assertEquals(Tracker.objects.count(), 1)
     self.assertEquals(e.tracker, Tracker.objects.all()[0])
     
     self.assertEquals(len(django_email.outbox), 1)
     self.assertEquals(django_email.outbox[0].subject, 'Subject')
     self.assertEquals(django_email.outbox[0].recipients(), 
                       ['[email protected]'])
Example #2
0
 def test_unique_username(self):
     # Check that Visitors cannot have duplicate names.
     v1 = Visitor(username='visitor1')
     v1.save()
     v2 = Visitor(username='visitor1')
     # should not allow saving object with same name
     self.assertRaises(IntegrityError, v2.save)
Example #3
0
 def test_basic_editExisting(self):
     # Very basic test... just see that url exists.
     self.create_users(1)
     t = Visitor(username='visitor', emailaddress='[email protected]')
     t.save()
     with self.scoped_login('user0', 'password'):
         url = urlreverse('linkanalytics-email-editcontact', 
                          kwargs={'username':'visitor'})
         response = self.client.get(url)
         self.assertEquals(response.status_code, 200)
Example #4
0
 def test_send_blankSubject(self):
     v = Visitor(username='user', emailaddress='[email protected]')
     v.save()
     de = DraftEmail(fromemail='', pixelimage=False)
     de.message = 'My message.'
     de.save()
     de.pending_recipients.add(v)
     de.save()
     e = de.send()
     
     self.assertTrue(de.sent)
     self.assertEquals(e.subject, app_settings.EMAIL_DEFAULT_SUBJECT)
     
     self.assertEquals(len(django_email.outbox), 1)
     self.assertEquals( django_email.outbox[0].subject, 
                        app_settings.EMAIL_DEFAULT_SUBJECT )
Example #5
0
 def test_to_nonExistentUsername(self):
     # A valid but non-existent username
     self.create_users(1)
     t = Visitor(username='visitor', emailaddress='[email protected]')
     t.save()
     with self.scoped_login('user0', 'password'):
         url = urlreverse('linkanalytics-email-compose')
         data = {'do_save':'', 'to':'badtrackee', 'message':'Message.'}
         response = self.client.post(url, data)
         
         self.assertEquals(response.status_code, 200)
         
         qs = DraftEmail.objects.all()
         self.assertEquals(qs.count(), 1)
         draft = qs[0]
         self.assertEquals(draft.pending_recipients.count(), 0)
Example #6
0
 def test_send_pixelimage(self):
     """Sends an email containing a pixelimage."""
     v = Visitor(username='user', emailaddress='[email protected]')
     v.save()
     html = '<html><head></head><body></body></html>'
     de = DraftEmail(fromemail='', subject='Subject')
     de.message = html
     de.pixelimage = True
     de.save()
     de.pending_recipients.add(v)
     de.save()
     eml = de.send()
     self.assertTrue(de.sent)
     
     qs = TrackedInstance.objects.filter(visitor=v)
     self.assertEquals(qs.count(), 1)
     uuid = qs[0].uuid
     
     self.assertEquals(len(django_email.outbox), 1)
     msg = django_email.outbox[0]
     content,mime = msg.alternatives[0]
     self.assertEquals(mime, 'text/html')
     ##print '\n{0}\n'.format(content)
         
     e = xml.etree.ElementTree.fromstring(content)
     self.assertEquals(e.tag, 'html')
     
     body = e.find('body')
     self.assertNotEquals(body, None)
     
     img = body.find('img')
     self.assertNotEquals(img, None)
     
     src = img.get('src', default=None)
     self.assertNotEquals(src, None)
     
     url = urlex.hashedurl_pixelpng(uuid)
     
     self.assertEquals(src, '{0}{1}'.format(app_settings.URLBASE, url))
Example #7
0
 def test_contacts_count(self):
     self.create_users(1)
     with self.scoped_login('user0', 'password'):
         url = urlreverse('linkanalytics-email-main')
         # Case 1: no trackees
         response = self.client.get(url)
         self.assertEquals(response.context['contact_count'], 0)
         
         # Case 2: one visitor with an email
         t = Visitor(username='withemail', emailaddress='[email protected]')
         t.save()
         response = self.client.get(url)
         self.assertEquals(response.context['contact_count'], 1)
         
         # Case 3: one visitor with and one without an email
         t = Visitor(username='withoutemail')
         t.save()
         response = self.client.get(url)
         self.assertEquals(response.context['contact_count'], 1)