Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimise e2e tests #508

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 0 additions & 23 deletions tests/clean_mongo_db.py

This file was deleted.

8 changes: 0 additions & 8 deletions tests/e2e/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,13 @@
import mongomock
import pymongo
import pytest
from pymongo import MongoClient

from ted_sws import config
from ted_sws.data_manager.adapters.notice_repository import NoticeRepository
from ted_sws.data_manager.adapters.triple_store import AllegroGraphTripleStore, FusekiAdapter
from tests import TEST_DATA_PATH


@pytest.fixture
def mongodb_client():
uri = config.MONGO_DB_AUTH_URL
mongodb_client = MongoClient(uri)
return mongodb_client


@pytest.fixture
def allegro_triple_store():
return AllegroGraphTripleStore(host=config.ALLEGRO_HOST, user=config.AGRAPH_SUPER_USER,
Expand Down
22 changes: 4 additions & 18 deletions tests/e2e/data_manager/test_mongodb_client.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import random
import string

from pymongo import MongoClient

from ted_sws import config
from ted_sws.data_manager.adapters.notice_repository import NoticeRepository
from ted_sws.data_manager.services.create_batch_collection_materialised_view import \
Expand All @@ -20,10 +17,7 @@
from ted_sws.notice_metadata_processor.services.metadata_normalizer import normalise_notice


def test_mongodb_client(notice_2016):
uri = config.MONGO_DB_AUTH_URL
mongodb_client = MongoClient(uri)
mongodb_client.drop_database('test')
def test_mongodb_client(notice_2016, mongodb_client):
test_db = mongodb_client['test']
fruits_collection = test_db['fruits']
fruits_collection.insert_one({"banana": 10, "orange": 50})
Expand Down Expand Up @@ -57,10 +51,7 @@ def random_object() -> dict:
]


def test_mongodb_queries():
uri = config.MONGO_DB_AUTH_URL
mongodb_client = MongoClient(uri)
mongodb_client.drop_database('test')
def test_mongodb_queries(mongodb_client):
test_db = mongodb_client['test']
objects_collection = test_db['objects']
for i in range(0, 20):
Expand Down Expand Up @@ -105,10 +96,7 @@ def test_mongodb_queries():
covered_notice_ids.append(notice_id)


def test_mongo_db_query_2():
uri = config.MONGO_DB_AUTH_URL
mongodb_client = MongoClient(uri)
mongodb_client.drop_database('test')
def test_mongo_db_query_2(mongodb_client):
test_db = mongodb_client['test']
objects_collection = test_db['objects']
for i in range(0, 3):
Expand Down Expand Up @@ -191,9 +179,7 @@ def test_create_matview_for_notices(fake_mongodb_client):
assert 'status' in fields_in_the_kpi_collection


def test_create_matview_for_batches():
uri = config.MONGO_DB_AUTH_URL
mongodb_client = MongoClient(uri)
def test_create_matview_for_batches(mongodb_client):
create_batch_collection_materialised_view(mongo_client=mongodb_client)
db = mongodb_client[config.MONGO_DB_AGGREGATES_DATABASE_NAME]
assert NOTICE_PROCESS_BATCH_COLLECTION_NAME in db.list_collection_names()
Expand Down
14 changes: 0 additions & 14 deletions tests/e2e/data_sampler/conftest.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,14 @@
import pytest
from pymongo import MongoClient

from ted_sws import config
from ted_sws.data_manager.adapters.notice_repository import NoticeRepository
from ted_sws.data_sampler.services.notice_xml_indexer import index_notice
from ted_sws.mapping_suite_processor.services.conceptual_mapping_processor import \
mapping_suite_processor_from_github_expand_and_load_package_in_mongo_db
from ted_sws.notice_metadata_processor.services.metadata_normalizer import normalise_notice


@pytest.fixture
def mongodb_client():
mongodb_client = MongoClient(config.MONGO_DB_AUTH_URL)
protected_databases = ['admin', 'config', 'local']
existing_databases = mongodb_client.list_database_names()
databases_to_delete = list(set(existing_databases) - set(protected_databases))
for database in databases_to_delete:
mongodb_client.drop_database(database)
return mongodb_client


@pytest.fixture
def notice_repository_with_indexed_notices(mongodb_client) -> NoticeRepository:

mapping_suite_processor_from_github_expand_and_load_package_in_mongo_db(
mapping_suite_package_name="package_F03_test",
mongodb_client=mongodb_client,
Expand Down
2 changes: 1 addition & 1 deletion tests/features/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

@pytest.fixture
def mongodb_end_point():
return config.MONGO_DB_AUTH_URL
return "fake_mongo_db_end_point"


@pytest.fixture(scope="function")
Expand Down
Loading