Chromium Code Reviews| Index: devserver_test.py |
| diff --git a/devserver_test.py b/devserver_test.py |
| index 69c754fcd6ed34417ee141fe3373cee9c6922d10..043e7000bd2335cf02b245b70b542e95c143329f 100755 |
| --- a/devserver_test.py |
| +++ b/devserver_test.py |
| @@ -18,8 +18,11 @@ from xml.dom import minidom |
| # Paths are relative to this script's base directory. |
| STATIC_DIR = 'static' |
| -TEST_IMAGE = 'testdata/devserver/developer-test.gz' |
| +TEST_IMAGE_PATH = 'testdata/devserver' |
| +TEST_IMAGE_NAME = 'developer-test.gz' |
| +TEST_IMAGE = TEST_IMAGE_PATH + '/' + TEST_IMAGE_NAME |
| TEST_FACTORY_CONFIG = 'testdata/devserver/miniomaha-test.conf' |
| +TEST_DATA_PATH = '/tmp/devserver-test' |
| # TODO(girts): Get a copy of a recent request. For now, I copied this from |
| # update_test. |
| @@ -62,11 +65,11 @@ class DevserverTest(unittest.TestCase): |
| # Copy in developer-test.gz, as "static/" directory is hardcoded, and it |
| # would be very hard to change it (static file serving is handled deep |
| # inside webpy). |
| - image_src = os.path.join(base_dir, TEST_IMAGE) |
| - self.image = os.path.join(base_dir, STATIC_DIR, 'developer-test.gz') |
| + self.image_src = os.path.join(base_dir, TEST_IMAGE) |
| + self.image = os.path.join(base_dir, STATIC_DIR, TEST_IMAGE_NAME) |
| if os.path.exists(self.image): |
| os.unlink(self.image) |
| - shutil.copy(image_src, self.image) |
| + shutil.copy(self.image_src, self.image) |
| self.factory_config = os.path.join(base_dir, TEST_FACTORY_CONFIG) |
| @@ -88,7 +91,7 @@ class DevserverTest(unittest.TestCase): |
| self.assertEqual(0, process.returncode) |
| self.assertTrue('Config file looks good.' in stdout) |
| - def _StartServer(self): |
| + def _StartServer(self,datadir=''): |
|
davidjames
2011/02/11 23:31:53
space after comma
|
| """Starts devserver, returns process.""" |
| cmd = [ |
| 'python', |
| @@ -96,6 +99,9 @@ class DevserverTest(unittest.TestCase): |
| 'devserver.py', |
| '--factory_config', self.factory_config, |
| ] |
| + if datadir: |
| + cmd.append('--datadir') |
| + cmd.append(datadir) |
| process = subprocess.Popen(cmd) |
| return process.pid |
| @@ -115,7 +121,7 @@ class DevserverTest(unittest.TestCase): |
| update = dom.getElementsByTagName('updatecheck')[0] |
| codebase = update.getAttribute('codebase') |
| - self.assertEqual('http://127.0.0.1:8080/static/developer-test.gz', |
| + self.assertEqual('http://127.0.0.1:8080/static/' + TEST_IMAGE_NAME, |
| codebase) |
| hash_value = update.getAttribute('hash') |
| @@ -128,6 +134,44 @@ class DevserverTest(unittest.TestCase): |
| finally: |
| os.kill(pid, signal.SIGKILL) |
| + def testHandleDatadirUpdate(self): |
| + """Tests getting an update from a specified datadir""" |
| + pid = self._StartServer(datadir=TEST_DATA_PATH) |
| + try: |
| + # Wait for the server to start up. |
| + time.sleep(1) |
|
davidjames
2011/02/11 23:31:53
I see you copied this from above. This sleep seems
|
| + # If we copy the test image here, devserver has taken care of creation |
| + # of the directories for us by now. |
| + foreign_image = os.path.join(TEST_DATA_PATH, |
| + STATIC_DIR + '/' + TEST_IMAGE_NAME) |
|
davidjames
2011/02/11 23:31:53
continued lines have 4 space indent. Also, why not
|
| + if os.path.exists(foreign_image): |
| + os.unlink(foreign_image) |
| + shutil.copy(self.image_src, foreign_image) |
| + |
| + request = urllib2.Request(UPDATE_URL, UPDATE_REQUEST) |
| + connection = urllib2.urlopen(request) |
| + response = connection.read() |
|
davidjames
2011/02/11 23:31:53
connection.close()
|
| + self.assertNotEqual('', response) |
| + |
| + # Parse the response and check if it contains the right result. |
| + dom = minidom.parseString(response) |
| + update = dom.getElementsByTagName('updatecheck')[0] |
| + |
| + codebase = update.getAttribute('codebase') |
| + self.assertEqual('http://127.0.0.1:8080/static/' + TEST_IMAGE_NAME, |
| + codebase) |
| + |
| + hash_value = update.getAttribute('hash') |
| + self.assertEqual('kGcOinJ0vA8vdYX53FN0F5BdwfY=', hash_value) |
| + |
| + # Try to fetch the image. |
| + connection = urllib2.urlopen(codebase) |
| + contents = connection.read() |
|
davidjames
2011/02/11 23:31:53
connection.close()
|
| + self.assertEqual('Developers, developers, developers!\n', contents) |
| + os.unlink(foreign_image) |
| + finally: |
| + os.kill(pid, signal.SIGKILL) |
| + |
| if __name__ == '__main__': |
| unittest.main() |