9
9
from pathlib import Path
10
10
from types import SimpleNamespace
11
11
12
- import flask . testing
12
+ from django . test import Client
13
13
import pytest
14
14
import redis
15
15
import requests
16
16
import requests_mock
17
- import sqlalchemy
18
- from flask import current_app
19
- from pytest_flask .plugin import JSONResponse
17
+ from django .http import JsonResponse as JSONResponse
18
+ from django .core .cache import cache
20
19
21
- from lando .api .legacy .app import SUBSYSTEMS , construct_app , load_config
22
- from lando .api .legacy .cache import cache
20
+ from lando import settings
23
21
from lando .api .legacy .mocks .auth import TEST_JWKS , MockAuth0
24
22
from lando .api .legacy .phabricator import PhabricatorClient
25
23
from lando .api .legacy .projects import (
29
27
SEC_PROJ_SLUG ,
30
28
)
31
29
from lando .api .legacy .repos import SCM_LEVEL_1 , SCM_LEVEL_3 , Repo
32
- from lando .api .legacy .storage import db as _db
33
- from lando .api .legacy .tasks import celery
34
30
from lando .api .legacy .transplants import CODE_FREEZE_OFFSET , tokens_are_equal
35
- from tests .mocks import PhabricatorDouble , TreeStatusDouble
31
+ from lando . api . tests .mocks import PhabricatorDouble , TreeStatusDouble
36
32
37
33
PATCH_NORMAL_1 = r"""
38
34
# HG changeset patch
@@ -102,7 +98,7 @@ def _patch(number=0):
102
98
return _patch
103
99
104
100
105
- class JSONClient (flask . testing . FlaskClient ):
101
+ class JSONClient (Client ):
106
102
"""Custom Flask test client that sends JSON by default.
107
103
108
104
HTTP methods have a 'json=...' keyword that will JSON-encode the
@@ -242,39 +238,6 @@ def init_app(self, app, db):
242
238
monkeypatch .setattr ("landoapi.storage.migrate" , StubAlembic ())
243
239
244
240
245
- @pytest .fixture
246
- def app (versionfile , docker_env_vars , disable_migrations , mocked_repo_config ):
247
- """Needed for pytest-flask."""
248
- config = load_config ()
249
- # We need the TESTING setting turned on to get tracebacks when testing API
250
- # endpoints with the TestClient.
251
- config ["TESTING" ] = True
252
- config ["CACHE_DISABLED" ] = True
253
- app = construct_app (config )
254
- flask_app = app .app
255
- flask_app .test_client_class = JSONClient
256
- for system in SUBSYSTEMS :
257
- system .init_app (flask_app )
258
-
259
- return flask_app
260
-
261
-
262
- @pytest .fixture
263
- def db (app ):
264
- """Reset database for each test."""
265
- try :
266
- _db .engine .connect ()
267
- except sqlalchemy .exc .OperationalError :
268
- if EXTERNAL_SERVICES_SHOULD_BE_PRESENT :
269
- raise
270
- else :
271
- pytest .skip ("Could not connect to PostgreSQL" )
272
- _db .create_all ()
273
- yield _db
274
- _db .session .remove ()
275
- _db .drop_all ()
276
-
277
-
278
241
@pytest .fixture
279
242
def jwks (monkeypatch ):
280
243
monkeypatch .setattr ("landoapi.auth.get_jwks" , lambda * args , ** kwargs : TEST_JWKS )
@@ -356,8 +319,8 @@ def set_value(val):
356
319
@pytest .fixture
357
320
def get_phab_client (app ):
358
321
def get_client (api_key = None ):
359
- api_key = api_key or current_app . config [ " PHABRICATOR_UNPRIVILEGED_API_KEY" ]
360
- return PhabricatorClient (current_app . config [ " PHABRICATOR_URL" ] , api_key )
322
+ api_key = api_key or settings . PHABRICATOR_UNPRIVILEGED_API_KEY
323
+ return PhabricatorClient (settings . PHABRICATOR_URL , api_key )
361
324
362
325
return get_client
363
326
@@ -379,21 +342,6 @@ def redis_cache(app):
379
342
cache .init_app (app , config = {"CACHE_TYPE" : "null" , "CACHE_NO_NULL_WARNING" : True })
380
343
381
344
382
- @pytest .fixture
383
- def celery_app (app ):
384
- """Configure our app's Celery instance for use with the celery_worker fixture."""
385
- # The test suite will fail if we don't override the default worker and
386
- # default task set.
387
- # Note: the test worker will fail if we don't specify a result_backend. The test
388
- # harness uses the backend for a custom ping() task that it uses as a health check.
389
- celery .conf .update (broker_url = "memory://" , result_backend = "rpc" )
390
- # Workaround for https://github.com/celery/celery/issues/4032. If 'tasks.ping' is
391
- # missing from the loaded task list then the test worker will fail with an
392
- # AssertionError.
393
- celery .loader .import_module ("celery.contrib.testing.tasks" )
394
- return celery
395
-
396
-
397
345
@pytest .fixture
398
346
def treestatus_url ():
399
347
"""A string holding the Tree Status base URL."""
0 commit comments