Skip to content

Commit

Permalink
Merge pull request #13 from nvllsvm/dep_stuff
Browse files Browse the repository at this point in the history
Fix tests, add support for aiodns>3,<4
  • Loading branch information
gmr committed Jun 28, 2022
2 parents e2b753e + ec795d1 commit c2a2f54
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
1 change: 1 addition & 0 deletions .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ on:
- '*.md'
- '*.rst'
tags-ignore: ["*"]
pull_request:
jobs:
test:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
25 changes: 12 additions & 13 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -415,7 +415,7 @@ def test_postgres_status_not_connected(self):
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')
Expand All @@ -428,7 +428,7 @@ def test_postgres_callproc(self):
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')
Expand Down Expand Up @@ -556,7 +556,7 @@ def test_row_count_no_rows(self):
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')
Expand All @@ -566,31 +566,31 @@ def test_unhandled_exception_in_on_postgres_error(self):
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')
self.assertEqual(response.code, 500)
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')
self.assertEqual(response.code, 409)
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')
self.assertEqual(response.code, 500)
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')
Expand All @@ -609,28 +609,28 @@ def tearDown(self):
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')
Expand All @@ -650,7 +650,7 @@ def test_on_error_no_exception_branch(self):

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')
Expand Down Expand Up @@ -743,7 +743,6 @@ async def test_srv_result(self):
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()
Expand Down

0 comments on commit c2a2f54

Please sign in to comment.