Merge lp:~allenap/maas/spurious-oauth-headers-test into lp:~maas-committers/maas/trunk

Proposed by Gavin Panella
Status: Merged
Approved by: Gavin Panella
Approved revision: no longer in the source branch.
Merged at revision: 5647
Proposed branch: lp:~allenap/maas/spurious-oauth-headers-test
Merge into: lp:~maas-committers/maas/trunk
Diff against target: 59 lines (+26/-9)
1 file modified
src/provisioningserver/refresh/tests/test_maas_api_helper.py (+26/-9)
To merge this branch: bzr merge lp:~allenap/maas/spurious-oauth-headers-test
Reviewer Review Type Date Requested Status
Lee Trager (community) Approve
Mike Pontillo (community) Approve
Review via email: mp+315240@code.launchpad.net

Commit message

Be a little more flexible with the oauth_timestamp field in test_oauth_headers.

Previously this was failing when run just before the clock ticked to the next second.

To post a comment you must log in.
Revision history for this message
Mike Pontillo (mpontillo) wrote :

Interesting. I guess running the tests in parallel is enough to make this take more than 1 second more often.

review: Approve
Revision history for this message
Lee Trager (ltrager) wrote :

I actually just did a similar fix for test_oauth_headers in lp:~ltrager/maas/use_testing_metadata_api

review: Approve
Revision history for this message
Gavin Panella (allenap) wrote :

> Interesting. I guess running the tests in parallel is enough to make
> this take more than 1 second more often.

I can trigger this just by running the test a few times with
bin/test.rack.

Thanks for the review!

Revision history for this message
Gavin Panella (allenap) wrote :

> I actually just did a similar fix for test_oauth_headers in
> lp:~ltrager/maas/use_testing_metadata_api

Ah, sorry, this will conflict with yours, but I hope it won't be too onerous to resolve.

Thanks for the review!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/provisioningserver/refresh/tests/test_maas_api_helper.py'
2--- src/provisioningserver/refresh/tests/test_maas_api_helper.py 2017-01-11 14:05:26 +0000
3+++ src/provisioningserver/refresh/tests/test_maas_api_helper.py 2017-01-20 15:55:40 +0000
4@@ -13,14 +13,30 @@
5 import urllib
6
7 from maastesting.factory import factory
8-from maastesting.matchers import MockAnyCall
9+from maastesting.matchers import (
10+ GreaterThanOrEqual,
11+ LessThanOrEqual,
12+ MockAnyCall,
13+)
14 from maastesting.testcase import MAASTestCase
15 from provisioningserver.refresh import maas_api_helper
16+from testtools.matchers import (
17+ AfterPreprocessing,
18+ Equals,
19+ MatchesAll,
20+ MatchesDict,
21+)
22
23
24 class TestHeaders(MAASTestCase):
25
26 def test_oauth_headers(self):
27+ now = time.time()
28+ is_about_now = MatchesAll(
29+ GreaterThanOrEqual(int(now)),
30+ LessThanOrEqual(int(now) + 3),
31+ )
32+
33 url = factory.make_name("url")
34 consumer_key = factory.make_name("consumer_key")
35 token_key = factory.make_name("token_key")
36@@ -39,14 +55,15 @@
37 self.assertIn('oauth_nonce', oauth_arguments)
38 oauth_arguments.pop('oauth_nonce', None)
39
40- self.assertEqual({
41- 'oauth_timestamp': format(time.time(), ".0f"),
42- 'oauth_version': '1.0',
43- 'oauth_signature_method': 'PLAINTEXT',
44- 'oauth_consumer_key': consumer_key,
45- 'oauth_token': token_key,
46- 'oauth_signature': "%s%%26%s" % (consumer_secret, token_secret),
47- }, oauth_arguments)
48+ self.assertThat(oauth_arguments, MatchesDict({
49+ 'oauth_timestamp': AfterPreprocessing(int, is_about_now),
50+ 'oauth_version': Equals('1.0'),
51+ 'oauth_signature_method': Equals('PLAINTEXT'),
52+ 'oauth_consumer_key': Equals(consumer_key),
53+ 'oauth_token': Equals(token_key),
54+ 'oauth_signature': Equals(
55+ "%s%%26%s" % (consumer_secret, token_secret)),
56+ }))
57
58 def test_authenticate_headers_appends_oauth(self):
59 url = factory.make_name("url")