Skip to content

Commit

Permalink
py3.6 compatible test for test_default_origin
Browse files Browse the repository at this point in the history
in:
python/cpython@bd48d27

Python changed the implementation of fnmatch so that it generates a slightly different regex

So we change the test to actually test the functionality, and not depend on the regex generated
  • Loading branch information
tardyp committed Feb 26, 2017
1 parent fe22ca0 commit 696b66a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
2 changes: 0 additions & 2 deletions .py3.notworking.txt
@@ -1,2 +0,0 @@
buildbot.test.unit.test_www_rest.V2RootResource.test_default_origin

40 changes: 32 additions & 8 deletions master/buildbot/test/unit/test_www_rest.py
Expand Up @@ -99,26 +99,50 @@ def test_invalid_http_method(self):
yield self.render_resource(self.rsrc, b'/', method=b'PATCH')
self.assertSimpleError('invalid HTTP method', 400)

def do_check_origin_regexp(self, goods, bads):
self.assertEqual(len(self.rsrc.origins), 1)
regexp = self.rsrc.origins[0]
for good in goods:
self.assertTrue(
regexp.match(good),
"{} should match default origin({}), but its not".format(
good, regexp.pattern
))
for bad in bads:
self.assertFalse(
regexp.match(bad),
"{} should not match default origin({}), but it is".format(
bad, regexp.pattern
))

def test_default_origin(self):
self.master.config.buildbotURL = 'http://server/path/'
self.rsrc.reconfigResource(self.master.config)
self.assertEqual(
[r.pattern for r in self.rsrc.origins], [r'http\:\/\/server\Z(?ms)'])
self.do_check_origin_regexp(
["http://server"],
["http://otherserver", "http://otherserver:909"],
)

self.master.config.buildbotURL = 'http://server/'
self.rsrc.reconfigResource(self.master.config)
self.assertEqual(
[r.pattern for r in self.rsrc.origins], [r'http\:\/\/server\Z(?ms)'])
self.do_check_origin_regexp(
["http://server"],
["http://otherserver", "http://otherserver:909"],
)

self.master.config.buildbotURL = 'http://server:8080/'
self.rsrc.reconfigResource(self.master.config)
self.assertEqual(
[r.pattern for r in self.rsrc.origins], [r'http\:\/\/server\:8080\Z(?ms)'])
self.do_check_origin_regexp(
["http://server:8080"],
["http://otherserver", "http://server:909"],
)

self.master.config.buildbotURL = 'https://server:8080/'
self.rsrc.reconfigResource(self.master.config)
self.assertEqual(
[r.pattern for r in self.rsrc.origins], [r'https\:\/\/server\:8080\Z(?ms)'])
self.do_check_origin_regexp(
["https://server:8080"],
["http://server:8080", "https://otherserver:8080"],
)


class V2RootResource_CORS(www.WwwTestMixin, unittest.TestCase):
Expand Down

0 comments on commit 696b66a

Please sign in to comment.