Test that the email notification actually generates some emails.
authorDiane Trout <diane@caltech.edu>
Tue, 6 Oct 2009 18:42:11 +0000 (18:42 +0000)
committerDiane Trout <diane@caltech.edu>
Tue, 6 Oct 2009 18:42:11 +0000 (18:42 +0000)
I discovered that django when run in a test environment will store
email messages sent in django.core.mail.outbox, so I could make sure
that when the "run started" send email is clicked, it actually creates
some messages. (Though my current test, is just that the body is non-zero).

htsworkflow/frontend/experiments/fixtures/test_flowcells.json
htsworkflow/frontend/experiments/tests.py

index 1ce52506e76cbee03c3fb7a38ccfdd8c2ff5df0b..b744e2bed8146898e1affd0c7fe898d2b7cd81bc 100644 (file)
@@ -1,5 +1,45 @@
 [
-  {"pk": 5, "model": "auth.user", 
+    {"pk": 1, "model": "samples.affiliation",
+     "fields": {
+         "users": [],
+         "contact": "group 1",
+         "name": "affiliation 1",
+         "email": "pk1@example.com"
+         }
+     },
+    {"pk": 2, "model": "samples.affiliation",
+     "fields": {
+         "users": [],
+         "contact": "group 2",
+         "name": "affiliation 2",
+         "email": "pk2@example.com"
+         }
+     },
+    {"pk": 3, "model": "samples.affiliation",
+     "fields": {
+         "users": [],
+         "contact": "group 3",
+         "name": "affiliation 3",
+         "email": "pk3@example.com"
+         }
+     },
+    {"pk": 4, "model": "samples.affiliation",
+     "fields": {
+         "users": [],
+         "contact": "group 4",
+         "name": "affiliation 4",
+         "email": "pk1@example.com"
+         }
+     },
+    {"pk": 5, "model": "samples.affiliation",
+     "fields": {
+         "users": [],
+         "contact": "group 5",
+         "name": "affiliation 5",
+         "email": "pk5@example.com"
+         }
+     },
+    {"pk": 5, "model": "auth.user", 
    "fields": {
        "username": "test",
        "first_name": "",
        "date_joined": "2009-01-01 00:01:01"
        }
    },
+  {"pk": 6, "model": "auth.user", 
+   "fields": {
+       "username": "admintest",
+       "first_name": "",
+       "last_name": "",
+       "is_active": true,
+       "is_superuser": false,
+       "is_staff": true,
+       "last_login": "2009-01-01 00:00:01",
+       "groups": [],
+       "user_permissions": [],
+       "password": "sha1$foo$5e4eefec1144a04becfb7da79244f07c487fc345",
+       "email": "",
+       "date_joined": "2009-01-01 00:01:01"
+       }
+   },
  {"pk": 1, "model": "experiments.clusterstation", "fields": {"name": "old"}}, 
  {"pk": 2, "model": "experiments.clusterstation", "fields": {"name": "loaner"}}, 
  {"pk": 3, "model": "experiments.clusterstation", "fields": {"name": "new"}}, 
             "library_type": null, 
             "made_by": "Igor", 
             "affiliations": [
-                40
+                1,2
             ], 
             "replicate": 1, 
             "condition": 1, 
             "library_type": 2, 
             "made_by": "Lorian", 
             "affiliations": [
-                41
+                2
             ], 
             "replicate": 1, 
             "condition": 1, 
             "library_type": 2, 
             "made_by": "Brian Williams", 
             "affiliations": [
-                4, 
-                8, 
-                12
+                3,4
             ], 
             "replicate": 1, 
             "condition": 1, 
             "library_type": 2, 
             "made_by": "Brian Williams", 
             "affiliations": [
-                37, 
-                8
+                5
             ], 
             "replicate": 1, 
             "condition": 1, 
             "library_type": 2, 
             "made_by": "Brian Williams", 
             "affiliations": [
-                37, 
-                8
+                2,4
             ], 
             "replicate": 1, 
             "condition": 1, 
             "library_type": 2, 
             "made_by": "Brian Williams", 
             "affiliations": [
-                37, 
-                8
+                4,5
             ], 
             "replicate": 1, 
             "condition": 1, 
             "library_type": 2, 
             "made_by": "Brian Williams", 
             "affiliations": [
-                37, 
-                8
+                1,3
             ], 
             "replicate": 1, 
             "condition": 1, 
             "library_type": 2, 
             "made_by": "Brian Williams", 
             "affiliations": [
-                37, 
-                8
+                3,5
             ], 
             "replicate": 1, 
             "condition": 1, 
             "library_type": 2, 
             "made_by": "Brian Williams", 
             "affiliations": [
-                14
+                3
             ], 
             "replicate": 1, 
             "condition": 1, 
             "library_type": 2, 
             "made_by": "Brian Williams", 
             "affiliations": [
-                26
+                4
             ], 
             "replicate": 1, 
             "condition": 1, 
             "library_type": 1, 
             "made_by": "Lorian", 
             "affiliations": [
-                18
+                5
             ], 
             "replicate": 1, 
             "condition": null, 
             "library_type": 1, 
             "made_by": "Lorian", 
             "affiliations": [
-                18
+                6
             ], 
             "replicate": 1, 
             "condition": null, 
             "library_type": 1, 
             "made_by": "Lorian", 
             "affiliations": [
-                26
+                1
             ], 
             "replicate": 1, 
             "condition": null, 
             "library_type": 1, 
             "made_by": "Lorian", 
             "affiliations": [
-                26
+                2
             ], 
             "replicate": 1, 
             "condition": null, 
             "library_type": 1, 
             "made_by": "Lorian", 
             "affiliations": [
-                26
+                3
             ], 
             "replicate": 1, 
             "condition": null, 
             "library_type": 2, 
             "made_by": "Brian Williams", 
             "affiliations": [
-                26
+                4
             ], 
             "replicate": 1, 
             "condition": 1, 
             "library_type": 2, 
             "made_by": "Brian Williams", 
             "affiliations": [
-                26
+                5
             ], 
             "replicate": 1, 
             "condition": 1, 
             "library_type": 2, 
             "made_by": "Brian Williams", 
             "affiliations": [
-                14
+                1
             ], 
             "replicate": 1, 
             "condition": 1, 
             "library_type": 1, 
             "made_by": "Lorian", 
             "affiliations": [
-                21
+                2
             ], 
             "replicate": 1, 
             "condition": null, 
             "library_type": 1, 
             "made_by": "Lorian", 
             "affiliations": [
-                21
+                3
             ], 
             "replicate": 1, 
             "condition": null, 
             "library_type": 1, 
             "made_by": "Lorian", 
             "affiliations": [
-                18
+                4
             ], 
             "replicate": 1, 
             "condition": null, 
             "library_type": 1, 
             "made_by": "Lorian", 
             "affiliations": [
-                26
+                5
             ], 
             "replicate": 1, 
             "condition": null, 
             "library_type": 2, 
             "made_by": "Igor", 
             "affiliations": [
-                40
+                1
             ], 
             "replicate": 1, 
             "condition": 1, 
             "library_type": 2, 
             "made_by": "Yuling Jiao", 
             "affiliations": [
-                29
+                2
             ], 
             "replicate": 1, 
             "condition": null, 
             "library_type": 2, 
             "made_by": "Yuling Jiao", 
             "affiliations": [
-                29
+                3
             ], 
             "replicate": 1, 
             "condition": null, 
             "antibody": null
         }
      }
+
 ]
index a4a53155f7fa3ca88f11a4b44da48ee74305dcb8..6081c44a56cab657fa6271969282b6938a67b75a 100644 (file)
@@ -2,7 +2,9 @@ try:
     import json
 except ImportError, e:
     import simplejson as json
-    
+import sys
+
+from django.core import mail
 from django.test import TestCase
 from htsworkflow.frontend.experiments import models
 from htsworkflow.frontend.experiments import experiments
@@ -92,5 +94,34 @@ class ExperimentsTestCases(TestCase):
 
         self.failUnlessEqual(library_sl039['library_id'], 'SL039')
 
-#class RetriveConfigTestCases(TestCase):
-#    fixtures = ['test_flowcells.json']
+class TestEmailNotify(TestCase):
+    fixtures = ['test_flowcells.json']
+
+    def test_started_email_not_logged_in(self):
+        response = self.client.get('/experiments/started/153/')
+        self.failUnlessEqual(response.status_code, 302)
+
+    def test_started_email_logged_in_user(self):
+        self.client.login(username='test', password='BJOKL5kAj6aFZ6A5')
+        response = self.client.get('/experiments/started/153/')
+        self.failUnlessEqual(response.status_code, 302)
+        
+    def test_started_email_logged_in_staff(self):
+        self.client.login(username='admintest', password='BJOKL5kAj6aFZ6A5') 
+        response = self.client.get('/experiments/started/153/')
+        self.failUnlessEqual(response.status_code, 200)
+
+    def test_started_email_send(self):
+        self.client.login(username='admintest', password='BJOKL5kAj6aFZ6A5') 
+        response = self.client.get('/experiments/started/153/')
+        self.failUnlessEqual(response.status_code, 200)
+        
+        self.failUnless('pk1@example.com' in response.content)
+        self.failUnless('Lane #8 : (11064) Paired ends 104' in response.content)
+
+        response = self.client.get('/experiments/started/153/', {'send':'1','bcc':'on'})
+        self.failUnlessEqual(response.status_code, 200)
+        self.failUnlessEqual(len(mail.outbox), 4)
+        print >>sys.stderr, "outbox:", mail.outbox
+        for m in mail.outbox:
+            self.failUnless(len(m.body) > 0)