Commits

cleemesser committed 4f0de12

add static file tests for developer mode

Comments (0)

Files changed (3)

tests/test_project.py

 PIDFILE = os.path.join(os.getcwd(),'test_project.pid')
 
 def launch_project_developer_mode():
-    """start django wsgiserver as daemon in developer mode"""
-    print "hello from launch project developer mode"
+    """start django wsgiserver as daemon in developer mode
+    except can't do autoreload as daemon"""
+    #print "hello from launch project developer mode"
     #sout = StringIO.StringIO()
     #serr = StringIO.StringIO()
     try:
         subprocess.check_call(["python", r"testdjangoproject/testdjango/manage.py",
             "runwsgiserver",
             "threads=10", "daemonize",
+            "autoreload=0",
             "pidfile=%s" % PIDFILE])
 
     except subprocess.CalledProcessError, msg:
         print msg
 
 def launch_project_production_mode():
-    """start django wsgiserver as daemon"""
+    """start django wsgiserver as daemon
+    do it in production mode: do not serve static files or autoreload
+    create thread file"""
     print "hello from launch project production mode"
     subprocess.check_call(["python", r"testdjangoproject/testdjango/manage.py",
                      "runwsgiserver",
     
 
 def stop_project():
-    print "olleh from stop project"
+    #print "olleh from stop project"
     subprocess.call(["python", r"testdjangoproject/testdjango/manage.py", "runwsgiserver",
                      "stop", "pidfile=%s" % PIDFILE])
 
     
 
 class TestDeveloperMode(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):
         #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(r'http://localhost:8000/')
+        r = self.session.get(self.rooturl)
         self.csrftoken =  r.cookies['csrftoken']
     
 
         self._check_ok(self.session.options(url, data='', headers=headers))
         self._check_ok(self.session.patch(url, data='', headers=headers))
 
-    def test_autoreload(self):
-        if not hasattr(self, 'session'):
-            self.session = requests.Session()
-        r=self.session.get(r'http://localhost:8000/testautoreload')
-        self.assertTrue(r.status_code == 200)
-        print r.text
-        fp=open('testdjangoproject/testdjango/testdjango/autoload_test.py', 'w+')
-        fp.write('x=%d\n' % random.randint(0,100))
-        fp.close()
-        time.sleep(2) # allow time for reload
-        r=self.session.get(r'http://localhost:8000/testautoreload')
-        print r.status_code
-        self.assertTrue(r.status_code == 200)
-        print r.text
 
+    # I have not found a good way to test autoreloading    
+    # def test_autoreload(self):
+    #     if not hasattr(self, 'session'):
+    #         self.session = requests.Session()
+    #     r=self.session.get(r'http://localhost:8000/testautoreload')
+    #     self.assertTrue(r.status_code == 200)
+    #     print r.text
+    #     fp=open('testdjangoproject/testdjango/testdjango/autoload_test.py', 'w+')
+    #     fp.write('x=%d\n' % random.randint(0,100))
+    #     fp.close()
+    #     time.sleep(2) # allow time for reload
+    #     r=self.session.get(r'http://localhost:8000/testautoreload')
+    #     print r.status_code
+    #     self.assertTrue(r.status_code == 200)
+    #     print r.text
 
+    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==200) # or  r.status_code == 304)
         
+    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==200) # or  r.status_code == 304)
 
     
     

tests/testdjangoproject/testdjango/static/teststaticfile1.txt

 teststaticfile1.txt
+this is in the root of the static/ file directory and is independent of the app directory version

tests/testdjangoproject/testdjango/testdjango/settings/local.py

 INSTALLED_APPS += (
 #    'debug_toolbar',
     'django_wsgiserver',
+    'dummyapp',
 )
 
 # See: https://github.com/django-debug-toolbar/django-debug-toolbar#installation
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.