diff --git a/tests/clean_mongo_db.py b/tests/clean_mongo_db.py deleted file mode 100644 index d315a2cf2..000000000 --- a/tests/clean_mongo_db.py +++ /dev/null @@ -1,23 +0,0 @@ -from logging import getLogger - -from pymongo import MongoClient - -from ted_sws import config - -logger = getLogger(__name__) - -def clean_mongo_db(): - uri = config.MONGO_DB_AUTH_URL - port = config.MONGO_DB_PORT - if port == 27018: - mongodb_client = MongoClient(uri) - 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) - else: - logger.warning("This was an attempt to erase the DB in NON-Staging environment.") - -clean_mongo_db() diff --git a/tests/e2e/conftest.py b/tests/e2e/conftest.py index 9198b1c81..ec4569925 100644 --- a/tests/e2e/conftest.py +++ b/tests/e2e/conftest.py @@ -3,7 +3,6 @@ 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 @@ -11,13 +10,6 @@ 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, diff --git a/tests/e2e/data_manager/test_mongodb_client.py b/tests/e2e/data_manager/test_mongodb_client.py index 820ea00ce..e22e1870e 100644 --- a/tests/e2e/data_manager/test_mongodb_client.py +++ b/tests/e2e/data_manager/test_mongodb_client.py @@ -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 \ @@ -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}) @@ -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): @@ -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): @@ -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() diff --git a/tests/e2e/data_sampler/conftest.py b/tests/e2e/data_sampler/conftest.py index c017ecca1..8f4cb0f93 100644 --- a/tests/e2e/data_sampler/conftest.py +++ b/tests/e2e/data_sampler/conftest.py @@ -1,7 +1,5 @@ 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 \ @@ -9,20 +7,8 @@ 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, diff --git a/tests/features/conftest.py b/tests/features/conftest.py index c44080227..1ef25315a 100644 --- a/tests/features/conftest.py +++ b/tests/features/conftest.py @@ -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")