cleemesser avatar cleemesser committed 77ac633

more work on test trying unittest framework

Comments (0)

Files changed (1)

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()
 
 
 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.