Commits

Chris Lee-Messer  committed 77ac633

more work on test trying unittest framework

  • Participants
  • Parent commits 000e876

Comments (0)

Files changed (1)

File tests/test_project.py

         time.sleep(1) # it takes a little time for the server to get started
         self.session = requests.Session()
 
+        self.ajaxurl = r'http://localhost:8000/testajax/' # remember it needs to end in a slash
+
     def test_django_root(self):
         time.sleep(1)
         r = self.session.get(r'http://localhost:8000/')
+        self.csrftoken =  r.cookies['csrftoken']
+    
+
         self.assertTrue(r.status_code in (200, 304))
 
+
+    def _check_ok(self, resp):
+        self.assertTrue(resp.status_code in (200, 304))
+        return resp
+        
+    def test_http_verbs(self):
+        # first get the csrftoken
+        r = self.session.get(r'http://localhost:8000/') # a session allows for persistent cookies and things
+        csrftoken =  r.cookies['csrftoken']
+        self.csrftoken = csrftoken
+        headers= {#'content-type':'application/json',
+                'X-CSRFToken': csrftoken }
+
+        url = self.ajaxurl    
+        self._check_ok(self.session.post(url, data='', headers=headers))
+        self._check_ok(self.session.put(url, data='', headers=headers))
+        self._check_ok(self.session.delete(url, data='', headers=headers))
+        self._check_ok(self.session.head(url, data='', headers=headers))
+        self._check_ok(self.session.options(url, data='', headers=headers))
+        self._check_ok(self.session.patch(url, data='', headers=headers))
+
+
+
+
+
+        
     def tearDown(self):
         stop_project()
     
 
     
 if __name__== '__main__':
-    main()
-    # unittest.main()
+    # main()
+    unittest.main()