climate-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1563543 - in /incubator/climate/trunk/ocw-ui/backend: directory_helpers.py tests/test_directory_helpers.py
Date Sun, 02 Feb 2014 02:31:56 GMT
Author: joyce
Date: Sun Feb  2 02:31:55 2014
New Revision: 1563543

URL: http://svn.apache.org/r1563543
Log:
CLIMATE-326 - Cleanup directory_helpers test initialization

- Remove unneeded imports from directory_helpers.
- Add proper setUp(Class) and tearDown(Class) methods as necessary in
  test_directory_helpers to make everything cleaner and to ensure that
  the tests cleanup after themselves properly.
- Add results retrieval test for /results/<results> endpoint.

Modified:
    incubator/climate/trunk/ocw-ui/backend/directory_helpers.py
    incubator/climate/trunk/ocw-ui/backend/tests/test_directory_helpers.py

Modified: incubator/climate/trunk/ocw-ui/backend/directory_helpers.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/ocw-ui/backend/directory_helpers.py?rev=1563543&r1=1563542&r2=1563543&view=diff
==============================================================================
--- incubator/climate/trunk/ocw-ui/backend/directory_helpers.py (original)
+++ incubator/climate/trunk/ocw-ui/backend/directory_helpers.py Sun Feb  2 02:31:55 2014
@@ -17,11 +17,9 @@
 
 ''' Endpoints for retrieving directory information from the server. '''
 
-from bottle import Bottle, request, route
+from bottle import Bottle, request
 import os
-import json
 import re
-import sys
 
 dir_app = Bottle()
 

Modified: incubator/climate/trunk/ocw-ui/backend/tests/test_directory_helpers.py
URL: http://svn.apache.org/viewvc/incubator/climate/trunk/ocw-ui/backend/tests/test_directory_helpers.py?rev=1563543&r1=1563542&r2=1563543&view=diff
==============================================================================
--- incubator/climate/trunk/ocw-ui/backend/tests/test_directory_helpers.py (original)
+++ incubator/climate/trunk/ocw-ui/backend/tests/test_directory_helpers.py Sun Feb  2 02:31:55
2014
@@ -10,13 +10,21 @@ test_app = TestApp(app)
 class TestDirectoryPathList(unittest.TestCase):
     PATH_LEADER = '/usr/local/rcmes'
 
-    if not os.path.exists(PATH_LEADER): os.mkdir(PATH_LEADER)
-    if not os.path.exists(PATH_LEADER + '/bar'):
-        os.mkdir(PATH_LEADER + '/bar')
-    if not os.path.exists(PATH_LEADER + '/baz.txt'):
-        open(PATH_LEADER + '/baz.txt', 'a').close()
-    if not os.path.exists(PATH_LEADER + '/test.txt'):
-        open(PATH_LEADER + '/test.txt', 'a').close()
+    @classmethod
+    def setUpClass(self):
+        if not os.path.exists(self.PATH_LEADER): os.mkdir(self.PATH_LEADER)
+        if not os.path.exists(self.PATH_LEADER + '/bar'):
+            os.mkdir(self.PATH_LEADER + '/bar')
+        if not os.path.exists(self.PATH_LEADER + '/baz.txt'):
+            open(self.PATH_LEADER + '/baz.txt', 'a').close()
+        if not os.path.exists(self.PATH_LEADER + '/test.txt'):
+            open(self.PATH_LEADER + '/test.txt', 'a').close()
+
+    @classmethod
+    def tearDownClass(self):
+        os.remove(self.PATH_LEADER + '/test.txt')
+        os.remove(self.PATH_LEADER + '/baz.txt')
+        os.rmdir(self.PATH_LEADER + '/bar')
 
     def test_valid_path_listing(self):
         expected_return = {'listing': ['/bar/', '/baz.txt', '/test.txt']}
@@ -36,11 +44,18 @@ class TestDirectoryPathList(unittest.Tes
 class TestResultDirectoryList(unittest.TestCase):
     WORK_DIR = '/tmp/rcmes'
 
-    def test_result_listing(self):
+    def setUp(self):
         if not os.path.exists(self.WORK_DIR): os.mkdir(self.WORK_DIR)
         if not os.path.exists(self.WORK_DIR + '/foo'): os.mkdir(self.WORK_DIR + '/foo')
         if not os.path.exists(self.WORK_DIR + '/bar'): os.mkdir(self.WORK_DIR + '/bar')
 
+    @classmethod
+    def tearDownClass(self):
+        if not os.path.exists(self.WORK_DIR + '/foo'): os.rmdir(self.WORK_DIR + '/foo')
+        if not os.path.exists(self.WORK_DIR + '/bar'): os.rmdir(self.WORK_DIR + '/bar')
+        if not os.path.exists(self.WORK_DIR): os.rmdir(self.WORK_DIR)
+
+    def test_result_listing(self):
         expected_return = {'listing': ['/bar', '/foo']}
         response = test_app.get('http://localhost:8082/dir/results/')
         self.assertDictEqual(response.json, expected_return)
@@ -57,21 +72,36 @@ class TestResultDirectoryList(unittest.T
 class TestResultResultRetrieval(unittest.TestCase):
     WORK_DIR = '/tmp/rcmes'
 
-    def test_no_test_directory_retreival(self):
-        if os.path.exists(self.WORK_DIR + '/foo'): os.rmdir(self.WORK_DIR + '/foo')
-
-        expected_return = {'listing': []}
-        response = test_app.get('http://localhost:8082/dir/results//foo')
-        self.assertDictEqual(response.json, expected_return)
-
-    def test_results_retreival(self):
+    @classmethod
+    def setUpClass(self):
         if not os.path.exists(self.WORK_DIR): os.mkdir(self.WORK_DIR)
         if not os.path.exists(self.WORK_DIR + '/foo'): os.mkdir(self.WORK_DIR + '/foo')
 
         if not os.path.exists(self.WORK_DIR + '/foo/baz.txt'):
-            open(self.WORK_DIR + '/baz.txt', 'a').close()
+            open(self.WORK_DIR + '/foo/baz.txt', 'a').close()
         if not os.path.exists(self.WORK_DIR + '/foo/test.txt'):
-            open(self.WORK_DIR + '/test.txt', 'a').close()
+            open(self.WORK_DIR + '/foo/test.txt', 'a').close()
+
+    @classmethod
+    def tearDownClass(self):
+        if os.path.exists(self.WORK_DIR + '/foo/baz.txt'):
+            os.remove(self.WORK_DIR + '/foo/baz.txt')
+
+        if os.path.exists(self.WORK_DIR + '/foo/test.txt'):
+            os.remove(self.WORK_DIR + '/foo/test.txt')
+
+        if not os.path.exists(self.WORK_DIR + '/foo'):
+            os.rmdirs(self.WORK_DIR + '/foo')
+
+    def test_no_test_directory_retreival(self):
+        expected_return = {'listing': []}
+        response = test_app.get('http://localhost:8082/dir/results//bar')
+        self.assertDictEqual(response.json, expected_return)
+
+    def test_results_retreival(self):
+        expected_return = {'listing': ['/foo/baz.txt', '/foo/test.txt']}
+        response = test_app.get('http://localhost:8082/dir/results//foo')
+        self.assertDictEqual(response.json, expected_return)
 
 class TestDirectoryPathCleaner(unittest.TestCase):
     PATH_LEADER = '/tmp/foo'



Mime
View raw message