コード例 #1
0
    def test_enable_missing_travis_setup(self, mock_check_call):
        mock_check_call.side_effect = [None, None]

        with self.assertRaises(RequiredPathDoesNotExist) as raised:
            travis.enable()

        self.assertEqual([
            'Travis project is not initialized for the current directory.',
            'Please initialize Travis project (e.g. `travis init`) with '
            'appropriate parameters.',
        ],
                         str(raised.exception).splitlines())
コード例 #2
0
    def test_enable_missing_travis_cli(self, mock_check_call):
        mock_check_call.side_effect = [FileNotFoundError()]

        with self.assertRaises(RequiredCommandNotFound) as raised:
            travis.enable()

        self.assertEqual([
            'Travis CLI (`travis`) is not available.',
            'Please install it before trying this command again:', '',
            '    $ sudo apt install ruby-dev ruby-ffi libffi-dev',
            '    $ sudo gem install travis'
        ],
                         str(raised.exception).splitlines())
コード例 #3
0
    def test_enable_missing_git(self, mock_check_call):
        mock_check_call.side_effect = [None, FileNotFoundError()]

        with self.assertRaises(RequiredCommandNotFound) as raised:
            travis.enable()

        self.assertEqual([
            'Git (`git`) is not available, this tool cannot verify its '
            'prerequisites.',
            'Please install it before trying this command again:',
            '',
            '    $ sudo apt install git',
        ],
                         str(raised.exception).splitlines())
コード例 #4
0
    def test_enable_broken_travis_cli(self, mock_check_call):
        mock_check_call.side_effect = [
            subprocess.CalledProcessError(1, 'test')
        ]

        with self.assertRaises(RequiredCommandFailure) as raised:
            travis.enable()

        self.assertEqual([
            'Travis CLI (`travis version`) is not functional.',
            'Make sure it works correctly in your system before trying this '
            'command again.',
        ],
                         str(raised.exception).splitlines())
コード例 #5
0
    def test_enable_broken_git_repo(self, mock_check_call):
        mock_check_call.side_effect = [
            None, subprocess.CalledProcessError(1, 'test')
        ]

        with self.assertRaises(RequiredCommandFailure) as raised:
            travis.enable()

        self.assertEqual([
            'The current directory is not a Git repository.',
            'Please switch to the desired project repository where '
            'Travis should be enabled.',
        ],
                         str(raised.exception).splitlines())
コード例 #6
0
    def test_enable_successfully(self, mock_get_account_information,
                                 mock_login, mock_getpass, mock_input,
                                 mock_check_call, mock_check_output):
        mock_input.side_effect = ['*****@*****.**', '123456']
        mock_getpass.return_value = 'secret'
        mock_login.side_effect = [
            storeapi.errors.StoreTwoFactorAuthenticationRequired(), None
        ]
        mock_get_account_information.return_value = {'account_id': 'abcd'}

        mock_check_call.side_effect = [None, None]
        mock_check_output.side_effect = [None]
        self.make_snapcraft_yaml(test_snapcraft_yaml)
        self.make_travis_yml('after_success: ["<travis-cli-decrypt>"]')

        travis.enable()

        # Attenuated credentials requested from the Store.
        mock_login.assert_called_with('*****@*****.**',
                                      'secret',
                                      one_time_password='******',
                                      acls=None,
                                      save=False,
                                      channels=['edge'],
                                      packages=[{
                                          'series': '16',
                                          'name': 'foo'
                                      }],
                                      config_fd=None)

        # Credentials encrypted with travis CLI.
        mock_check_output.assert_called_with([
            'travis', 'encrypt-file', '--force', '--add', 'after_success',
            '--decrypt-to', travis.LOCAL_CONFIG_FILENAME, mock.ANY,
            travis.ENCRYPTED_CONFIG_FILENAME
        ],
                                             stderr=subprocess.PIPE)

        # '.travis.yml' updated for snap CI.
        with open('.travis.yml') as fd:
            travis_conf = yaml.load(fd)
            self.assertThat(travis_conf['sudo'], Equals('required'))
            self.assertThat(travis_conf['services'], Equals(['docker']))
            self.assertThat(travis_conf['after_success'],
                            Equals([
                                '<travis-cli-decrypt>',
                            ]))
            self.assertThat(
                travis_conf['deploy'],
                Equals({
                    'skip_cleanup':
                    True,
                    'provider':
                    'script',
                    'script':
                    ('docker run -v $(pwd):$(pwd) -t snapcore/snapcraft '
                     'sh -c "apt update -qq && '
                     'cd $(pwd) && '
                     'snapcraft && snapcraft push *.snap --release edge"'),
                    'on': {
                        'branch': 'master',
                    },
                }))

        # Descriptive logging ...
        self.assertThat(self.fake_logger.output,
                        Contains(
                            dedent("""\
                Enabling Travis testbeds to push and release 'foo' snaps to edge channel in series '16'
                Acquiring specific authorization information ...
                Encrypting authorization for Travis and adjusting project to automatically decrypt and use it during "after_success".
                Configuring "deploy" phase to build and release the snap in the Store.
                Done. Now you just have to review and commit changes in your Travis project (`.travis.yml`).
                Also make sure you add the new `.snapcraft/travis_snapcraft.cfg` file.
            """)))  # noqa TODO this type of test should not be done
コード例 #7
0
    def test_enable_successfully(
        self,
        mock_get_account_information,
        mock_login,
        mock_getpass,
        mock_input,
        mock_check_call,
        mock_check_output,
    ):
        mock_input.side_effect = ["*****@*****.**", "123456"]
        mock_getpass.return_value = "secret"
        mock_login.side_effect = [
            storeapi.errors.StoreTwoFactorAuthenticationRequired(),
            None,
        ]
        mock_get_account_information.return_value = {"account_id": "abcd"}

        mock_check_call.side_effect = [None, None]
        mock_check_output.side_effect = [None]
        snapcraft_yaml_file_path = self.make_snapcraft_yaml(test_snapcraft_yaml)
        project = Project(snapcraft_yaml_file_path=snapcraft_yaml_file_path)
        self.make_travis_yml('after_success: ["<travis-cli-decrypt>"]')

        travis.enable(project)

        # Attenuated credentials requested from the Store.
        mock_login.assert_called_with(
            "*****@*****.**",
            "secret",
            one_time_password="******",
            save=False,
            acls=["package_access", "package_push", "package_release"],
            channels=["edge"],
            packages=[{"series": "16", "name": "foo"}],
            expires=None,
            config_fd=None,
        )

        # Credentials encrypted with travis CLI.
        mock_check_output.assert_called_with(
            [
                "travis",
                "encrypt-file",
                "--force",
                "--add",
                "after_success",
                "--decrypt-to",
                travis.LOCAL_CONFIG_FILENAME,
                mock.ANY,
                travis.ENCRYPTED_CONFIG_FILENAME,
            ],
            stderr=subprocess.PIPE,
        )

        # '.travis.yml' updated for snap CI.
        with open(".travis.yml") as fd:
            travis_conf = yaml_utils.load(fd)
            self.assertThat(travis_conf["sudo"], Equals("required"))
            self.assertThat(travis_conf["services"], Equals(["docker"]))
            self.assertThat(
                travis_conf["after_success"], Equals(["<travis-cli-decrypt>"])
            )
            self.assertThat(
                travis_conf["deploy"],
                Equals(
                    {
                        "skip_cleanup": True,
                        "provider": "script",
                        "script": (
                            "docker run -v $(pwd):$(pwd) -t snapcore/snapcraft "
                            'sh -c "apt update -qq && '
                            "cd $(pwd) && "
                            'snapcraft && snapcraft push *.snap --release edge"'
                        ),
                        "on": {"branch": "master"},
                    }
                ),
            )

        # Descriptive logging ...
        self.assertThat(
            self.fake_logger.output,
            Contains(
                dedent(
                    """\
                Enabling Travis testbeds to push and release 'foo' snaps to edge channel in series '16'
                Acquiring specific authorization information ...
                """
                )
            ),
        )
        self.assertThat(
            self.fake_logger.output,
            Contains(
                dedent(
                    """\
                Encrypting authorization for Travis and adjusting project to automatically decrypt and use it during "after_success".
                Configuring "deploy" phase to build and release the snap in the Store.
                Done. Now you just have to review and commit changes in your Travis project (`.travis.yml`).
                Also make sure you add the new `.snapcraft/travis_snapcraft.cfg` file.
            """
                )
            ),
        )  # noqa TODO this type of test should not be done
コード例 #8
0
ファイル: test_travis.py プロジェクト: 3v1n0/snapcraft
    def test_enable_successfully(
            self, mock_get_account_information, mock_login, mock_getpass,
            mock_input, mock_check_call, mock_check_output):
        mock_input.side_effect = ['*****@*****.**', '123456']
        mock_getpass.return_value = 'secret'
        mock_login.side_effect = [
            storeapi.errors.StoreTwoFactorAuthenticationRequired(), None]
        mock_get_account_information.return_value = {'account_id': 'abcd'}

        mock_check_call.side_effect = [None, None]
        mock_check_output.side_effect = [None]
        self.make_snapcraft_yaml(test_snapcraft_yaml)
        self.make_travis_yml('after_success: ["<travis-cli-decrypt>"]')

        travis.enable()

        # Attenuated credentials requested from the Store.
        mock_login.assert_called_with(
            '*****@*****.**', 'secret',
            one_time_password='******', acls=None, save=False,
            channels=['edge'], packages=[{'series': '16', 'name': 'foo'}])

        # Credentials encrypted with travis CLI.
        mock_check_output.assert_called_with(
            ['travis', 'encrypt-file', '--force',
             '--add', 'after_success', '--decrypt-to',
             travis.LOCAL_CONFIG_FILENAME,
             mock.ANY, travis.ENCRYPTED_CONFIG_FILENAME],
            stderr=subprocess.PIPE)

        # '.travis.yml' updated for snap CI.
        with open('.travis.yml') as fd:
            travis_conf = yaml.load(fd)
            self.assertEqual('required', travis_conf['sudo'])
            self.assertEqual(['docker'], travis_conf['services'])
            self.assertEqual([
                '<travis-cli-decrypt>',
            ], travis_conf['after_success'])
            self.assertEqual({
                'skip_cleanup': True,
                'provider': 'script',
                'script': (
                    'docker run -v $(pwd):$(pwd) -t ubuntu:xenial sh -c '
                    '"apt update -qq && apt install snapcraft -y && '
                    'cd $(pwd) && '
                    'snapcraft && snapcraft push *.snap --release edge"'),
                'on': {
                    'branch': 'master',
                },
            }, travis_conf['deploy'])

        # Descriptive logging ...
        self.assertEqual([
            "Enabling Travis testbeds to push and release 'foo' snaps "
            "to edge channel in series '16'",
            'Acquiring specific authorization information ...',
            'Login successful.',
            'Encrypting authorization for Travis and adjusting project '
            'to automatically decrypt and use it during "after_success".',
            'Configuring "deploy" phase to build and release the snap in '
            'the Store.',
            'Done. Now you just have to review and commit changes in your '
            'Travis project (`.travis.yml`).',
            'Also make sure you add the new '
            '`.snapcraft/travis_snapcraft.cfg` file.',
        ], self.fake_logger.output.splitlines()[1:])
コード例 #9
0
ファイル: test_travis.py プロジェクト: mvo5/snapcraft
    def test_enable_successfully(
        self,
        mock_get_account_information,
        mock_login,
        mock_getpass,
        mock_input,
        mock_check_call,
        mock_check_output,
    ):
        mock_input.side_effect = ["*****@*****.**", "123456"]
        mock_getpass.return_value = "secret"
        mock_login.side_effect = [
            storeapi.errors.StoreTwoFactorAuthenticationRequired(),
            None,
        ]
        mock_get_account_information.return_value = {"account_id": "abcd"}

        mock_check_call.side_effect = [None, None]
        mock_check_output.side_effect = [None]
        snapcraft_yaml_file_path = self.make_snapcraft_yaml(test_snapcraft_yaml)
        project = Project(snapcraft_yaml_file_path=snapcraft_yaml_file_path)
        self.make_travis_yml('after_success: ["<travis-cli-decrypt>"]')

        travis.enable(project)

        # Attenuated credentials requested from the Store.
        mock_login.assert_called_with(
            "*****@*****.**",
            "secret",
            one_time_password="******",
            save=False,
            acls=["package_access", "package_push", "package_release"],
            channels=["edge"],
            packages=[{"series": "16", "name": "foo"}],
            expires=None,
            config_fd=None,
        )

        # Credentials encrypted with travis CLI.
        mock_check_output.assert_called_with(
            [
                "travis",
                "encrypt-file",
                "--force",
                "--add",
                "after_success",
                "--decrypt-to",
                travis.LOCAL_CONFIG_FILENAME,
                mock.ANY,
                travis.ENCRYPTED_CONFIG_FILENAME,
            ],
            stderr=subprocess.PIPE,
        )

        # '.travis.yml' updated for snap CI.
        with open(".travis.yml") as fd:
            travis_conf = yaml.load(fd)
            self.assertThat(travis_conf["sudo"], Equals("required"))
            self.assertThat(travis_conf["services"], Equals(["docker"]))
            self.assertThat(
                travis_conf["after_success"], Equals(["<travis-cli-decrypt>"])
            )
            self.assertThat(
                travis_conf["deploy"],
                Equals(
                    {
                        "skip_cleanup": True,
                        "provider": "script",
                        "script": (
                            "docker run -v $(pwd):$(pwd) -t snapcore/snapcraft "
                            'sh -c "apt update -qq && '
                            "cd $(pwd) && "
                            'snapcraft && snapcraft push *.snap --release edge"'
                        ),
                        "on": {"branch": "master"},
                    }
                ),
            )

        # Descriptive logging ...
        self.assertThat(
            self.fake_logger.output,
            Contains(
                dedent(
                    """\
                Enabling Travis testbeds to push and release 'foo' snaps to edge channel in series '16'
                Acquiring specific authorization information ...
                Encrypting authorization for Travis and adjusting project to automatically decrypt and use it during "after_success".
                Configuring "deploy" phase to build and release the snap in the Store.
                Done. Now you just have to review and commit changes in your Travis project (`.travis.yml`).
                Also make sure you add the new `.snapcraft/travis_snapcraft.cfg` file.
            """
                )
            ),
        )  # noqa TODO this type of test should not be done