예제 #1
0
    def test_refresh_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.refresh()

        # 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 only with the decrypt command.
        with open('.travis.yml') as fd:
            travis_conf = yaml.load(fd)
            self.assertThat(travis_conf['after_success'],
                            Equals([
                                '<travis-cli-decrypt>',
                            ]))

        # Descriptive logging ...
        self.assertThat(
            self.fake_logger.output.splitlines()[1:],
            Equals([
                'Refreshing credentials 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".',
                'Done. Please commit the changes to '
                '`.snapcraft/travis_snapcraft.cfg` file.',
            ]))
예제 #2
0
    def test_refresh_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.refresh()

        # 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 only with the decrypt command.
        with open('.travis.yml') as fd:
            travis_conf = yaml.load(fd)
            self.assertThat(
                travis_conf['after_success'],
                Equals([
                    '<travis-cli-decrypt>',
                ]))

        # Descriptive logging ...
        self.assertThat(
            self.fake_logger.output.splitlines()[1:],
            Equals([
                'Refreshing credentials 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".',
                'Done. Please commit the changes to '
                '`.snapcraft/travis_snapcraft.cfg` file.',
            ]))
예제 #3
0
    def test_refresh_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.refresh(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 only with the decrypt command.
        with open(".travis.yml") as fd:
            travis_conf = yaml_utils.load(fd)
            self.assertThat(
                travis_conf["after_success"], Equals(["<travis-cli-decrypt>"])
            )

        # Descriptive logging ...
        self.assertThat(
            self.fake_logger.output,
            Contains(
                dedent(
                    """\
                Refreshing credentials 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".
                Done. Please commit the changes to `.snapcraft/travis_snapcraft.cfg` file.
                """
                )
            ),
        )  # noqa TODO this type of test should not be done
예제 #4
0
    def test_refresh_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.refresh(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 only with the decrypt command.
        with open(".travis.yml") as fd:
            travis_conf = yaml.load(fd)
            self.assertThat(
                travis_conf["after_success"], Equals(["<travis-cli-decrypt>"])
            )

        # Descriptive logging ...
        self.assertThat(
            self.fake_logger.output,
            Contains(
                dedent(
                    """\
                Refreshing credentials 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".
                Done. Please commit the changes to `.snapcraft/travis_snapcraft.cfg` file.
            """
                )
            ),
        )  # noqa TODO this type of test should not be done