Commits

Chris Lee-Messer committed 4096273

rename do_tests to do_stuff so that nose does not pick it up
***
test production mode

  • Participants
  • Parent commits 73694d2

Comments (0)

Files changed (1)

File tests/test_project.py

 # This is still a skelton right now
-# 1. assume that all requirements are met currently
-# 2. ? manipulate PYTHONPATH?
-# 3. spawn python testdjangoproject/testdjango/manage.py runwsgiserver [options]
-# 4. run test appropriate
-# 5. repeat 3 + 4 with appropriate options
-
-
 
 # using requests with django
 # probably useful for api testing
         # print r.status_code
         self.assertTrue(r.status_code==200) # or  r.status_code == 304)
 
+
+class TestProductionMode(unittest.TestCase):
+    rooturl = r'http://localhost:8000/'
+    ajaxurl = r'http://localhost:8000/testajax/' # remember it needs to end in a slash
+    @classmethod
+    def setUpClass(clss):
+        launch_project_production_mode()
+        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
+
+    @classmethod
+    def tearDownClass(clss):
+        stop_project()
+
+    def test_django_root(self):
+        time.sleep(1)
+        self.session = requests.Session()
+        r = self.session.get(self.rooturl)
+        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
+        self.session = requests.Session()
+        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 test_get_static_from_root(self):
+        """get a static file out of the root of the static directory"""
+        r = requests.get(os.path.join(self.rooturl, 'static/teststaticfile1.txt'))
+        print r.status_code
+        self.assertTrue(r.status_code==404) 
+        
+    def test_get_static_from_app(self):
+        """get a static file out of an app static directory"""
+        r = requests.get(os.path.join(self.rooturl, r'static/dummyapp/dummyapp_in_sub.txt'))
+        print r.status_code
+        self.assertTrue(r.status_code==404) # or  r.status_code == 304)
+
+        
     
 
 def do_stuff():