| OLD | NEW |
| 1 #!/usr/bin/python | 1 #!/usr/bin/python |
| 2 | 2 |
| 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 3 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be | 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. | 5 # found in the LICENSE file. |
| 6 | 6 |
| 7 """Regression tests for devserver.""" | 7 """Regression tests for devserver.""" |
| 8 | 8 |
| 9 import os | 9 import os |
| 10 import signal | 10 import signal |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 track="developer-build" | 42 track="developer-build" |
| 43 board="x86-generic"> | 43 board="x86-generic"> |
| 44 <o:ping active="0"></o:ping> | 44 <o:ping active="0"></o:ping> |
| 45 <o:updatecheck></o:updatecheck> | 45 <o:updatecheck></o:updatecheck> |
| 46 </o:app> | 46 </o:app> |
| 47 </o:gupdate> | 47 </o:gupdate> |
| 48 """ | 48 """ |
| 49 # TODO(girts): use a random available port. | 49 # TODO(girts): use a random available port. |
| 50 UPDATE_URL = 'http://127.0.0.1:8080/update' | 50 UPDATE_URL = 'http://127.0.0.1:8080/update' |
| 51 | 51 |
| 52 # Run all tests while being in / |
| 53 base_dir = os.path.dirname(os.path.abspath(sys.argv[0])) |
| 54 os.chdir("/") |
| 52 | 55 |
| 53 class DevserverTest(unittest.TestCase): | 56 class DevserverTest(unittest.TestCase): |
| 54 """Regressions tests for devserver.""" | 57 """Regressions tests for devserver.""" |
| 55 | 58 |
| 56 def setUp(self): | 59 def setUp(self): |
| 57 """Copies in testing files.""" | 60 """Copies in testing files.""" |
| 58 base_dir = os.path.dirname(os.path.abspath(sys.argv[0])) | |
| 59 | 61 |
| 60 # Copy in developer-test.gz, as "static/" directory is hardcoded, and it | 62 # Copy in developer-test.gz, as "static/" directory is hardcoded, and it |
| 61 # would be very hard to change it (static file serving is handled deep | 63 # would be very hard to change it (static file serving is handled deep |
| 62 # inside webpy). | 64 # inside webpy). |
| 63 image_src = os.path.join(base_dir, TEST_IMAGE) | 65 image_src = os.path.join(base_dir, TEST_IMAGE) |
| 64 self.image = os.path.join(base_dir, STATIC_DIR, 'developer-test.gz') | 66 self.image = os.path.join(base_dir, STATIC_DIR, 'developer-test.gz') |
| 65 if os.path.exists(self.image): | 67 if os.path.exists(self.image): |
| 66 os.unlink(self.image) | 68 os.unlink(self.image) |
| 67 shutil.copy(image_src, self.image) | 69 shutil.copy(image_src, self.image) |
| 68 | 70 |
| 69 self.factory_config = os.path.join(base_dir, TEST_FACTORY_CONFIG) | 71 self.factory_config = os.path.join(base_dir, TEST_FACTORY_CONFIG) |
| 70 | 72 |
| 71 def tearDown(self): | 73 def tearDown(self): |
| 72 """Removes testing files.""" | 74 """Removes testing files.""" |
| 73 if os.path.exists(self.image): | 75 if os.path.exists(self.image): |
| 74 os.unlink(self.image) | 76 os.unlink(self.image) |
| 75 | 77 |
| 76 def testValidateFactoryConfig(self): | 78 def testValidateFactoryConfig(self): |
| 77 """Tests --validate_factory_config.""" | 79 """Tests --validate_factory_config.""" |
| 78 cmd = [ | 80 cmd = [ |
| 79 'python', | 81 'python', |
| 80 'devserver.py', | 82 os.path.join(base_dir, 'devserver.py'), |
| 81 '--validate_factory_config', | 83 '--validate_factory_config', |
| 82 '--factory_config', self.factory_config, | 84 '--factory_config', self.factory_config, |
| 83 ] | 85 ] |
| 84 process = subprocess.Popen(cmd, stdout=subprocess.PIPE) | 86 process = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
| 85 stdout, _ = process.communicate() | 87 stdout, _ = process.communicate() |
| 86 self.assertEqual(0, process.returncode) | 88 self.assertEqual(0, process.returncode) |
| 87 self.assertTrue('Config file looks good.' in stdout) | 89 self.assertTrue('Config file looks good.' in stdout) |
| 88 | 90 |
| 89 def _StartServer(self): | 91 def _StartServer(self): |
| 90 """Starts devserver, returns process.""" | 92 """Starts devserver, returns process.""" |
| 91 cmd = [ | 93 cmd = [ |
| 92 'python', | 94 'python', |
| 95 os.path.join(base_dir, 'devserver.py'), |
| 93 'devserver.py', | 96 'devserver.py', |
| 94 '--factory_config', self.factory_config, | 97 '--factory_config', self.factory_config, |
| 95 ] | 98 ] |
| 96 process = subprocess.Popen(cmd) | 99 process = subprocess.Popen(cmd) |
| 97 return process.pid | 100 return process.pid |
| 98 | 101 |
| 99 def testHandleUpdate(self): | 102 def testHandleUpdate(self): |
| 100 """Tests running the server and getting an update.""" | 103 """Tests running the server and getting an update.""" |
| 101 pid = self._StartServer() | 104 pid = self._StartServer() |
| 102 try: | 105 try: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 121 # Try to fetch the image. | 124 # Try to fetch the image. |
| 122 connection = urllib2.urlopen(codebase) | 125 connection = urllib2.urlopen(codebase) |
| 123 contents = connection.read() | 126 contents = connection.read() |
| 124 self.assertEqual('Developers, developers, developers!\n', contents) | 127 self.assertEqual('Developers, developers, developers!\n', contents) |
| 125 finally: | 128 finally: |
| 126 os.kill(pid, signal.SIGKILL) | 129 os.kill(pid, signal.SIGKILL) |
| 127 | 130 |
| 128 | 131 |
| 129 if __name__ == '__main__': | 132 if __name__ == '__main__': |
| 130 unittest.main() | 133 unittest.main() |
| OLD | NEW |