def test_create_postgraas_twice(self): db_credentials = { "db_name": 'tests_postgraas_instance_name', "db_username": '******', "db_pwd": 'test_db_pwd', "host": pid.get_hostname(), "port": pid.get_open_port() } db_entry = DBInstance( postgraas_instance_name=db_credentials['db_name'], db_name=db_credentials['db_name'], username=db_credentials['db_username'], password="", hostname=db_credentials['host'], port=db_credentials['port']) db_entry.container_id = self.this_app.postgraas_backend.create( db_entry, db_credentials) with pytest.raises(PostgraasApiException) as excinfo: db_entry.container_id = self.this_app.postgraas_backend.create( db_entry, db_credentials) if self.backend == "pg_cluster": assert excinfo.value.message == 'db or user already exists' elif self.backend == "docker": assert excinfo.value.message == 'Container exists already' self.this_app.postgraas_backend.delete(db_entry) assert True
def test_create_postgres_instance_with_fully_qualified_username(self): db_credentials = { "db_name": 'test_db_name', "db_username": '******'.format(pid.get_hostname()), "db_pwd": 'test_db_pwd', "host": pid.get_hostname(), "port": pid.get_open_port() } mock_c = MagicMock() mock_c.id = 'dN4IsDN5eOqeCgli23MlxeTA' mock_create = Mock(return_value=mock_c) with patch.object(docker.models.containers.ContainerCollection, 'create', mock_create): result = pid.create_postgres_instance( 'tests_postgraas_test_instance_name', db_credentials ) assert result == 'dN4IsDN5eOqeCgli23MlxeTA'
def test_create_postgres_instance(self): db_credentials = { "db_name": 'test_db_name', "db_username": '******', "db_pwd": 'test_db_pwd', "host": pid.get_hostname(), "port": pid.get_open_port() } mock_c = MagicMock() mock_c.id = 'EW3uvF3C3tLce9Eo5D76NbQe' mock_create = Mock(return_value=mock_c) with patch.object(docker.models.containers.ContainerCollection, 'create', mock_create): result = pid.create_postgres_instance( 'tests_postgraas_test_instance_name', db_credentials ) assert result == 'EW3uvF3C3tLce9Eo5D76NbQe'
def test_driver_name_exists(self): db_credentials = { "db_name": 'test_db_name', "db_username": '******', "db_pwd": 'test_db_pwd', "host": pid.get_hostname(), "port": pid.get_open_port() } if pid.check_container_exists('test_instance_name'): pid.delete_postgres_instance('test_instance_name') id0 = pid.create_postgres_instance('test_instance_name', db_credentials) with pytest.raises(ValueError): pid.create_postgres_instance('test_instance_name', db_credentials) pid.delete_postgres_instance(id0) assert pid.check_container_exists(id0) is False, "container exists after it was deleted"
def test_create_postgres_instance_with_fully_qualified_username(self): db_credentials = { "db_name": 'test_db_name', "db_username": '******'.format(pid.get_hostname()), "db_pwd": 'test_db_pwd', "host": pid.get_hostname(), "port": pid.get_open_port() } mock_c = MagicMock() mock_c.id = 'dN4IsDN5eOqeCgli23MlxeTA' mock_create = Mock(return_value=mock_c) with patch.object(docker.models.containers.ContainerCollection, 'create', mock_create): result = pid.create_postgres_instance( 'tests_postgraas_test_instance_name', db_credentials) assert result == 'dN4IsDN5eOqeCgli23MlxeTA'
def test_create_postgres_instance(self): db_credentials = { "db_name": 'test_db_name', "db_username": '******', "db_pwd": 'test_db_pwd', "host": pid.get_hostname(), "port": pid.get_open_port() } mock_c = MagicMock() mock_c.id = 'EW3uvF3C3tLce9Eo5D76NbQe' mock_create = Mock(return_value=mock_c) with patch.object(docker.models.containers.ContainerCollection, 'create', mock_create): result = pid.create_postgres_instance( 'tests_postgraas_test_instance_name', db_credentials) assert result == 'EW3uvF3C3tLce9Eo5D76NbQe'
def test_driver_name_exists(self): db_credentials = { "db_name": 'test_db_name', "db_username": '******', "db_pwd": 'test_db_pwd', "host": pid.get_hostname(), "port": pid.get_open_port() } if pid.check_container_exists('test_instance_name'): pid.delete_postgres_instance('test_instance_name') id0 = pid.create_postgres_instance('test_instance_name', db_credentials) with pytest.raises(ValueError): pid.create_postgres_instance('test_instance_name', db_credentials) pid.delete_postgres_instance(id0) assert pid.check_container_exists( id0) is False, "container exists after it was deleted"
def test_create_and_delete_postgres_instance(self): db_credentials = { "db_name": 'tests_postgraas_instance_name', "db_username": '******', "db_pwd": 'test_db_pwd', "host": pid.get_hostname(), "port": pid.get_open_port() } db_entry = DBInstance( postgraas_instance_name=db_credentials['db_name'], db_name=db_credentials['db_name'], username=db_credentials['db_username'], password="", hostname=db_credentials['host'], port=db_credentials['port']) db_entry.container_id = self.this_app.postgraas_backend.create( db_entry, db_credentials) self.this_app.postgraas_backend.delete(db_entry) assert True
def test_delete_nonexisting_db(self): db_credentials = { "db_name": 'tests_postgraas_instance_name', "db_username": '******', "db_pwd": 'test_db_pwd', "host": pid.get_hostname(), "port": pid.get_open_port() } db_entry = DBInstance( postgraas_instance_name=db_credentials['db_name'], db_name=db_credentials['db_name'], username=db_credentials['db_username'], password="", hostname=db_credentials['host'], port=db_credentials['port'], container_id="4n8nz48az49prdmdmprmr4doesnotexit") with pytest.raises(PostgraasApiException) as excinfo: db_entry.container_id = self.this_app.postgraas_backend.delete( db_entry) assert 'does not exist' in excinfo.value.message
def test_create_postgraas_bad_username(self): db_credentials = { "db_name": 'tests_postgraas_instance_name', "db_username": '******', "db_pwd": 'test_db_pwd', "host": pid.get_hostname(), "port": pid.get_open_port() } db_entry = DBInstance( postgraas_instance_name=db_credentials['db_name'], db_name=db_credentials['db_name'], username=db_credentials['db_username'], password="", hostname=db_credentials['host'], port=db_credentials['port']) if self.backend == "pg_cluster": with pytest.raises(PostgraasApiException) as excinfo: db_entry.container_id = self.this_app.postgraas_backend.create( db_entry, db_credentials) self.this_app.postgraas_backend.delete(db_entry) assert 'syntax error at or near "-"' in excinfo.value.message