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
=== modified file 'src/provisioningserver/refresh/tests/test_maas_api_helper.py'
--- src/provisioningserver/refresh/tests/test_maas_api_helper.py 2017-01-11 14:05:26 +0000
+++ src/provisioningserver/refresh/tests/test_maas_api_helper.py 2017-01-20 15:55:40 +0000
@@ -13,14 +13,30 @@
13import urllib13import urllib
1414
15from maastesting.factory import factory15from maastesting.factory import factory
16from maastesting.matchers import MockAnyCall16from maastesting.matchers import (
17 GreaterThanOrEqual,
18 LessThanOrEqual,
19 MockAnyCall,
20)
17from maastesting.testcase import MAASTestCase21from maastesting.testcase import MAASTestCase
18from provisioningserver.refresh import maas_api_helper22from provisioningserver.refresh import maas_api_helper
23from testtools.matchers import (
24 AfterPreprocessing,
25 Equals,
26 MatchesAll,
27 MatchesDict,
28)
1929
2030
21class TestHeaders(MAASTestCase):31class TestHeaders(MAASTestCase):
2232
23 def test_oauth_headers(self):33 def test_oauth_headers(self):
34 now = time.time()
35 is_about_now = MatchesAll(
36 GreaterThanOrEqual(int(now)),
37 LessThanOrEqual(int(now) + 3),
38 )
39
24 url = factory.make_name("url")40 url = factory.make_name("url")
25 consumer_key = factory.make_name("consumer_key")41 consumer_key = factory.make_name("consumer_key")
26 token_key = factory.make_name("token_key")42 token_key = factory.make_name("token_key")
@@ -39,14 +55,15 @@
39 self.assertIn('oauth_nonce', oauth_arguments)55 self.assertIn('oauth_nonce', oauth_arguments)
40 oauth_arguments.pop('oauth_nonce', None)56 oauth_arguments.pop('oauth_nonce', None)
4157
42 self.assertEqual({58 self.assertThat(oauth_arguments, MatchesDict({
43 'oauth_timestamp': format(time.time(), ".0f"),59 'oauth_timestamp': AfterPreprocessing(int, is_about_now),
44 'oauth_version': '1.0',60 'oauth_version': Equals('1.0'),
45 'oauth_signature_method': 'PLAINTEXT',61 'oauth_signature_method': Equals('PLAINTEXT'),
46 'oauth_consumer_key': consumer_key,62 'oauth_consumer_key': Equals(consumer_key),
47 'oauth_token': token_key,63 'oauth_token': Equals(token_key),
48 'oauth_signature': "%s%%26%s" % (consumer_secret, token_secret),64 'oauth_signature': Equals(
49 }, oauth_arguments)65 "%s%%26%s" % (consumer_secret, token_secret)),
66 }))
5067
51 def test_authenticate_headers_appends_oauth(self):68 def test_authenticate_headers_appends_oauth(self):
52 url = factory.make_name("url")69 url = factory.make_name("url")