Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(214)

Side by Side Diff: devserver_test.py

Issue 6508001: devserver: introduce --datadir option to override where devserver puts static (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/dev-util.git@master
Patch Set: Fixed a tab Created 9 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« devserver.py ('K') | « devserver.py ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 = 'testdata/devserver/developer-test.gz' 21 TEST_IMAGE_PATH = 'testdata/devserver'
22 TEST_IMAGE_NAME = 'developer-test.gz'
23 TEST_IMAGE = TEST_IMAGE_PATH + '/' + TEST_IMAGE_NAME
22 TEST_FACTORY_CONFIG = 'testdata/devserver/miniomaha-test.conf' 24 TEST_FACTORY_CONFIG = 'testdata/devserver/miniomaha-test.conf'
25 TEST_DATA_PATH = '/tmp/devserver-test'
23 26
24 # TODO(girts): Get a copy of a recent request. For now, I copied this from 27 # TODO(girts): Get a copy of a recent request. For now, I copied this from
25 # update_test. 28 # update_test.
26 UPDATE_REQUEST = """<?xml version="1.0" encoding="UTF-8"?> 29 UPDATE_REQUEST = """<?xml version="1.0" encoding="UTF-8"?>
27 <o:gupdate 30 <o:gupdate
28 xmlns:o="http://www.google.com/update2/request" 31 xmlns:o="http://www.google.com/update2/request"
29 version="MementoSoftwareUpdate-0.1.0.0" 32 version="MementoSoftwareUpdate-0.1.0.0"
30 protocol="2.0" 33 protocol="2.0"
31 machineid="{1B0A13AC-7004-638C-3CA6-EC082E8F5DE9}" 34 machineid="{1B0A13AC-7004-638C-3CA6-EC082E8F5DE9}"
32 ismachine="0" 35 ismachine="0"
(...skipping 22 matching lines...) Expand all
55 58
56 class DevserverTest(unittest.TestCase): 59 class DevserverTest(unittest.TestCase):
57 """Regressions tests for devserver.""" 60 """Regressions tests for devserver."""
58 61
59 def setUp(self): 62 def setUp(self):
60 """Copies in testing files.""" 63 """Copies in testing files."""
61 64
62 # Copy in developer-test.gz, as "static/" directory is hardcoded, and it 65 # Copy in developer-test.gz, as "static/" directory is hardcoded, and it
63 # would be very hard to change it (static file serving is handled deep 66 # would be very hard to change it (static file serving is handled deep
64 # inside webpy). 67 # inside webpy).
65 image_src = os.path.join(base_dir, TEST_IMAGE) 68 self.image_src = os.path.join(base_dir, TEST_IMAGE)
66 self.image = os.path.join(base_dir, STATIC_DIR, 'developer-test.gz') 69 self.image = os.path.join(base_dir, STATIC_DIR, TEST_IMAGE_NAME)
67 if os.path.exists(self.image): 70 if os.path.exists(self.image):
68 os.unlink(self.image) 71 os.unlink(self.image)
69 shutil.copy(image_src, self.image) 72 shutil.copy(self.image_src, self.image)
70 73
71 self.factory_config = os.path.join(base_dir, TEST_FACTORY_CONFIG) 74 self.factory_config = os.path.join(base_dir, TEST_FACTORY_CONFIG)
72 75
73 def tearDown(self): 76 def tearDown(self):
74 """Removes testing files.""" 77 """Removes testing files."""
75 if os.path.exists(self.image): 78 if os.path.exists(self.image):
76 os.unlink(self.image) 79 os.unlink(self.image)
77 80
78 def testValidateFactoryConfig(self): 81 def testValidateFactoryConfig(self):
79 """Tests --validate_factory_config.""" 82 """Tests --validate_factory_config."""
80 cmd = [ 83 cmd = [
81 'python', 84 'python',
82 os.path.join(base_dir, 'devserver.py'), 85 os.path.join(base_dir, 'devserver.py'),
83 '--validate_factory_config', 86 '--validate_factory_config',
84 '--factory_config', self.factory_config, 87 '--factory_config', self.factory_config,
85 ] 88 ]
86 process = subprocess.Popen(cmd, stdout=subprocess.PIPE) 89 process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
87 stdout, _ = process.communicate() 90 stdout, _ = process.communicate()
88 self.assertEqual(0, process.returncode) 91 self.assertEqual(0, process.returncode)
89 self.assertTrue('Config file looks good.' in stdout) 92 self.assertTrue('Config file looks good.' in stdout)
90 93
91 def _StartServer(self): 94 def _StartServer(self,datadir=''):
davidjames 2011/02/11 23:31:53 space after comma
92 """Starts devserver, returns process.""" 95 """Starts devserver, returns process."""
93 cmd = [ 96 cmd = [
94 'python', 97 'python',
95 os.path.join(base_dir, 'devserver.py'), 98 os.path.join(base_dir, 'devserver.py'),
96 'devserver.py', 99 'devserver.py',
97 '--factory_config', self.factory_config, 100 '--factory_config', self.factory_config,
98 ] 101 ]
102 if datadir:
103 cmd.append('--datadir')
104 cmd.append(datadir)
99 process = subprocess.Popen(cmd) 105 process = subprocess.Popen(cmd)
100 return process.pid 106 return process.pid
101 107
102 def testHandleUpdate(self): 108 def testHandleUpdate(self):
103 """Tests running the server and getting an update.""" 109 """Tests running the server and getting an update."""
104 pid = self._StartServer() 110 pid = self._StartServer()
105 try: 111 try:
106 # Wait for the server to start up. 112 # Wait for the server to start up.
107 time.sleep(1) 113 time.sleep(1)
108 request = urllib2.Request(UPDATE_URL, UPDATE_REQUEST) 114 request = urllib2.Request(UPDATE_URL, UPDATE_REQUEST)
109 connection = urllib2.urlopen(request) 115 connection = urllib2.urlopen(request)
110 response = connection.read() 116 response = connection.read()
davidjames 2011/02/11 23:31:53 connection.close()
111 self.assertNotEqual('', response) 117 self.assertNotEqual('', response)
112 118
113 # Parse the response and check if it contains the right result. 119 # Parse the response and check if it contains the right result.
114 dom = minidom.parseString(response) 120 dom = minidom.parseString(response)
115 update = dom.getElementsByTagName('updatecheck')[0] 121 update = dom.getElementsByTagName('updatecheck')[0]
116 122
117 codebase = update.getAttribute('codebase') 123 codebase = update.getAttribute('codebase')
118 self.assertEqual('http://127.0.0.1:8080/static/developer-test.gz', 124 self.assertEqual('http://127.0.0.1:8080/static/' + TEST_IMAGE_NAME,
119 codebase) 125 codebase)
120 126
121 hash_value = update.getAttribute('hash') 127 hash_value = update.getAttribute('hash')
122 self.assertEqual('kGcOinJ0vA8vdYX53FN0F5BdwfY=', hash_value) 128 self.assertEqual('kGcOinJ0vA8vdYX53FN0F5BdwfY=', hash_value)
123 129
124 # Try to fetch the image. 130 # Try to fetch the image.
125 connection = urllib2.urlopen(codebase) 131 connection = urllib2.urlopen(codebase)
126 contents = connection.read() 132 contents = connection.read()
davidjames 2011/02/11 23:31:53 connection.close()
127 self.assertEqual('Developers, developers, developers!\n', contents) 133 self.assertEqual('Developers, developers, developers!\n', contents)
128 finally: 134 finally:
129 os.kill(pid, signal.SIGKILL) 135 os.kill(pid, signal.SIGKILL)
130 136
137 def testHandleDatadirUpdate(self):
138 """Tests getting an update from a specified datadir"""
139 pid = self._StartServer(datadir=TEST_DATA_PATH)
140 try:
141 # Wait for the server to start up.
142 time.sleep(1)
davidjames 2011/02/11 23:31:53 I see you copied this from above. This sleep seems
143 # If we copy the test image here, devserver has taken care of creation
144 # of the directories for us by now.
145 foreign_image = os.path.join(TEST_DATA_PATH,
146 STATIC_DIR + '/' + TEST_IMAGE_NAME)
davidjames 2011/02/11 23:31:53 continued lines have 4 space indent. Also, why not
147 if os.path.exists(foreign_image):
148 os.unlink(foreign_image)
149 shutil.copy(self.image_src, foreign_image)
150
151 request = urllib2.Request(UPDATE_URL, UPDATE_REQUEST)
152 connection = urllib2.urlopen(request)
153 response = connection.read()
davidjames 2011/02/11 23:31:53 connection.close()
154 self.assertNotEqual('', response)
155
156 # Parse the response and check if it contains the right result.
157 dom = minidom.parseString(response)
158 update = dom.getElementsByTagName('updatecheck')[0]
159
160 codebase = update.getAttribute('codebase')
161 self.assertEqual('http://127.0.0.1:8080/static/' + TEST_IMAGE_NAME,
162 codebase)
163
164 hash_value = update.getAttribute('hash')
165 self.assertEqual('kGcOinJ0vA8vdYX53FN0F5BdwfY=', hash_value)
166
167 # Try to fetch the image.
168 connection = urllib2.urlopen(codebase)
169 contents = connection.read()
davidjames 2011/02/11 23:31:53 connection.close()
170 self.assertEqual('Developers, developers, developers!\n', contents)
171 os.unlink(foreign_image)
172 finally:
173 os.kill(pid, signal.SIGKILL)
174
131 175
132 if __name__ == '__main__': 176 if __name__ == '__main__':
133 unittest.main() 177 unittest.main()
OLDNEW
« devserver.py ('K') | « devserver.py ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698