def test_manifest_deletion(self): _, result = SQLStore.delete_manifest(self.test_model.id) self.assertEqual(self.result, 200, msg='Assert Manifest Deleted') exists = ManifestAdapter.exists_in_db(self.test_model.id) self.assertFalse(exists, msg='Assert manifest does NOT Exist.') manifest_sql = ManifestAdapter.find_by_id_name(self.test_model.id) self.assertIsNone(manifest_sql)
def test_service_deletion(self): _, result = SQLStore.delete_service(self.test_model.id) self.assertEqual(self.result, 200, msg='Assert Service Deleted') exists = ServiceTypeAdapter.exists_in_db(self.test_model.id) self.assertFalse(exists, msg='Assert service does NOT Exist.') service_sql = ServiceTypeAdapter.find_by_id_name(self.test_model.id) self.assertIsNone(service_sql)
def test_instance_deletion(self): _, result = SQLStore.delete_service_instance(self.id_name) self.assertEqual(self.result, 200, msg='Assert Instance Deleted') exists = Adapter.exists_in_db(self.id_name) self.assertFalse(exists, msg='Assert Instance does NOT Exist.') model_sql = Adapter.find_by_id_name(self.id_name) self.assertIsNone(model_sql)
def setUp(self): """PREREQUISITES""" PlanAdapter.create_table() ServiceTypeAdapter.create_table() PlanServiceTypeAdapter.create_table() self.service = ServiceTypeAdapter.sample_model('manifest1') ServiceTypeAdapter.save(self.service) ManifestAdapter.create_table() self.test_model = ManifestAdapter.sample_model('manifest1') _, self.result = SQLStore.add_manifest(self.test_model)
def setUp(self): """ PREREQUISITES """ PlanAdapter.create_table() ServiceTypeAdapter.create_table() PlanServiceTypeAdapter.create_table() # ManifestAdapter.create_table() self.service = ServiceTypeAdapter.sample_model('instance1') ServiceTypeAdapter.save(self.service) Adapter.create_table() self.test_model = Adapter.sample_model('instance1') self.id_name = Adapter.get_id(self.test_model) _, self.result = SQLStore.add_service_instance(self.test_model)
def test_add_service_existing(self, mock_exists): mock_exists.return_value = True _, result = SQLStore.add_service(self.test_model) self.assertEqual(result, 409, msg='Assert Service Already Exists')
def test_get_instance_with_id_as_none(self): models = SQLStore.get_service_instance(instance_id=None) self.assertNotEqual(models, [])
def test_get_manifest_with_id_and_not_found(self, mock_exists_in_db): mock_exists_in_db.return_value = False manifests = SQLStore.get_manifest(self.test_model.id) self.assertEqual(manifests, [])
def test_get_manifest_with_plan_id(self): result = SQLStore.get_manifest(manifest_id=None, plan_id=self.test_model.plan_id) self.assertGreater(len(result), 0) self.assertIsInstance(result[0], Manifest)
def test_get_instance_with_id_and_not_found(self, mock_exists_in_db): mock_exists_in_db.return_value = False models = SQLStore.get_service_instance(self.id_name) self.assertEqual(models, [])
def test_get_service_with_id_as_none(self): services = SQLStore.get_service(service_id=None) self.assertNotEqual(services, [])
def test_db_connect_successful(self): connection = SQLStore.get_connection() self.assertIsNotNone(connection) connection.close() wait_time = 0 SQLStore.set_up(wait_time)
def setUp(self): self.test_model = ServiceTypeAdapter.sample_model('service1') ServiceTypeAdapter.create_table() PlanAdapter.create_table() PlanServiceTypeAdapter.create_table() _, self.result = SQLStore.add_service(self.test_model)
def test_get_service_with_id(self): services = SQLStore.get_service(service_id=self.test_model.id) self.assertGreater(len(services), 0) self.assertIsInstance(services[0], ServiceType)
def test_delete_service_nonexistent(self): _, result = SQLStore.delete_service(self.test_model.id) _, result = SQLStore.delete_service(self.test_model.id) self.assertEqual(result, 500, msg='Assert Delete Service Nonexistent')
def test_get_manifest_with_id(self): manifests = SQLStore.get_manifest(manifest_id=self.test_model.id) self.assertGreater(len(manifests), 0) self.assertIsInstance(manifests[0], Manifest)
def tearDown(self): SQLStore.delete_manifest(self.test_model.id) ServiceTypeAdapter.delete(self.service.id)
def test_get_manifest_with_id_as_none(self): manifests = SQLStore.get_manifest(manifest_id=None) self.assertNotEqual(manifests, [])
def test_delete_manifest_nonexistent(self): _, result = SQLStore.delete_manifest(self.test_model.id) _, result = SQLStore.delete_manifest(self.test_model.id) self.assertEqual(result, 500, msg='Assert Delete Manifest Nonexistent')
def test_delete_all(self): _, result = SQLStore.delete_service(service_id=None) self.assertEqual(self.result, 200, msg='Assert Service Delete w/ \'None\'')
def test_delete_instance_nonexistent(self): _, result = SQLStore.delete_service_instance(self.id_name) _, result = SQLStore.delete_service_instance(self.id_name) self.assertEqual(result, 500, msg='Assert Delete Instance Nonexistent')
def tearDown(self): SQLStore.delete_service(self.test_model.id)
def tearDown(self): SQLStore.delete_service_instance(Adapter.get_id(self.test_model)) ServiceTypeAdapter.delete(self.service.id)
def test_get_service_with_id_and_not_found(self, mock_exists_in_db): mock_exists_in_db.return_value = False services = SQLStore.get_service(self.test_model.id) self.assertEqual(services, [])
def test_get_instance_with_instance_id(self): result = SQLStore.get_service_instance(instance_id=self.id_name) self.assertGreater(len(result), 0) self.assertIsInstance(result[0], ServiceInstance)
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the # License for the specific language governing permissions and limitations # under the License. # GENERICS from adapters.store import SQLStore from unittest.mock import patch # TESTS from unittest import skipIf import unittest import os # TODO: move to test_store_backends module if os.getenv('MYSQL_TESTS', 'NO') == 'YES': SQLStore.set_up() @skipIf( os.getenv('MYSQL_TESTS', 'NO') != 'YES', "MYSQL_TESTS not set in environment variables") class TestCaseManifestManifest(unittest.TestCase): def test_db_connect_successful(self): connection = SQLStore.get_connection() self.assertIsNotNone(connection) connection.close() wait_time = 0 SQLStore.set_up(wait_time) @patch.object(SQLStore, 'get_connection') def test_db_connect_not_successful(self, mock_connection):
def test_get_instance_with_id(self): models = SQLStore.get_service_instance(instance_id=self.id_name) self.assertGreater(len(models), 0) self.assertIsInstance(models[0], ServiceInstance)
def test_db_connect_not_successful(self, mock_connection): wait_time = 0 mock_connection.return_value = None with self.assertRaises(Exception): SQLStore.set_up(wait_time)
def test_get_manifest_with_manifest_id_and_plan_id(self): with self.assertRaises(Exception): SQLStore.get_manifest(manifest_id=self.test_model.id, plan_id=self.test_model.plan_id)