예제 #1
0
    def test_no_changes(self, get_input, config_file):
        fake_stream = utils.FakeInputStream(["", "", "", "", ""])
        get_input.side_effect = fake_stream

        args = argparse.Namespace(target="foo")
        config = {
            "targets": {
                "foo": {
                    "local_folder": "/home/mark/documents",
                    "s3_uri": "s3://buckets/mybackup",
                    "aws_access_key_id": "23123123123313",
                    "aws_secret_access_key": "edwdadwadwadwdd",
                    "region_name": "eu-west-1",
                }
            }
        }
        command = EditCommand(args, config, utils.create_logger())
        command.run()

        with open(config_file, "r") as fp:
            config = json.load(fp)

        expected_config = {
            "targets": {
                "foo": {
                    "local_folder": "/home/mark/documents",
                    "s3_uri": "s3://buckets/mybackup",
                    "aws_access_key_id": "23123123123313",
                    "aws_secret_access_key": "edwdadwadwadwdd",
                    "region_name": "eu-west-1",
                }
            }
        }
        assert expected_config == config
예제 #2
0
    def test_correct_behaviour(self, get_input, config_file):
        fake_stream = utils.FakeInputStream([
            "/home/user/Documents",
            "s3://mybucket/Documents",
            "eu-west-2",
            "aaaaaaaaaaaaaaaaaaaaaaaa",
            "bbbbbbbbbbbbbbbbbbbbbbbb",
            "",
        ])
        get_input.side_effect = fake_stream
        args = argparse.Namespace(copy_target_credentials=None)

        command = AddCommand(args, {"targets": {}}, utils.create_logger())
        command.run()

        with open(config_file, "r") as fp:
            new_config = json.load(fp)

        expected_config = {
            "targets": {
                "Documents": {
                    "local_folder": "/home/user/Documents",
                    "s3_uri": "s3://mybucket/Documents",
                    "aws_access_key_id": "aaaaaaaaaaaaaaaaaaaaaaaa",
                    "aws_secret_access_key": "bbbbbbbbbbbbbbbbbbbbbbbb",
                    "region_name": "eu-west-2",
                }
            }
        }
        assert new_config == expected_config
예제 #3
0
    def test_custom_target_name(self, get_input, config_file):
        fake_stream = utils.FakeInputStream([
            "/home/user/Music",
            "s3://mybucket/Musiccccc",
            "us-west-1",
            "1234567890",
            "abcdefghij",
            "Tunes",
        ])
        get_input.side_effect = fake_stream
        args = argparse.Namespace(copy_target_credentials=None)

        command = AddCommand(args, {"targets": {}}, utils.create_logger())
        command.run()

        with open(config_file, "r") as fp:
            new_config = json.load(fp)

        expected_config = {
            "targets": {
                "Tunes": {
                    "local_folder": "/home/user/Music",
                    "s3_uri": "s3://mybucket/Musiccccc",
                    "aws_access_key_id": "1234567890",
                    "aws_secret_access_key": "abcdefghij",
                    "region_name": "us-west-1",
                }
            }
        }
        assert new_config == expected_config
예제 #4
0
    def test_copy_target_credentials_bad_target(self, get_input, capsys):
        fake_stream = utils.FakeInputStream(
            ["/home/user/Animals", "s3://mybucket/Zoo", "us-west-2", "Beasts"])
        get_input.side_effect = fake_stream
        args = argparse.Namespace(copy_target_credentials="Foo")

        command = AddCommand(args, {"targets": {
            "bar": {}
        }}, utils.create_logger())
        command.run()

        out, err = capsys.readouterr()
        assert out == ""
        assert err == ('"Foo" is an unknown target\n' "Choices are: ['bar']\n")
예제 #5
0
    def test_correct_output(self, get_input, config_file):
        fake_stream = utils.FakeInputStream([
            '/home/user/Documents',
            's3://buckets/mybackup222',
            '9999999999',
            'bbbbbbbbbbbbbbbbbbbbbbbb',
            'eu-west-2',
        ])
        get_input.side_effect = fake_stream

        args = argparse.Namespace(target='foo')
        config = {
            'targets': {
                'foo': {
                    'local_folder': '/home/mark/documents',
                    's3_uri': 's3://buckets/mybackup',
                    'aws_access_key_id': '23123123123313',
                    'aws_secret_access_key': 'edwdadwadwadwdd',
                    'region_name': 'eu-west-1',
                }
            }
        }
        command = EditCommand(args, config, utils.create_logger())
        command.run()

        with open(config_file, 'r') as fp:
            config = json.load(fp)

        expected_config = {
            'targets': {
                'foo': {
                    'local_folder': '/home/user/Documents',
                    's3_uri': 's3://buckets/mybackup222',
                    'aws_access_key_id': '9999999999',
                    'aws_secret_access_key': 'bbbbbbbbbbbbbbbbbbbbbbbb',
                    'region_name': 'eu-west-2',
                }
            }
        }
        assert expected_config == config
예제 #6
0
    def test_copy_target_credentials(self, get_input, config_file):
        fake_stream = utils.FakeInputStream(
            ["/home/user/Animals", "s3://mybucket/Zoo", "us-west-2", "Beasts"])
        get_input.side_effect = fake_stream
        args = argparse.Namespace(copy_target_credentials="bar")

        command = AddCommand(
            args,
            {
                "targets": {
                    "bar": {
                        "aws_secret_access_key": "bar-secretz",
                        "aws_access_key_id": "so-much-bar",
                    }
                }
            },
            utils.create_logger(),
        )
        command.run()

        with open(config_file, "r") as fp:
            new_config = json.load(fp)

        expected_config = {
            "targets": {
                "bar": {
                    "aws_access_key_id": "so-much-bar",
                    "aws_secret_access_key": "bar-secretz",
                },
                "Beasts": {
                    "local_folder": "/home/user/Animals",
                    "s3_uri": "s3://mybucket/Zoo",
                    "aws_access_key_id": "so-much-bar",
                    "aws_secret_access_key": "bar-secretz",
                    "region_name": "us-west-2",
                },
            }
        }
        assert new_config == expected_config