From a424ce0b84052870f7ab9505ea6ef44145bc5f0f Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Wed, 4 Aug 2021 19:13:51 -0400 Subject: [PATCH 1/4] Fix tests with aiopg>=1.3; still compatible with aiopg<1.3 --- tests.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/tests.py b/tests.py index 3aff85b..d0020cc 100644 --- a/tests.py +++ b/tests.py @@ -415,7 +415,7 @@ class RequestHandlerMixinTestCase(TestCase): data = json.loads(response.body) self.assertEqual(data['status'], 'unavailable') - @mock.patch('aiopg.cursor.Cursor.execute') + @mock.patch('aiopg.Cursor.execute') def test_postgres_status_error(self, execute): execute.side_effect = asyncio.TimeoutError() response = self.fetch('/status') @@ -428,7 +428,7 @@ class RequestHandlerMixinTestCase(TestCase): self.assertIsInstance( uuid.UUID(json.loads(response.body)['value']), uuid.UUID) - @mock.patch('aiopg.cursor.Cursor.execute') + @mock.patch('aiopg.Cursor.execute') def test_postgres_error(self, execute): execute.side_effect = asyncio.TimeoutError response = self.fetch('/error') @@ -556,7 +556,7 @@ class RequestHandlerMixinTestCase(TestCase): data = json.loads(response.body) self.assertEqual(data['count'], 5) - @mock.patch('aiopg.cursor.Cursor.execute') + @mock.patch('aiopg.Cursor.execute') def test_timeout_error_when_overriding_on_postgres_error(self, execute): execute.side_effect = asyncio.TimeoutError response = self.fetch('/timeout-error') @@ -566,7 +566,7 @@ class RequestHandlerMixinTestCase(TestCase): response = self.fetch('/unhandled-exception') self.assertEqual(response.code, 422) - @mock.patch('aiopg.cursor.Cursor.execute') + @mock.patch('aiopg.Cursor.execute') def test_postgres_execute_timeout_error(self, execute): execute.side_effect = asyncio.TimeoutError() response = self.fetch('/pdexecute?value=1') @@ -574,7 +574,7 @@ class RequestHandlerMixinTestCase(TestCase): problem = json.loads(response.body) self.assertEqual(problem['title'], 'Query Timeout') - @mock.patch('aiopg.cursor.Cursor.execute') + @mock.patch('aiopg.Cursor.execute') def test_postgres_execute_unique_violation(self, execute): execute.side_effect = errors.UniqueViolation() response = self.fetch('/pdexecute?value=1') @@ -582,7 +582,7 @@ class RequestHandlerMixinTestCase(TestCase): problem = json.loads(response.body) self.assertEqual(problem['title'], 'Unique Violation') - @mock.patch('aiopg.cursor.Cursor.execute') + @mock.patch('aiopg.Cursor.execute') def test_postgres_execute_error(self, execute): execute.side_effect = psycopg2.Error() response = self.fetch('/pdexecute?value=1') @@ -590,7 +590,7 @@ class RequestHandlerMixinTestCase(TestCase): problem = json.loads(response.body) self.assertEqual(problem['title'], 'Database Error') - @mock.patch('aiopg.cursor.Cursor.fetchone') + @mock.patch('aiopg.Cursor.fetchone') def test_postgres_programming_error(self, fetchone): fetchone.side_effect = psycopg2.ProgrammingError() response = self.fetch('/pdexecute?value=1') @@ -609,28 +609,28 @@ class HTTPErrorTestCase(TestCase): sprockets_postgres.problemdetails = self._problemdetails super().tearDown() - @mock.patch('aiopg.cursor.Cursor.execute') + @mock.patch('aiopg.Cursor.execute') def test_postgres_execute_timeout_error(self, execute): execute.side_effect = asyncio.TimeoutError() response = self.fetch('/execute?value=1') self.assertEqual(response.code, 500) self.assertIn(b'Query Timeout', response.body) - @mock.patch('aiopg.cursor.Cursor.execute') + @mock.patch('aiopg.Cursor.execute') def test_postgres_execute_unique_violation(self, execute): execute.side_effect = errors.UniqueViolation() response = self.fetch('/execute?value=1') self.assertEqual(response.code, 409) self.assertIn(b'Unique Violation', response.body) - @mock.patch('aiopg.cursor.Cursor.execute') + @mock.patch('aiopg.Cursor.execute') def test_postgres_execute_error(self, execute): execute.side_effect = psycopg2.Error() response = self.fetch('/execute?value=1') self.assertEqual(response.code, 500) self.assertIn(b'Database Error', response.body) - @mock.patch('aiopg.cursor.Cursor.fetchone') + @mock.patch('aiopg.Cursor.fetchone') def test_postgres_programming_error(self, fetchone): fetchone.side_effect = psycopg2.ProgrammingError() response = self.fetch('/execute?value=1') @@ -650,7 +650,7 @@ class HTTPErrorTestCase(TestCase): class NoMixinTestCase(TestCase): - @mock.patch('aiopg.cursor.Cursor.execute') + @mock.patch('aiopg.Cursor.execute') def test_postgres_cursor_raises(self, execute): execute.side_effect = psycopg2.ProgrammingError() response = self.fetch('/no-mixin') From f0adbedf5147b97d3681ed72a8bcba4dc9335298 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Wed, 4 Aug 2021 19:36:33 -0400 Subject: [PATCH 2/4] Fix broken test ttl was -1 for this host, thus the test failed. Not sure what the intention of this test was; ttl is never used by sprockets-postgres. --- aiodns was returning the following records for this lookup ``` [ host=alt2.xmpp-server.l.google.com, port=5269, priority=20, weight=0, ttl=-1, host=xmpp-server.l.google.com, port=5269, priority=5, weight=0, ttl=-1, host=alt4.xmpp-server.l.google.com, port=5269, priority=20, weight=0, ttl=-1, host=alt1.xmpp-server.l.google.com, port=5269, priority=20, weight=0, ttl=-1, host=alt3.xmpp-server.l.google.com, port=5269, priority=20, weight=0, ttl=-1] ``` Also noticed a ttl of -1 with `_xmpp-server._tcp.jabber.org` --- tests.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests.py b/tests.py index d0020cc..44b6459 100644 --- a/tests.py +++ b/tests.py @@ -743,7 +743,6 @@ class SRVTestCase(asynctest.TestCase): obj = Application() result = await obj._resolve_srv('_xmpp-server._tcp.google.com') self.assertIsInstance(result[0], pycares.ares_query_srv_result) - self.assertGreater(result[0].ttl, 0) async def test_srv_error(self): obj = Application() From 555c5195bd3ba18680c24aad8adb634b7a9be796 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Wed, 4 Aug 2021 19:38:48 -0400 Subject: [PATCH 3/4] Add support for aiodns>3,<4 There is nothing between 2.0.0 and 3.0.0 which breaks our usage https://github.com/saghul/aiodns/compare/aiodns-2.0.0...aiodns-3.0.0#diff-747d6ba768991c3ef9a3f37637383ba3ef677cd84599372ddc49562bc1411ca5 --- setup.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.cfg b/setup.cfg index 1bc809a..37c1640 100644 --- a/setup.cfg +++ b/setup.cfg @@ -35,7 +35,7 @@ keywords = include_package_data = True install_requires = aiopg>=1.0.0,<2 - aiodns>=2,<3 + aiodns>=2,<4 sprockets.http>=2.1.1,<3 tornado>=6,<7 py_modules = From ec795d17e9bd856eb4c72fb5b569c314cb9ca4b9 Mon Sep 17 00:00:00 2001 From: Andrew Rabert Date: Tue, 15 Mar 2022 18:33:46 -0400 Subject: [PATCH 4/4] Run tests on PR --- .github/workflows/testing.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 5e08fd7..324c057 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -8,6 +8,7 @@ on: - '*.md' - '*.rst' tags-ignore: ["*"] + pull_request: jobs: test: runs-on: ubuntu-latest