예제 #1
0
    def test_round_trip_with_delete_missing_records_ask_for_confirmation(self):
        # Load some data
        cmd = 'kinto-wizard {} --server={} --auth={}'
        load_cmd = cmd.format("load {}".format(self.file), self.server,
                              self.auth)
        sys.argv = load_cmd.split(" ")
        main()

        # Change something that could make the server to fail.
        client = Client(server_url=self.server,
                        auth=tuple(self.auth.split(':')))
        client.create_record(bucket='build-hub',
                             collection='archives',
                             id='8031d549-0a69-48dd-b240-feef94688d47',
                             data={})
        cmd = 'kinto-wizard {} --server={} -D --auth={} --delete-records'
        load_cmd = cmd.format("load {}".format(self.file), self.server,
                              self.auth)
        sys.argv = load_cmd.split(" ")

        with mockInput('yes'):
            main()

        with pytest.raises(exceptions.KintoException) as exc:
            client.get_record(bucket='build-hub',
                              collection='archives',
                              id='8031d549-0a69-48dd-b240-feef94688d47')
        assert "'Not Found'" in str(exc.value)
예제 #2
0
    def test_round_trip_with_client_wins(self):
        # Load some data
        cmd = 'kinto-wizard {} --server={} --auth={}'
        load_cmd = cmd.format("load {}".format(self.file), self.server,
                              self.auth)
        sys.argv = load_cmd.split(" ")
        main()

        # Change something that could make the server to fail.
        client = Client(server_url=self.server,
                        auth=tuple(self.auth.split(':')))
        client.update_record(bucket='build-hub',
                             collection='archives',
                             id='0831d549-0a69-48dd-b240-feef94688d47',
                             data={})
        record = client.get_record(bucket='build-hub',
                                   collection='archives',
                                   id='0831d549-0a69-48dd-b240-feef94688d47')
        assert set(record['data'].keys()) == {'id', 'last_modified'}
        cmd = 'kinto-wizard {} --server={} -D --auth={} --force'
        load_cmd = cmd.format("load {}".format(self.file), self.server,
                              self.auth)
        sys.argv = load_cmd.split(" ")
        main()
        record = client.get_record(bucket='build-hub',
                                   collection='archives',
                                   id='0831d549-0a69-48dd-b240-feef94688d47')
        assert set(record['data'].keys()) != {'id', 'last_modified'}
예제 #3
0
 def test_dry_round_trip(self):
     cmd = 'kinto-wizard {} --server={} --auth={} --dry-run'
     load_cmd = cmd.format("load {}".format(self.file), self.server,
                           self.auth)
     sys.argv = load_cmd.split(" ")
     main()
     client = Client(server_url=self.server,
                     auth=tuple(self.auth.split(':')))
     with pytest.raises(exceptions.KintoException):
         client.get_bucket(id="staging")
예제 #4
0
    def load(self, bucket=None, collection=None):
        cmd = 'kinto-wizard {} --server={} --auth={}'

        if bucket:
            cmd += ' --bucket={}'.format(bucket)

        if collection:
            cmd += ' --collection={}'.format(collection)

        load_cmd = cmd.format("load {}".format(self.file), self.server,
                              self.auth)
        sys.argv = load_cmd.split(" ")
        main()
예제 #5
0
    def test_full_dump(self):
        # Load some data
        cmd = 'kinto-wizard {} --server={} --auth={}'
        load_cmd = cmd.format("load {}".format(self.file), self.server,
                              self.auth)
        sys.argv = load_cmd.split(" ")
        main()

        cmd = 'kinto-wizard {} --server={} --auth={} --full'
        load_cmd = cmd.format("dump", self.server, self.auth)
        sys.argv = load_cmd.split(" ")
        output = io.StringIO()
        with redirect_stdout(output):
            main()
        output.flush()
        assert 'last_modified' in output.getvalue()
예제 #6
0
    def test_round_trip(self):
        cmd = 'kinto-wizard {} --server={} --auth={}'
        load_cmd = cmd.format("load {}".format(self.file), self.server,
                              self.auth)
        sys.argv = load_cmd.split(" ")
        main()

        dump_cmd = cmd.format("dump", self.server, self.auth)
        sys.argv = dump_cmd.split(" ")
        output = io.StringIO()
        with redirect_stdout(output):
            main()
        output.flush()

        # Check that identical to original file.
        generated = output.getvalue()
        assert self.original == generated
예제 #7
0
def dump(server, auth, bucket=None, collection=None):
    cmd = 'kinto-wizard {} --server={} --auth={}'
    dump_cmd = cmd.format("dump --full", server, auth)

    if bucket:
        dump_cmd += ' --bucket={}'.format(bucket)

    if collection:
        dump_cmd += ' --collection={}'.format(collection)

    sys.argv = dump_cmd.split(" ")
    output = io.StringIO()
    with redirect_stdout(output):
        main()
    output.flush()

    # Check that identical to original file.
    return output.getvalue()
예제 #8
0
    def test_round_trip(self):
        # Load some data
        cmd = 'kinto-wizard {} --server={} --auth={}'
        load_cmd = cmd.format("load {}".format(self.file), self.server,
                              self.auth)
        sys.argv = load_cmd.split(" ")
        main()

        cmd = 'kinto-wizard {} --server={} --auth={} --data --records'
        load_cmd = cmd.format("dump", self.server, self.auth)
        sys.argv = load_cmd.split(" ")
        output = io.StringIO()
        with redirect_stdout(output):
            main()
        output.flush()

        # Check that identical to original file.
        generated = output.getvalue()
        with open(self.file) as f:
            assert f.read() == generated
예제 #9
0
def load(server, auth, file, bucket=None, collection=None, extra=None):
    cmd = 'kinto-wizard {} --server={} --auth={}'

    if bucket:
        cmd += ' --bucket={}'.format(bucket)

    if collection:
        cmd += ' --collection={}'.format(collection)

    if extra:
        cmd += ' ' + extra

    load_cmd = cmd.format("load {}".format(file), server, auth)
    sys.argv = load_cmd.strip().split(" ")
    return main()
예제 #10
0
def validate(filename):
    sys.argv = ['kinto-wizard', 'validate', filename]
    return main()