Skip to content
This repository has been archived by the owner on Jan 4, 2023. It is now read-only.

Commit

Permalink
fix(e2e): destroy_mimic_mapping as fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
simonvadee committed Oct 15, 2021
1 parent 348a2a4 commit c4ba44c
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,16 @@
DATA_FIXTURES_DIR = Path(__file__).resolve().parent.parent / "fixtures"


def destroy_source(source):
@pytest.fixture(scope="session")
def destroy_mimic_source(mimic_mapping):
"""Removes source from river-api if exists"""
response = requests.get(f"{settings.RIVER_API_URL}/sources/")
for existing_source in response.json():
if existing_source["name"] == source["name"]:
response = requests.delete(f"{settings.RIVER_API_URL}/sources/{source['id']}/")
if existing_source["name"] == mimic_mapping["name"]:
response = requests.delete(f"{settings.RIVER_API_URL}/sources/{existing_source['id']}/")
assert (
response.status_code == 204
), f"api DELETE /sources/{source['id']}/ returned an error: {response.text}"
), f"api DELETE /sources/{existing_source['id']}/ returned an error: {response.text}"


@pytest.fixture(scope="session")
Expand Down Expand Up @@ -51,7 +52,7 @@ def mimic_mapping():


@pytest.fixture(scope="session")
def uploaded_mapping(mimic_mapping):
def uploaded_mapping(mimic_mapping, destroy_mimic_source):
"""Impots the mimic mapping to river-api
Args:
Expand All @@ -63,7 +64,6 @@ def uploaded_mapping(mimic_mapping):
Yields:
dict: The uploaded mapping
"""
destroy_source(mimic_mapping)
try:
# send a batch request
response = requests.post(f"{settings.RIVER_API_URL}/sources/import/", json=mimic_mapping)
Expand Down

0 comments on commit c4ba44c

Please sign in to comment.