def test_creation_service_generates_default_sample_code_when_selected( self, filesystem): project_loader = mock.MagicMock() creation_service = CreationService(project_loader) creation_options = CreationOptions(directory='AwesomeProject', project_name='AwesomeProject') creation_service.create(creation_options) filesystem.create_file.assert_called_with('AwesomeProject/main.cpp', CPP_HELLO_WORLD)
def test_it_creates_directory_and_descriptor_file_when_creating_project( self, filesystem): project_loader = mock.MagicMock() creation_service = CreationService(project_loader) creation_options = CreationOptions(generate_sample_code=False, directory='AwesomeProject', project_name='AwesomeProject') creation_service.create(creation_options) filesystem.create_directory.assert_called_once_with('AwesomeProject') filesystem.create_file.assert_called_once_with( 'AwesomeProject/project.yaml', mock.ANY)
def test_it_only_creates_descriptor_file_when_creating_project_from_existing_sources( self, filesystem): project_loader = mock.MagicMock() creation_service = CreationService(project_loader) creation_options = CreationOptions(generate_sample_code=False, directory='.', project_name='AwesomeProject', init_from_existing_sources=True) creation_service.create(creation_options) filesystem.create_directory.assert_not_called() filesystem.create_file.assert_called_once_with('./project.yaml', mock.ANY)
def test_creation_service_returns_generated_project(self, filesystem): project_loader = mock.MagicMock() creation_service = CreationService(project_loader) creation_options = CreationOptions(project_name='AwesomeProject') project = creation_service.create(creation_options) assert project.name == 'AwesomeProject' assert project.build.sources == ['main.cpp']
def test_creation_service_uses_cpm_hub_connector_to_download_template(self, project_descriptor_editor): project_loader = mock.MagicMock() cpm_hub_connector = mock.MagicMock() template_installer = mock.MagicMock() creation_service = CreationService(project_loader, cpm_hub_connector, template_installer) options = CreationOptions( project_name='AwesomeProject', init_from_template=True, template_name='arduino-uno', ) template_project = Project(name=options.project_name, version=DEFAULT_PROJECT_VERSION) project_loader.load.return_value = template_project project_template = ProjectTemplate( name='arduino-uno', version='1.0.0', payload='payload' ) cpm_hub_connector.download_template.return_value = project_template project = creation_service.create(options) assert project.name == 'AwesomeProject' template_installer.install.assert_called_once_with(project_template, options.directory) project_descriptor_editor.update.assert_called_once()