diff --git a/setup.py b/setup.py index cc6d3fde..c9d8ee63 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,6 @@ def run(self): extras_require = { 'test': [ 'pytest>=5', - 'pytest-django>=3.5', 'celery>=5', ], 'lint': [ diff --git a/tests/conftest.py b/tests/conftest.py index 3608bb19..ea9e7416 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -16,9 +16,6 @@ Team, ) import pytest -from pytest_django.fixtures import ( - _disable_native_migrations, -) from pretix_eth.payment import Ethereum from rest_framework.test import APIClient @@ -137,67 +134,6 @@ def _get_order_and_payment(order_kwargs=None, payment_kwargs=None, info_data=Non return _get_order_and_payment -@pytest.fixture(scope="function") -def django_db_setup( - request, - django_test_environment, - django_db_blocker, - django_db_use_migrations, - django_db_keepdb, - django_db_createdb, - django_db_modify_db_settings, -): - """ - Copied and pasted from here: - https://github.com/pytest-dev/pytest-django/blob/d2973e21c34d843115acdbccdd7a16cb2714f4d3/pytest_django/fixtures.py#L84 - - We override this fixture and give it a "function" scope as a hack to force - the test database to be re-created per test case. This causes the same - database ids to be used for payment records in each test run. Usage of the - `reset_sequences` flag provided by pytest-django isn't always sufficient - since it can depend on whether or not a particular database supports - sequence resets. - - As an example of why sequence resets are necessary, tests in the - `tests.integration.test_confirm_payments` module will fail if database ids - are not reset per test function. This is because the test wallet on the - Goerli test net must hardcode payment ids into transactions and token - transfers. If payment ids don't deterministically begin at 1 per test - case, payment ids in the Goerli test wallet won't correctly correspond to - payment ids generated during test runs. - """ - from pytest_django.compat import setup_databases, teardown_databases - - setup_databases_args = {} - - if not django_db_use_migrations: - _disable_native_migrations() - - if django_db_keepdb and not django_db_createdb: - setup_databases_args["keepdb"] = True - - with django_db_blocker.unblock(): - db_cfg = setup_databases( - verbosity=request.config.option.verbose, - interactive=False, - **setup_databases_args - ) - - def teardown_database(): - with django_db_blocker.unblock(): - try: - teardown_databases(db_cfg, verbosity=request.config.option.verbose) - except Exception as exc: - request.node.warn( - pytest.PytestWarning( - "Error when trying to teardown test databases: %r" % exc - ) - ) - - if not django_db_keepdb: - request.addfinalizer(teardown_database) - - def pytest_addoption(parser): parser.addoption( "--require-web3", action="store_true", default=False, diff --git a/tests/integration/test_confirm_payments.py b/tests/integration/test_confirm_payments.py index c95ac63f..a17f5ccb 100644 --- a/tests/integration/test_confirm_payments.py +++ b/tests/integration/test_confirm_payments.py @@ -8,6 +8,7 @@ WEB3_PROVIDER_URI = os.environ.get("WEB3_PROVIDER_URI") +SINGLE_RECEIVER_ADDRESS = "0x0000000000000000000000000000000000000000" def check_web3_provider(pytesconfig): @@ -66,12 +67,10 @@ def make_order_payment(payment_info, provider, get_request_order_payment): { "currency": "ETH - Goerli", "amount": int("1000", base=10), - "hex_address": "0xb84AC43014d60AE5dCe5d36975eE461f31e953d3", }, # Has about 0.5 ETH { "currency": "DAI - Goerli", "amount": int("1000", base=10), - "hex_address": "0x18FF3A11FAF05F83198A8724006975ce414872Bc", }, # Has about 48 DAI ] @@ -84,10 +83,9 @@ def test_confirm_payment_enough( provider, event, get_request_order_payment, pytestconfig ): check_web3_provider(pytestconfig) - provider.settings.set("NETWORK_RPC_URL", - {"Goerli_RPC_URL": WEB3_PROVIDER_URI}) - provider.settings.set("SINGLE_RECEIVER_ADDRESS", - "0x0000000000000000000000000000000000000000") + provider.settings.set("NETWORK_RPC_URL", {"Goerli_RPC_URL": WEB3_PROVIDER_URI}) + provider.settings.set("SINGLE_RECEIVER_ADDRESS", SINGLE_RECEIVER_ADDRESS) + payments = [] orders = [] for payment_info in TEST_ENOUGH_AMOUNT: @@ -117,6 +115,7 @@ def test_confirm_payment_dry_run( ): check_web3_provider(pytestconfig) provider.settings.set("NETWORK_RPC_URL", {"Goerli_RPC_URL": WEB3_PROVIDER_URI}) + provider.settings.set("SINGLE_RECEIVER_ADDRESS", SINGLE_RECEIVER_ADDRESS) payments = [] orders = [] @@ -144,12 +143,10 @@ def test_confirm_payment_dry_run( { "currency": "ETH - Goerli", "amount": int("99000000", base=10), - "hex_address": "0xDb9574bf428A612fe13BEFFeB7F4bD8C73BF2D88", }, # Has about 10'000'000 wei { "currency": "DAI - Goerli", "amount": int("99000000", base=10), - "hex_address": "0x3d5091A1652e215c71C755BCfA97A08AFC9d6CB0", }, # Has about 32'035 wei ] @@ -163,6 +160,7 @@ def test_confirm_payment_lower_amount( ): check_web3_provider(pytestconfig) provider.settings.set("NETWORK_RPC_URL", {"Goerli_RPC_URL": WEB3_PROVIDER_URI}) + provider.settings.set("SINGLE_RECEIVER_ADDRESS", SINGLE_RECEIVER_ADDRESS) payments = [] orders = [] @@ -188,12 +186,10 @@ def test_confirm_payment_lower_amount( { "currency": "DAI - Goerli", "amount": int("1000", base=10), - "hex_address": "0xb84AC43014d60AE5dCe5d36975eE461f31e953d3", }, # Has enough amount, but in ETH { "currency": "ETH - Goerli", "amount": int("1000", base=10), - "hex_address": "0x18FF3A11FAF05F83198A8724006975ce414872Bc", }, # Has enough amount, but in DAI ] @@ -207,6 +203,7 @@ def test_confirm_payment_wrong_currency( ): check_web3_provider(pytestconfig) provider.settings.set("NETWORK_RPC_URL", {"Goerli_RPC_URL": WEB3_PROVIDER_URI}) + provider.settings.set("SINGLE_RECEIVER_ADDRESS", SINGLE_RECEIVER_ADDRESS) payments = [] orders = [] diff --git a/tox.ini b/tox.ini index f8fc25c2..2895b7af 100644 --- a/tox.ini +++ b/tox.ini @@ -13,7 +13,7 @@ exclude=venv,docs usedevelop=True commands= core: pytest {posargs:tests/core} - integration: pytest {posargs:tests/integration} + integration: pytest --require-web3 {posargs:tests/integration} extras=test basepython= py311: python3.11 @@ -22,6 +22,7 @@ basepython= py38: python3.8 py37: python3.7 passenv= + WEB3_PROVIDER_URI ETHERSCAN_API_KEY [testenv:lint]