Пример #1
0
def compose(project_descriptor):
    project = Project(project_descriptor.name,
                      version=project_descriptor.version,
                      description=project_descriptor.description,
                      descriptor=project_descriptor)
    # TODO: pass target as argument
    project.targets['default'] = compose_target('default', project_descriptor)
    compose_tests('default', project_descriptor, project)
    return project
Пример #2
0
def compose(project_descriptor, target_name):
    project = Project(
        project_descriptor.name,
        version=project_descriptor.version,
        description=project_descriptor.description,
        descriptor=project_descriptor
    )
    project.target = compose_target(target_name, project_descriptor)
    compose_tests(target_name, project_descriptor, project)
    return project
Пример #3
0
    def dtest_it_uses_image_declared_for_target(self, docker):
        project = Project('Project')
        target = Target('ubuntu')
        target.image = 'cpmhub/ubuntu'
        project.targets.append(target)
        docker_client = MagicMock()
        container = MagicMock()
        container.logs.return_value = []
        docker_client.containers.return_value = container
        docker.from_env.return_value = docker_client
        self.project_loader.load.return_value = project

        self.compilation_service.build_target('ubuntu')

        self.project_loader.load.assert_called_once()
        docker_client.containers.run.assert_called_once_with(
            f'cpmhub/ubuntu',
            'cpm build',
            working_dir=f'/{project.name}',
            volumes={
                f'{os.getcwd()}': {
                    'bind': f'/{project.name}',
                    'mode': 'rw'
                }
            },
            user=f'{os.getuid()}:{os.getgid()}',
            detach=True)
Пример #4
0
    def test_compilation_service_only_generates_compilation_recipe_when_updating(self):
        project = Project('ProjectName')
        self.project_loader.load.return_value = project

        self.compilation_service.update()

        self.project_loader.load.assert_called_once()
        self.cmakelists_builder.build.assert_called_once_with(project, 'default')
Пример #5
0
    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()
Пример #6
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)
Пример #7
0
    def test_compilation_service_generates_compilation_recipe_from_project_sources_and_compiles_project(self):
        project = Project('ProjectName')
        self.project_loader.load.return_value = project

        self.compilation_service.build()

        self.project_loader.load.assert_called_once()
        self.cmakelists_builder.build.assert_called_once_with(project, 'default')
        self.project_builder.build.assert_called_once_with(project, 'default')
Пример #8
0
    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')
Пример #9
0
    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')
Пример #10
0
    def test_bit_installation_when_bit_was_installed_before(self, filesystem):
        project_loader = mock.MagicMock()
        installer = BitInstaller(project_loader)
        bit_download = BitDownload("cest", "1.0", "Yml0IHBheWxvYWQ=")
        project_loader.load.return_value = Project("cest")
        filesystem.directory_exists.return_value = True

        installer.install(bit_download)

        filesystem.remove_directory.assert_called_once_with('bits/cest')
        filesystem.create_directory.assert_called_once_with('bits/cest')
        filesystem.unzips.assert_called_once_with(b'bit payload', 'bits/cest')
Пример #11
0
    def test_service_passes_test_args_to_run_command(self):
        project = Project('ProjectName')
        project.test.test_suites = ['test']
        self.project_loader.load.return_value = project

        self.test_service.run_tests(['tests'], 'default', test_args=['arg1'])

        self.project_loader.load.assert_called_once()
        self.cmakelists_builder.build.assert_called_once_with(project)
        self.project_commands.build_tests.assert_called_once_with(
            project, ['tests'])
        self.project_commands.run_tests.assert_called_once_with(
            project, ['tests'], ['arg1'])
Пример #12
0
    def test_service_build_and_runs_only_specified_tests(self):
        project = Project('ProjectName')
        project.test.test_suites = ['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)
        self.project_commands.build_tests.assert_called_once_with(
            project, ['tests'])
        self.project_commands.run_tests.assert_called_once_with(
            project, ['tests'], ())
Пример #13
0
    def test_service_generates_the_recipe_then_compiles_and_runs_the_tests(
            self):
        project = Project('ProjectName')
        project.test.test_suites = ['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)
        self.project_commands.build_tests.assert_called_once_with(project, [])
        self.project_commands.run_tests.assert_called_once_with(
            project, [], ())
Пример #14
0
    def dtest_it_raises_an_exception_when_docker_image_is_not_found(self, docker):
        project = Project('Project')
        target = Target('ubuntu')
        target.image = 'cpmhub/ubuntu'
        project.targets.append(target)
        docker_client = MagicMock()
        docker.errors.ImageNotFound = RuntimeError
        docker_client.images.pull.side_effect = docker.errors.ImageNotFound
        docker.from_env.return_value = docker_client
        self.project_loader.load.return_value = project

        self.assertRaises(DockerImageNotFound, self.compilation_service.build_target, 'ubuntu')

        self.project_loader.load.assert_called_once()
        docker_client.containers.run.assert_not_called()
Пример #15
0
    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(
            f'{connector.repository_url}/bits',
            data=
            '{"bit_name": "cpm-hub", "version": "0.1", "payload": "Yml0IHBheWxvYWQ=", "username": "******", "password": "******"}'
        )
Пример #16
0
    def dtest_it_uses_docker_to_build_for_the_specified_target(self, docker):
        project = Project('Project')
        self.project_loader.load.return_value = project
        docker_client = MagicMock()
        container = MagicMock()
        container.logs.return_value = []
        docker_client.containers.return_value = container
        docker.from_env.return_value = docker_client

        self.compilation_service.build_target('raspberrypi4:64')

        self.project_loader.load.assert_called_once()
        docker_client.containers.run.assert_called_once_with(
            f'cpmbits/raspberrypi4:64',
            'cpm build',
            working_dir=f'/{project.name}',
            volumes={f'{os.getcwd()}': {'bind': f'/{project.name}', 'mode': 'rw'}},
            user=f'{os.getuid()}:{os.getgid()}',
            detach=True
        )
Пример #17
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()
Пример #18
0
 def __init__(self, name):
     self.target_name = ''
     self.target = None
     self.project = Project(name)