def test_do_import_package(self, mock_load_utils, mock_log): manage.CONF = mock.MagicMock() manage.CONF.command = mock.MagicMock( directory='test_dir', categories=[cat.name for cat in self.test_package.categories], update=True) mock_load_utils.load_from_dir.return_value = self.mock_loaded_package manage.do_import_package() # Assert that the function ran to completion. self.assertIn("Finished import of package", str(mock_log.info.mock_calls[0])) # Check that the package was uploaded to the DB. filter_params = { 'name': self.test_package.name, 'fully_qualified_name': self.test_package.fully_qualified_name, 'type': self.test_package.type, 'description': self.test_package.description } retrieved_package = None session = db_session.get_session() with session.begin(): retrieved_package = session.query(models.Package)\ .filter_by(**filter_params).first() self.assertIsNotNone(retrieved_package) self.assertNotEqual(self.test_package.id, retrieved_package.id)
def test_do_import_package_without_update(self, mock_db_catalog_api, mock_load_utils, mock_log): mock_db_catalog_api.package_search.return_value =\ [self.test_package] mock_load_utils.load_from_dir.return_value =\ mock.MagicMock(full_name='test_full_name') manage.CONF = mock.MagicMock() manage.CONF.command = mock.MagicMock(directory='test_dir', categories=[], update=False) manage.do_import_package() mock_log.error.assert_called_once_with( "Package '{name}' exists ({pkg_id}). Use --update.".format( name='test_full_name', pkg_id=self.test_package.id))