Merge lp:~mandel/ubuntuone-dev-tools/mocked-webserver into lp:ubuntuone-dev-tools
| Status: | Merged | ||||
|---|---|---|---|---|---|
| Approved by: | Manuel de la Peña on 2012-04-17 | ||||
| Approved revision: | 99 | ||||
| Merged at revision: | 62 | ||||
| Proposed branch: | lp:~mandel/ubuntuone-dev-tools/mocked-webserver | ||||
| Merge into: | lp:ubuntuone-dev-tools | ||||
| Prerequisite: | lp:~mandel/ubuntuone-dev-tools/tcp-testcases | ||||
| Diff against target: |
349 lines (+322/-1) 4 files modified
ubuntuone/devtools/testcases/txtcpserver.py (+0/-1) ubuntuone/devtools/testing/tests/__init__.py (+29/-0) ubuntuone/devtools/testing/tests/test_txwebserver.py (+172/-0) ubuntuone/devtools/testing/txwebserver.py (+121/-0) |
||||
| To merge this branch: | bzr merge lp:~mandel/ubuntuone-dev-tools/mocked-webserver | ||||
| Related bugs: |
|
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| dobey (community) | 2012-04-09 | Approve on 2012-04-17 | |
| Alejandro J. Cura (community) | Approve on 2012-04-16 | ||
|
Review via email:
|
|||
Commit Message
- Added a mock Web server which ensures its resources are correctly finalized, for use in tests (LP: #972366).
Description of the Change
- Added a mock Webserver than can be used in tests and that ensures that its resources are correctly closed (LP: #972366).
| Alejandro J. Cura (alecu) wrote : | # |
Nice branch. This is a very good second step in order to reduce the amount of boilerplate we have everywhere in our tests.
The only bit I don't like is the many "if self.ssl_settings" scattered around.
What about splitting the WebServer class into HTTPS and HTTP classes?
| Manuel de la Peña (mandel) wrote : | # |
> 107 + def test_get_iri(self):
> 108 + """Test getting the iri from the server."""
> 109 + expected = u"http://
> 110 + self.assert_
> 111 +
> 112 + def test_get_uri(self):
> 113 + """Test getting the uri from the server."""
> 114 + expected = "http://
> 115 + self.assert_
>
> 128 + def test_get_
> 129 + """Test getting the ssl iri."""
> 130 + self.assertEqua
> 131 +
> 132 + def test_get_
> 133 + """Test getting the ssl uri."""
> 134 + self.assertEqua
>
> 274 + def get_iri(self):
> 275 + """Build the iri for this mock server."""
> 276 + url = u"http://
> 277 + return url % self.get_port()
> 278 +
> 279 + def get_uri(self):
> 280 + """Build the uri for this mock server."""
> 281 + url = "http://
> 282 + return url % self.get_port()
> 283 +
> 284 + def get_ssl_iri(self):
> 285 + """Build the ssl iri for this mock server."""
> 286 + if self.ssl_settings:
> 287 + url = u"https:/
> 288 + return url % self.get_ssl_port()
> 289 +
> 290 + def get_ssl_uri(self):
> 291 + """Build the ssl iri for this mock server."""
> 292 + if self.ssl_settings:
> 293 + url = "https:/
> 294 + return url % self.get_ssl_port()
>
> Why all this duplicated code?
Looks like a merge fail from me, let me double check.
| Manuel de la Peña (mandel) wrote : | # |
> Nice branch. This is a very good second step in order to reduce the amount of
> boilerplate we have everywhere in our tests.
>
> The only bit I don't like is the many "if self.ssl_settings" scattered around.
> What about splitting the WebServer class into HTTPS and HTTP classes?
Sure!
| dobey (dobey) wrote : | # |
+SAMPLE_RESOURCE = '{"%s": "%s"}' % (SAMPLE_KEY, SAMPLE_VALUE)
There are a lot of strings being combined with %-notation in here. Please use the new .format() notation for string formatting instead, as %-notation is deprecated. As the new notation uses {0} for example as insertion markers, you probably should use unicode(
| Alejandro J. Cura (alecu) wrote : | # |
> +SAMPLE_RESOURCE = '{"%s": "%s"}' % (SAMPLE_KEY, SAMPLE_VALUE)
>
> There are a lot of strings being combined with %-notation in here. Please use
> the new .format() notation for string formatting instead, as %-notation is
> deprecated. As the new notation uses {0} for example as insertion markers, you
> probably should use unicode(
> u'{0}'.
The SAMPLE_RESOURCE is just a json-like sequence of bytes used for testing, so the fix requested is wrong.
It should be something like:
+SAMPLE_RESOURCE = '{{"{0}": "{1}"}}
Also, and for the record, the string interpolation operator % is not deprecated; not even in python 3.3:
"there are no current plans to deprecate printf-style formatting."
http://
| dobey (dobey) wrote : | # |
Can we have the scheme, host, and port all passed around separately? Passing around "http://
| dobey (dobey) wrote : | # |
Also, as this doesn't provide any testcases, I think it's better to be under testing/ instead of testcases/.
| Ubuntu One Auto Pilot (otto-pilot) wrote : | # |
The attempt to merge lp:~mandel/ubuntuone-dev-tools/mocked-webserver into lp:ubuntuone-dev-tools failed. Below is the output from the failed tests.
Traceback (most recent call last):
File "bin/u1trial", line 337, in <module>
main()
File "bin/u1trial", line 317, in main
suite = trial_runner.
File "bin/u1trial", line 196, in get_suite
config[
File "bin/u1trial", line 180, in _collect_tests
module_suite = self._load_
File "bin/u1trial", line 120, in _load_unittest
module = __import__(modpath, None, None, [""])
ImportError: No module named tests.test_
- 99. By Manuel de la Peña on 2012-04-17
-
Added missing __init__.py

107 + def test_get_iri(self): 127.0.0. 1:%d/" url(expected) 127.0.0. 1:%d/" url(expected)
108 + """Test getting the iri from the server."""
109 + expected = u"http://
110 + self.assert_
111 +
112 + def test_get_uri(self):
113 + """Test getting the uri from the server."""
114 + expected = "http://
115 + self.assert_
128 + def test_get_ ssl_iri( self): l(None, self.server. get_ssl_ uri()) ssl_uri( self): l(None, self.server. get_ssl_ uri())
129 + """Test getting the ssl iri."""
130 + self.assertEqua
131 +
132 + def test_get_
133 + """Test getting the ssl uri."""
134 + self.assertEqua
274 + def get_iri(self): 127.0.0. 1:%d/" 127.0.0. 1:%d/" /127.0. 0.1:%d/" /127.0. 0.1:%d/"
275 + """Build the iri for this mock server."""
276 + url = u"http://
277 + return url % self.get_port()
278 +
279 + def get_uri(self):
280 + """Build the uri for this mock server."""
281 + url = "http://
282 + return url % self.get_port()
283 +
284 + def get_ssl_iri(self):
285 + """Build the ssl iri for this mock server."""
286 + if self.ssl_settings:
287 + url = u"https:/
288 + return url % self.get_ssl_port()
289 +
290 + def get_ssl_uri(self):
291 + """Build the ssl iri for this mock server."""
292 + if self.ssl_settings:
293 + url = "https:/
294 + return url % self.get_ssl_port()
Why all this duplicated code?