def test_project_actions_discovers_one_action_when_project_has_one_actions( self, ProjectLoader): project_loader = MagicMock() ProjectLoader.return_value = project_loader project = Project("cpm-hub") project.add_action(ProjectAction("deploy", "sudo make me a sandwich")) project_loader.load.return_value = project assert discover_project_actions() == [ ProjectActionRunner("deploy", "sudo make me a sandwich") ]
def test_service_build_ans_runs_only_specified_tests(self): project = Project('ProjectName') project.tests = ['test'] self.project_loader.load.return_value = project self.test_service.run_tests(['tests'], 'default') self.project_loader.load.assert_called_once() self.cmakelists_builder.build.assert_called_once_with( project, 'default') self.project_commands.build_tests.assert_called_once_with( project, 'default', ['tests']) self.project_commands.run_tests.assert_called_once_with( project, 'default', ['tests'])
def test_service_generates_the_recipe_then_compiles_and_runs_the_tests( self): project = Project('ProjectName') project.tests = ['test'] self.project_loader.load.return_value = project self.test_service.run_tests([], 'default') self.project_loader.load.assert_called_once() self.cmakelists_builder.build.assert_called_once_with( project, 'default') self.project_commands.build_tests.assert_called_once_with( project, 'default', []) self.project_commands.run_tests.assert_called_once_with( project, 'default', [])
def test_packaging_bit_raises_exception_when_output_directory_exists(self, filesystem): filesystem.directory_exists.return_value = True packager = BitPackager() project = Project('cest') project.build.add_package(Package('fakeit')) self.assertRaises(PackagingFailure, packager.pack, project, 'dist')
def test_service_raises_exception_when_no_test_suites_are_found(self): project = Project('ProjectName') self.project_loader.load.return_value = project self.assertRaises(NoTestsFound, self.test_service.run_tests, [], 'default') self.project_loader.load.assert_called_once()
def test_project_exists_when_loading_the_project_succeeds(self): project_loader = mock.MagicMock() project_loader.load.return_value = Project('dummy') creation_service = CreationService(project_loader) directory = '.' assert creation_service.exists(directory) project_loader.load.assert_called_once_with(directory)
def create(self, options): project = Project(options.project_name) if not options.init_from_existing_sources: self.create_project_directory(options.directory) self.create_project_descriptor_file(options) if options.generate_sample_code: self.generate_sample_code(project) return project
def test_publish_bit_raises_publication_error_when_status_code_is_not_200( self, getpass, input, http_client, filesystem): project = Project('cpm-hub') connector = CpmHubConnectorV1() http_client.post.return_value = HttpResponse(409, '') filesystem.read_file.return_value = b'bit payload' getpass.return_value = 'password' input.return_value = 'username' self.assertRaises(PublicationFailure, connector.publish_bit, project, 'cpm-hub.zip')
def test_publish_bit_raises_invalid_cpm_hub_url_on_status_code_404( self, getpass, input, http_client, filesystem): project = Project('cpm-hub') connector = CpmHubConnectorV1() http_client.post.return_value = HttpResponse(404, '') filesystem.read_file.return_value = b'bit payload' getpass.return_value = 'password' input.return_value = 'username' self.assertRaises(InvalidCpmHubUrl, connector.publish_bit, project, 'cpm-hub.zip')
def test_publish_bit_posts_bit_with_base64_encoded_payload_and_user_credentials( self, getpass, input, http_client, filesystem): project = Project('cpm-hub') connector = CpmHubConnectorV1() http_client.post.return_value = HttpResponse(200, '') filesystem.read_file.return_value = b'bit payload' getpass.return_value = 'password' input.return_value = 'username' connector.publish_bit(project, 'cpm-hub.zip') http_client.post.assert_called_once_with( connector.repository_url, data= '{"bit_name": "cpm-hub", "version": "0.1", "payload": "Yml0IHBheWxvYWQ=", "username": "******", "password": "******"}' )
def test_packaging_creates_output_directory(self, filesystem): filesystem.directory_exists.return_value = False packager = BitPackager() project = Project('cest') project.build.add_package(Package('api')) project.build.add_package(Package('domain')) packager.pack(project, 'dist') filesystem.create_directory.assert_called_once_with('dist') filesystem.copy_file.assert_called_once_with('project.yaml', 'dist/project.yaml') filesystem.copy_directory.assert_has_calls([ mock.call('api', 'dist/api'), mock.call('domain', 'dist/domain'), ]) filesystem.zip.assert_called_once_with('dist', 'cest') filesystem.remove_directory.assert_called_once_with('dist')
def test_project_actions_discovers_zero_actions_when_project_has_no_actions( self, ProjectLoader): project_loader = MagicMock() ProjectLoader.return_value = project_loader project_loader.load.return_value = Project("cpm-hub") assert discover_project_actions() == []
def test_packaging_bit_raises_exception_when_no_packages_are_declared(self): packager = BitPackager() project = Project('cest') self.assertRaises(PackagingFailure, packager.pack, project, 'dist')