Esempio n. 1
0
    def test_project_does_not_exist_when_loading_the_project_fails(self):
        project_loader = mock.MagicMock()
        project_loader.load.side_effect = NotACpmProject
        creation_service = CreationService(project_loader)
        directory = 'project_location'

        assert not creation_service.exists(directory)
        project_loader.load.assert_called_once_with(directory)
Esempio n. 2
0
    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)
Esempio n. 3
0
    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']
Esempio n. 4
0
    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)
Esempio n. 5
0
    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)
Esempio n. 6
0
    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)
Esempio n. 7
0
def execute(argv):
    create_parser = argparse.ArgumentParser(
        prog='cpm create',
        description='Create a new cpm project',
        add_help=False)
    create_parser.add_argument('project_name')
    create_parser.add_argument('-s',
                               '--no-sample-code',
                               required=False,
                               action='store_true',
                               default=False)
    args = create_parser.parse_args(argv)

    project_loader = ProjectLoader()
    service = CreationService(project_loader)

    options = CreationOptions(
        generate_sample_code=not args.no_sample_code,
        project_name=args.project_name,
        directory=args.project_name,
        init_from_existing_sources=False,
    )
    result = new_project(service, options)

    return result
Esempio n. 8
0
def execute(argv):
    create_parser = argparse.ArgumentParser(
        prog='cpm create',
        description='Create a new cpm project',
        add_help=False)
    create_parser.add_argument('project_name')
    create_parser.add_argument('-s',
                               '--repository-url',
                               required=False,
                               action='store',
                               default='https://repo.cpmbits.com:8000')
    create_parser.add_argument('-t',
                               '--template',
                               required=False,
                               action='store')
    args = create_parser.parse_args(argv)

    project_loader = ProjectLoader()
    cpm_hub_connector = CpmHubConnectorV1(repository_url=args.repository_url)
    service = CreationService(project_loader,
                              cpm_hub_connector=cpm_hub_connector)
    template_name, template_version = __template_to_use(args.template)

    options = CreationOptions(
        project_name=args.project_name,
        directory=args.project_name,
        init_from_existing_sources=False,
        init_from_template=True if args.template else False,
        template_name=template_name,
        template_version=template_version)
    result = new_project(service, options)

    return result
Esempio n. 9
0
    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()
Esempio n. 10
0
def execute(argv):
    create_parser = argparse.ArgumentParser(
        prog='cpm init',
        description='Initialize a project from existing sources',
        add_help=False)
    create_parser.add_argument('project_name')
    args = create_parser.parse_args(argv)

    project_loader = ProjectLoader()
    service = CreationService(project_loader)

    options = CreationOptions(init_from_existing_sources=True,
                              generate_sample_code=False,
                              directory='.',
                              project_name=args.project_name)
    result = init_project(service, options)

    return result
Esempio n. 11
0
 def test_it_instantiation(self):
     project_loader = mock.MagicMock()
     CreationService(project_loader)