Skip to content

Commit

Permalink
#1 got the db creation done. Looks like will continually need to upda…
Browse files Browse the repository at this point in the history
…te the basic_mock_pyarango to neuter any functionality for basic init tests as we go
  • Loading branch information
Isaiah committed May 12, 2021
1 parent a4abb8a commit 98a77c6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 9 deletions.
7 changes: 7 additions & 0 deletions lowball_arangodb_authdb/authdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ def __init__(self,
verify=self.verify
)

try:
self.database = self.connection[self.database_name]
except KeyError:
self.database = self.connection.createDatabase(name=self.database_name)



@property
def url(self):
return self._url
Expand Down
27 changes: 23 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ def init_calls_expected_connection(request):
verify=verify
)

@pytest.fixture
def basic_db_name():
return 'test'

class TestMockConnection(Connection):

Expand All @@ -242,7 +245,7 @@ class TestMockDocument(Document):
pass

@pytest.fixture
def basic_mock_pyarango(basic_mock_connection_init):
def basic_mock_pyarango(basic_mock_connection, basic_mock_database):

pass

Expand All @@ -255,16 +258,32 @@ def mock_pyarango(monkeypatch):
monkeypatch.setattr(lowball_arangodb_authdb.authdb, "Document", TestMockDocument)

@pytest.fixture
def basic_mock_connection_init(monkeypatch):
def basic_mock_connection(monkeypatch):

monkeypatch.setattr(TestMockConnection, "__init__", Mock(return_value=None))
monkeypatch.setattr(TestMockConnection, "createDatabase", Mock(return_value=Mock()))
monkeypatch.setattr(TestMockConnection, "__getitem__", Mock(return_value=None))

@pytest.fixture
def basic_mock_database(monkeypatch):

monkeypatch.setattr(TestMockDatabase, "__init__", Mock(return_value=None))

@pytest.fixture
def basic_mock_connection_get_item_db_not_present(monkeypatch):
def basic_mock_connection_get_item_db_not_present(monkeypatch, basic_db_name):

mock = Mock()
mock.side_effect = KeyError()
TestMockDatabase.name = basic_db_name
monkeypatch.setattr(TestMockDatabase, "__init__", Mock(return_value=None))
monkeypatch.setattr(TestMockConnection, "__init__", Mock(return_value=None))
monkeypatch.setattr(TestMockConnection, "__getitem__", mock)
monkeypatch.setattr(TestMockConnection, "createDatabase", Mock(return_value=TestMockDatabase(connection=Mock(), name="test")))
monkeypatch.setattr(TestMockConnection, "createDatabase", Mock(return_value=TestMockDatabase(connection=Mock(), name=basic_db_name)))

@pytest.fixture
def mock_connection_get_item_db_present(monkeypatch, basic_db_name):
TestMockDatabase.name = basic_db_name
monkeypatch.setattr(TestMockDatabase, "__init__", Mock(return_value=None))
monkeypatch.setattr(TestMockConnection, "__init__", Mock(return_value=None))
monkeypatch.setattr(TestMockConnection, "__getitem__", Mock(return_value=TestMockDatabase(connection=Mock(), name=basic_db_name)))

24 changes: 19 additions & 5 deletions tests/test_authdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
from unittest.mock import call
import pyArango
from pyArango.connection import Connection
from pyArango.collection import Collection
from pyArango.database import Database
from pyArango.document import Document

class TestAuthDBInit:
"""Tests:
Expand Down Expand Up @@ -235,7 +238,7 @@ def test_validation_of_index_client_id_if_bool(self,

def test_arango_connection_created_correctly(self, mock_pyarango, init_calls_expected_connection,
basic_mock_pyarango,
basic_mock_connection_init):
basic_mock_connection):

params, expected_call = init_calls_expected_connection

Expand All @@ -246,13 +249,24 @@ def test_arango_connection_created_correctly(self, mock_pyarango, init_calls_exp
def test_authentication_database_created_if_not_present(self,
mock_pyarango,
basic_mock_connection_get_item_db_not_present,
basic_mock_connection_init):
basic_db_name):

pass
authdb = AuthDB(database_name=basic_db_name)
authdb.connection.__getitem__.assert_called_once_with(basic_db_name)
authdb.connection.createDatabase.assert_called_once_with(name=basic_db_name)

def test_authentication_database_accessed_if_present(self):
assert isinstance(authdb.database, Database)
assert authdb.database.name == basic_db_name

pass
def test_authentication_database_accessed_if_present(self,
mock_pyarango,
basic_db_name,
mock_connection_get_item_db_present):
authdb = AuthDB(database_name=basic_db_name)
authdb.connection.__getitem__.assert_called_once_with(basic_db_name)

assert isinstance(authdb.database, Database)
assert authdb.database.name == basic_db_name

def test_authentication_collection_created_if_not_present(self):

Expand Down

0 comments on commit 98a77c6

Please sign in to comment.