Skip to content

Commit

Permalink
Simplify mysql tests (#459)
Browse files Browse the repository at this point in the history
  • Loading branch information
aminalaee committed Jul 28, 2022
1 parent 6427be4 commit 6a52a4a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 53 deletions.
51 changes: 0 additions & 51 deletions tests/test_databases.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import functools
import os
import re
import sys
from unittest.mock import MagicMock, patch

import pytest
Expand All @@ -17,23 +16,6 @@
DATABASE_URLS = [url.strip() for url in os.environ["TEST_DATABASE_URLS"].split(",")]


def mysql_versions(wrapped_func):
"""
Decorator used to handle multiple versions of Python for mysql drivers
"""

@functools.wraps(wrapped_func)
def check(*args, **kwargs): # pragma: no cover
url = DatabaseURL(kwargs["database_url"])
if url.scheme in ["mysql", "mysql+aiomysql"] and sys.version_info >= (3, 10):
pytest.skip("aiomysql supports python 3.9 and lower")
if url.scheme == "mysql+asyncmy" and sys.version_info < (3, 7):
pytest.skip("asyncmy supports python 3.7 and higher")
return wrapped_func(*args, **kwargs)

return check


class AsyncMock(MagicMock):
async def __call__(self, *args, **kwargs):
return super(AsyncMock, self).__call__(*args, **kwargs)
Expand Down Expand Up @@ -145,7 +127,6 @@ def run_sync(*args, **kwargs):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_queries(database_url):
"""
Expand Down Expand Up @@ -223,7 +204,6 @@ async def test_queries(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_queries_raw(database_url):
"""
Expand Down Expand Up @@ -285,7 +265,6 @@ async def test_queries_raw(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_ddl_queries(database_url):
"""
Expand All @@ -305,7 +284,6 @@ async def test_ddl_queries(database_url):

@pytest.mark.parametrize("exception", [Exception, asyncio.CancelledError])
@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_queries_after_error(database_url, exception):
"""
Expand All @@ -327,7 +305,6 @@ async def test_queries_after_error(database_url, exception):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_results_support_mapping_interface(database_url):
"""
Expand Down Expand Up @@ -356,7 +333,6 @@ async def test_results_support_mapping_interface(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_results_support_column_reference(database_url):
"""
Expand Down Expand Up @@ -388,7 +364,6 @@ async def test_results_support_column_reference(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_result_values_allow_duplicate_names(database_url):
"""
Expand All @@ -405,7 +380,6 @@ async def test_result_values_allow_duplicate_names(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_fetch_one_returning_no_results(database_url):
"""
Expand All @@ -420,7 +394,6 @@ async def test_fetch_one_returning_no_results(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_execute_return_val(database_url):
"""
Expand All @@ -447,7 +420,6 @@ async def test_execute_return_val(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_rollback_isolation(database_url):
"""
Expand All @@ -467,7 +439,6 @@ async def test_rollback_isolation(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_rollback_isolation_with_contextmanager(database_url):
"""
Expand All @@ -490,7 +461,6 @@ async def test_rollback_isolation_with_contextmanager(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_transaction_commit(database_url):
"""
Expand All @@ -508,7 +478,6 @@ async def test_transaction_commit(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_transaction_commit_serializable(database_url):
"""
Expand Down Expand Up @@ -553,7 +522,6 @@ def delete_independently():


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_transaction_rollback(database_url):
"""
Expand All @@ -576,7 +544,6 @@ async def test_transaction_rollback(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_transaction_commit_low_level(database_url):
"""
Expand All @@ -600,7 +567,6 @@ async def test_transaction_commit_low_level(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_transaction_rollback_low_level(database_url):
"""
Expand All @@ -625,7 +591,6 @@ async def test_transaction_rollback_low_level(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_transaction_decorator(database_url):
"""
Expand Down Expand Up @@ -656,7 +621,6 @@ async def insert_data(raise_exception):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_datetime_field(database_url):
"""
Expand All @@ -681,7 +645,6 @@ async def test_datetime_field(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_decimal_field(database_url):
"""
Expand Down Expand Up @@ -709,7 +672,6 @@ async def test_decimal_field(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_json_field(database_url):
"""
Expand All @@ -732,7 +694,6 @@ async def test_json_field(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_custom_field(database_url):
"""
Expand All @@ -758,7 +719,6 @@ async def test_custom_field(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_connections_isolation(database_url):
"""
Expand All @@ -781,7 +741,6 @@ async def test_connections_isolation(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_commit_on_root_transaction(database_url):
"""
Expand All @@ -806,7 +765,6 @@ async def test_commit_on_root_transaction(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_connect_and_disconnect(database_url):
"""
Expand All @@ -830,7 +788,6 @@ async def test_connect_and_disconnect(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_connection_context(database_url):
"""
Expand Down Expand Up @@ -872,7 +829,6 @@ async def get_connection_2():


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_connection_context_with_raw_connection(database_url):
"""
Expand All @@ -886,7 +842,6 @@ async def test_connection_context_with_raw_connection(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_queries_with_expose_backend_connection(database_url):
"""
Expand Down Expand Up @@ -993,7 +948,6 @@ async def test_queries_with_expose_backend_connection(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_database_url_interface(database_url):
"""
Expand Down Expand Up @@ -1072,7 +1026,6 @@ async def test_iterate_outside_transaction_with_values(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_iterate_outside_transaction_with_temp_table(database_url):
"""
Expand Down Expand Up @@ -1102,7 +1055,6 @@ async def test_iterate_outside_transaction_with_temp_table(database_url):

@pytest.mark.parametrize("database_url", DATABASE_URLS)
@pytest.mark.parametrize("select_query", [notes.select(), "SELECT * FROM notes"])
@mysql_versions
@async_adapter
async def test_column_names(database_url, select_query):
"""
Expand Down Expand Up @@ -1170,7 +1122,6 @@ async def test_posgres_interface(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_postcompile_queries(database_url):
"""
Expand All @@ -1188,7 +1139,6 @@ async def test_postcompile_queries(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_result_named_access(database_url):
async with Database(database_url) as database:
Expand All @@ -1204,7 +1154,6 @@ async def test_result_named_access(database_url):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
@async_adapter
async def test_mapping_property_interface(database_url):
"""
Expand Down
3 changes: 1 addition & 2 deletions tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from starlette.testclient import TestClient

from databases import Database, DatabaseURL
from tests.test_databases import DATABASE_URLS, mysql_versions
from tests.test_databases import DATABASE_URLS

metadata = sqlalchemy.MetaData()

Expand Down Expand Up @@ -84,7 +84,6 @@ async def add_note(request):


@pytest.mark.parametrize("database_url", DATABASE_URLS)
@mysql_versions
def test_integration(database_url):
app = get_app(database_url)

Expand Down

0 comments on commit 6a52a4a

Please sign in to comment.