def connect(self): """ Get the connection to the database service and set the model variables """ if not self.data_model and not self.variable_model: orm = DjangoORM() orm.connect() self.data_model = orm.data_model self.variable_model = orm.variable_model
def test_get_data_model(self): """ Test: The data model can be accessed When: After it is imported """ orm = DjangoORM() orm.connect() # pylint:disable=protected-access model = orm._get_data_model() actual = model.Instrument.objects.filter(name='GEM').first() self.assertIsNotNone(actual) self.assertEqual(actual.name, 'GEM')
def test_get_variable_model(self): """ Test: The variable model can be accessed When: After it is imported Note: This will fail if not pointing to the testing database """ orm = DjangoORM() orm.connect() # pylint:disable=protected-access model = orm._get_variable_model() actual = model.Variable.objects.filter(name='bool_variable').first() self.assertIsNotNone(actual) self.assertEqual(actual.name, 'bool_variable') self.assertEqual(actual.type, 'boolean')
def test_failed_connect(self, mock_data): """ Test: False is returned When: connect fails to retrieve data (raises an exception) """ mock_data.Instrument.objects.first.side_effect = RuntimeError orm = DjangoORM() self.assertFalse(orm.connect())
def test_connect(self): """ Test: The DjangoORM instance is exposed and populated as member variables When: calling the connect function """ orm = DjangoORM() self.assertTrue(orm.connect()) self.assertIsNotNone(orm.data_model.Instrument.objects.all()) self.assertIsNotNone(orm.variable_model.Variable.objects.all())