Commit 1be1b896 authored by Spencer Sutton's avatar Spencer Sutton
Browse files

Fixing unit tests

parent 1c5b224d
......@@ -49,6 +49,7 @@ phases:
# run unit tests
- cp osdu_api/test/osdu_api.ini osdu_api.ini
- rm -r osdu_api/test/providers-unit-tests
- python -m unittest discover osdu_api/test
- rm osdu_api.ini
......
......@@ -63,11 +63,6 @@ class BaseClient:
self.use_service_principal = config_manager.getbool('environment', 'use_service_principal', False)
if self.use_service_principal:
self.service_principal_module_name = config_manager.get('provider', 'service_principal_module_name')
config_parser = SafeConfigParser(os.environ)
config_file_name = 'osdu_api.ini'
found_names = config_parser.read(config_file_name)
if config_file_name not in found_names:
raise Exception('Could not find osdu_api.ini config file')
if data_partition_id is None:
self.data_partition_id = config_manager.get('environment', 'data_partition_id')
......
......@@ -27,7 +27,7 @@ class TestDefaultConfigManager:
@pytest.fixture
def default_config_file(self):
cwd = os.getcwd()
config_file = f"{os.path.dirname(__file__)}/fake_configosdu_api.ini"
config_file = f"{os.path.dirname(__file__)}/fake_config/osdu_api/test/osdu_api.ini"
path = shutil.copy(config_file, cwd)
yield path
os.remove(path)
......@@ -37,12 +37,12 @@ class TestDefaultConfigManager:
DefaultConfigManager()
def test_configmanager_with_env_var(self):
config_file = f"{os.path.dirname(__file__)}/fake_configosdu_api.ini"
config_file = f"{os.path.dirname(__file__)}/fake_config/osdu_api/test/osdu_api.ini"
os.environ["OSDU_API_CONFIG_INI"] = config_file
DefaultConfigManager()
def test_configmanager_with_passed_directly(self):
config_file = f"{os.path.dirname(__file__)}/fake_configosdu_api.ini"
config_file = f"{os.path.dirname(__file__)}/fake_config/osdu_api/test/osdu_api.ini"
DefaultConfigManager(config_file)
def test_raise_error_if_no_file(self):
......
......@@ -13,7 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import unittest
import os
import mock
import responses
......@@ -28,7 +28,7 @@ class TestBaseClient(unittest.TestCase):
# Arrange
# Act
client = BaseClient(DefaultConfigManager('osdu_api.ini'), "opendes")
client = BaseClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
# Assert
mocked_token_method.assert_called()
......@@ -37,7 +37,7 @@ class TestBaseClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_make_request(self, mocked_token_method):
# Arrange
client = BaseClient(DefaultConfigManager('osdu_api.ini'), "opendes")
client = BaseClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
client.service_principal_token = 'stubbed'
responses.add(responses.PUT, 'http://stubbed', json={'response': 'true'}, status=200)
......
......@@ -14,7 +14,7 @@
import unittest
import mock
import os
from osdu_api.clients.base_client import BaseClient
from osdu_api.clients.data_workflow.data_workflow_client import DataWorkflowClient
from osdu_api.model.data_workflow.start_workflow import StartWorkflow
......@@ -28,7 +28,7 @@ class TestDataWorkflowClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_make_request(self, get_bearer_token_mock, make_request_mock):
# Arrange
client = DataWorkflowClient(DefaultConfigManager('osdu_api.ini'), "opendes")
client = DataWorkflowClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
client.service_principal_token = 'stubbed'
client.data_workflow_url = 'stubbed url'
client.headers = {}
......
......@@ -14,7 +14,7 @@
import unittest
import mock
import os
from osdu_api.clients.base_client import BaseClient
from osdu_api.clients.dataset.dataset_registry_client import DatasetRegistryClient
from osdu_api.model.dataset.create_dataset_registries_request import CreateDatasetRegistriesRequest
......@@ -32,7 +32,7 @@ class TestDatasetRegistryClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_make_request(self, get_bearer_token_mock, make_request_mock):
# Arrange
client = DatasetRegistryClient(DefaultConfigManager('osdu_api.ini'), "opendes")
client = DatasetRegistryClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
client.service_principal_token = 'stubbed'
client.dataset_registry_url = 'stubbed url'
client.headers = {}
......
......@@ -14,7 +14,7 @@
import unittest
import mock
import os
from osdu_api.clients.base_client import BaseClient
from osdu_api.clients.entitlements.entitlements_client import EntitlementsClient
from osdu_api.model.entitlements.group import Group
......@@ -27,7 +27,7 @@ class Test_Entitlments_Client(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_get_file_upload(self, get_bearer_token_mock, make_request_mock):
# Arrange
client = EntitlementsClient(DefaultConfigManager('osdu_api.ini'), "opendes")
client = EntitlementsClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
client.service_principal_token = 'stubbed'
client.entitlements_url = 'stubbed url'
client.headers = {}
......
......@@ -13,6 +13,7 @@
# limitations under the License.
import unittest
import mock
import os
from osdu_api.clients.ingestion_workflow.ingestion_workflow_client import IngestionWorkflowClient
from osdu_api.clients.base_client import BaseClient
from osdu_api.model.http_method import HttpMethod
......@@ -27,7 +28,7 @@ class TestIngestionWorkflowClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_make_request(self, get_bearer_token_mock, make_request_mock):
# Arrange
client = IngestionWorkflowClient(DefaultConfigManager('osdu_api.ini'), data_partition_id="osdu")
client = IngestionWorkflowClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), data_partition_id="osdu")
client.service_principal_token = 'stubbed'
client.ingestion_workflow_url = 'stubbed url'
client.headers = {}
......
......@@ -14,7 +14,7 @@
import unittest
import mock
import os
from osdu_api.clients.base_client import BaseClient
from osdu_api.clients.legal.legal_client import LegalClient
from osdu_api.configuration.config_manager import DefaultConfigManager
......@@ -26,7 +26,7 @@ class TestLegalClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_get_file_upload(self, get_bearer_token_mock, make_request_mock):
# Arrange
client = LegalClient(DefaultConfigManager('osdu_api.ini'), "opendes")
client = LegalClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
client.service_principal_token = 'stubbed'
client.legal_url = 'stubbed url'
client.headers = {}
......
......@@ -15,7 +15,7 @@
import json
import types
import unittest
import os
import mock
from osdu_api.clients.base_client import BaseClient
......@@ -99,7 +99,7 @@ class TestRecordClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_create_update_records_model_record(self, get_bearer_token_mock, make_request_mock):
# Arrange
record_client = RecordClient(DefaultConfigManager('osdu_api.ini'), "opendes")
record_client = RecordClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
record_client.service_principal_token = 'stubbed'
record_client.storage_url = 'stubbed url'
record_client.headers = {}
......@@ -114,7 +114,7 @@ class TestRecordClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_get_latest_record_version(self, get_bearer_token_mock, make_request_mock):
# Arrange
record_client = RecordClient(DefaultConfigManager('osdu_api.ini'), "opendes")
record_client = RecordClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
record_client.service_principal_token = 'stubbed'
record_client.storage_url = 'stubbed url'
record_client.headers = {}
......@@ -131,7 +131,7 @@ class TestRecordClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_get_specific_record_version(self, get_bearer_token_mock, make_request_mock):
# Arrange
record_client = RecordClient(DefaultConfigManager('osdu_api.ini'), "opendes")
record_client = RecordClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
record_client.service_principal_token = 'stubbed'
record_client.storage_url = 'stubbed url'
record_client.headers = {}
......@@ -149,7 +149,7 @@ class TestRecordClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_get_record_versions(self, get_bearer_token_mock, make_request_mock):
# Arrange
record_client = RecordClient(DefaultConfigManager('osdu_api.ini'), "opendes")
record_client = RecordClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
record_client.service_principal_token = 'stubbed'
record_client.storage_url = 'stubbed url'
record_client.headers = {}
......
......@@ -14,7 +14,7 @@
import unittest
import mock
import os
from osdu_api.clients.base_client import BaseClient
from osdu_api.clients.search.search_client import SearchClient
from osdu_api.model.http_method import HttpMethod
......@@ -28,7 +28,7 @@ class TestSeachClient(unittest.TestCase):
@mock.patch.object(BaseClient, '_refresh_service_principal_token', return_value="stubbed")
def test_make_request(self, get_bearer_token_mock, make_request_mock):
# Arrange
client = SearchClient(DefaultConfigManager('osdu_api.ini'), "opendes")
client = SearchClient(DefaultConfigManager(os.getcwd() + '/osdu_api/test/osdu_api.ini'), "opendes")
client.service_principal_token = 'stubbed'
client.data_workflow_url = 'stubbed url'
client.headers = {}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment