| 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 |
| 11 import shutil | 11 import shutil |
| 12 import subprocess | 12 import subprocess |
| 13 import sys | 13 import sys |
| 14 import time | 14 import time |
| 15 import unittest | 15 import unittest |
| 16 import urllib2 | 16 import urllib2 |
| 17 from xml.dom import minidom | 17 from xml.dom import minidom |
| 18 | 18 |
| 19 # Paths are relative to this script's base directory. | 19 # Paths are relative to this script's base directory. |
| 20 STATIC_DIR = 'static' | 20 STATIC_DIR = 'static' |
| 21 TEST_IMAGE_PATH = 'testdata/devserver' | 21 TEST_IMAGE_PATH = 'testdata/devserver' |
| 22 TEST_IMAGE_NAME = 'developer-test.gz' | 22 TEST_IMAGE_NAME = 'developer-test.gz' |
| 23 TEST_IMAGE = TEST_IMAGE_PATH + '/' + TEST_IMAGE_NAME | 23 TEST_IMAGE = TEST_IMAGE_PATH + '/' + TEST_IMAGE_NAME |
| 24 TEST_FACTORY_CONFIG = 'testdata/devserver/miniomaha-test.conf' | 24 TEST_FACTORY_CONFIG = 'testdata/devserver/miniomaha-test.conf' |
| 25 TEST_DATA_PATH = '/tmp/devserver-test' | 25 TEST_DATA_PATH = '/tmp/devserver-test' |
| 26 TEST_CLIENT_PREFIX = 'ChromeOSUpdateEngine' |
| 26 | 27 |
| 27 # TODO(girts): Get a copy of a recent request. For now, I copied this from | |
| 28 # update_test. | |
| 29 UPDATE_REQUEST = """<?xml version="1.0" encoding="UTF-8"?> | 28 UPDATE_REQUEST = """<?xml version="1.0" encoding="UTF-8"?> |
| 30 <o:gupdate | 29 <o:gupdate xmlns:o="http://www.google.com/update2/request" version="ChromeOSUpda
teEngine-0.1.0.0" updaterversion="ChromeOSUpdateEngine-0.1.0.0" protocol="2.0" i
smachine="1"> |
| 31 xmlns:o="http://www.google.com/update2/request" | 30 <o:os version="Indy" platform="Chrome OS" sp="0.11.254.2011_03_09_1814_i686"
></o:os> |
| 32 version="MementoSoftwareUpdate-0.1.0.0" | 31 <o:app appid="{DEV-BUILD}" version="0.11.254.2011_03_09_1814" lang="en-US" t
rack="developer-build" board="x86-generic" hardware_class="BETA DVT" delta_okay=
"true"> |
| 33 protocol="2.0" | 32 <o:updatecheck></o:updatecheck> |
| 34 machineid="{1B0A13AC-7004-638C-3CA6-EC082E8F5DE9}" | 33 <o:event eventtype="3" eventresult="2" previousversion="0.11.216.2011_03
_02_1358"></o:event> |
| 35 ismachine="0" | 34 </o:app> |
| 36 userid="{bogus}"> | |
| 37 <o:os version="Memento" | |
| 38 platform="memento" | |
| 39 sp="ForcedUpdate_i686"> | |
| 40 </o:os> | |
| 41 <o:app appid="{87efface-864d-49a5-9bb3-4b050a7c227a}" | |
| 42 version="ForcedUpdate" | |
| 43 lang="en-us" | |
| 44 brand="GGLG" | |
| 45 track="developer-build" | |
| 46 board="x86-generic"> | |
| 47 <o:ping active="0"></o:ping> | |
| 48 <o:updatecheck></o:updatecheck> | |
| 49 </o:app> | |
| 50 </o:gupdate> | 35 </o:gupdate> |
| 51 """ | 36 """ |
| 52 # TODO(girts): use a random available port. | 37 # TODO(girts): use a random available port. |
| 53 UPDATE_URL = 'http://127.0.0.1:8080/update' | 38 UPDATE_URL = 'http://127.0.0.1:8080/update' |
| 54 | 39 |
| 55 # Run all tests while being in / | 40 # Run all tests while being in / |
| 56 base_dir = os.path.dirname(os.path.abspath(sys.argv[0])) | 41 base_dir = os.path.dirname(os.path.abspath(sys.argv[0])) |
| 57 os.chdir("/") | 42 os.chdir("/") |
| 58 | 43 |
| 59 class DevserverTest(unittest.TestCase): | 44 class DevserverTest(unittest.TestCase): |
| (...skipping 17 matching lines...) Expand all Loading... |
| 77 """Removes testing files.""" | 62 """Removes testing files.""" |
| 78 if os.path.exists(self.image): | 63 if os.path.exists(self.image): |
| 79 os.unlink(self.image) | 64 os.unlink(self.image) |
| 80 | 65 |
| 81 def testValidateFactoryConfig(self): | 66 def testValidateFactoryConfig(self): |
| 82 """Tests --validate_factory_config.""" | 67 """Tests --validate_factory_config.""" |
| 83 cmd = [ | 68 cmd = [ |
| 84 'python', | 69 'python', |
| 85 os.path.join(base_dir, 'devserver.py'), | 70 os.path.join(base_dir, 'devserver.py'), |
| 86 '--validate_factory_config', | 71 '--validate_factory_config', |
| 72 '--client_prefix', TEST_CLIENT_PREFIX, |
| 87 '--factory_config', self.factory_config, | 73 '--factory_config', self.factory_config, |
| 88 ] | 74 ] |
| 89 process = subprocess.Popen(cmd, stdout=subprocess.PIPE) | 75 process = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
| 90 stdout, _ = process.communicate() | 76 stdout, _ = process.communicate() |
| 91 self.assertEqual(0, process.returncode) | 77 self.assertEqual(0, process.returncode) |
| 92 self.assertTrue('Config file looks good.' in stdout) | 78 self.assertTrue('Config file looks good.' in stdout) |
| 93 | 79 |
| 94 def _StartServer(self, data_dir=''): | 80 def _StartServer(self, data_dir=''): |
| 95 """Starts devserver, returns process.""" | 81 """Starts devserver, returns process.""" |
| 96 cmd = [ | 82 cmd = [ |
| 97 'python', | 83 'python', |
| 98 os.path.join(base_dir, 'devserver.py'), | 84 os.path.join(base_dir, 'devserver.py'), |
| 99 'devserver.py', | 85 'devserver.py', |
| 86 '--client_prefix', TEST_CLIENT_PREFIX, |
| 100 '--factory_config', self.factory_config, | 87 '--factory_config', self.factory_config, |
| 101 ] | 88 ] |
| 102 if data_dir: | 89 if data_dir: |
| 103 cmd.append('--data_dir') | 90 cmd.append('--data_dir') |
| 104 cmd.append(data_dir) | 91 cmd.append(data_dir) |
| 105 process = subprocess.Popen(cmd) | 92 process = subprocess.Popen(cmd) |
| 106 return process.pid | 93 return process.pid |
| 107 | 94 |
| 108 def testHandleUpdate(self): | 95 def testHandleUpdate(self): |
| 109 """Tests running the server and getting an update.""" | 96 """Tests running the server and getting an update.""" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 175 contents = connection.read() | 162 contents = connection.read() |
| 176 connection.close() | 163 connection.close() |
| 177 self.assertEqual('Developers, developers, developers!\n', contents) | 164 self.assertEqual('Developers, developers, developers!\n', contents) |
| 178 os.unlink(foreign_image) | 165 os.unlink(foreign_image) |
| 179 finally: | 166 finally: |
| 180 os.kill(pid, signal.SIGKILL) | 167 os.kill(pid, signal.SIGKILL) |
| 181 | 168 |
| 182 | 169 |
| 183 if __name__ == '__main__': | 170 if __name__ == '__main__': |
| 184 unittest.main() | 171 unittest.main() |
| OLD | NEW |