Esempio n. 1
0
def test_schema_validation_error(tmpdir):
    tmpdir = str(tmpdir)
    with pytest.raises(jsonschema.ValidationError) as ex:
        commit.apply(os.path.join(test_path, 'applytest1-exception'),
                'node', tmpdir, {}, None)

    assert ex.value.cause is None # make sure it was a validation error
    assert ex.value.validator_value == 'integer'
Esempio n. 2
0
def test_schema_validation_error(tmpdir):
    tmpdir = str(tmpdir)
    with pytest.raises(jsonschema.ValidationError) as ex:
        commit.apply(os.path.join(test_path, 'applytest1-exception'), 'node',
                     tmpdir, {}, None)

    assert ex.value.cause is None  # make sure it was a validation error
    assert ex.value.validator_value == 'integer'
Esempio n. 3
0
def test_apply(tmpdir, source_dir, dest_dir, do_commit, do_copy):
    tmpdir = str(tmpdir)

    commit_tmp = os.path.join(tmpdir, 'tmp')
    makedirsp(commit_tmp)

    apply_dir = os.path.join(tmpdir, 'apply')
    # apply_dir must not yet exist
    shutil.copytree(os.path.join(test_path, source_dir), apply_dir)

    # Write out config
    state_tmp = os.path.join(tmpdir,'state')
    makedirsp(state_tmp)
    config_dir = os.path.join(apply_dir, 'config', 'dev')
    makedirsp(config_dir)

    config = {
        'version':'0.0.1',
        'config':{
            'state1':os.path.join(state_tmp,'one'),
            'state2':os.path.join(state_tmp,'two'),
            'dbhostname':'example.com'
        },
        'base_dir':os.path.join(tmpdir,'basedir')
    }

    with open(os.path.join(config_dir, 'api.json'), 'w') as cfile:
        cfile.write(json.dumps(config))

    previous_dir = None
    if do_copy:
        previous_dir = os.path.join(tmpdir, 'previous', 'example', 'path')
        makedirsp(previous_dir)
        with open(os.path.join(previous_dir, 'test.txt'), 'w') as copy_file:
            copy_file.write('You did it!\n')

    results = commit.apply(apply_dir, 'node', commit_tmp, {}, previous_dir)

    assert len(results) == 1
    assert are_dir_trees_equal(results['api']['dir'],
            os.path.join(test_path, dest_dir))

    checkfile(config['config']['state1'], '55')
    checkfile(config['config']['state2'], '0')

    if do_commit:
        makedirsp(results['api']['base_dir'])
        commit.commit(results)
Esempio n. 4
0
def test_apply(tmpdir, source_dir, dest_dir, do_commit, do_copy):
    tmpdir = str(tmpdir)

    commit_tmp = os.path.join(tmpdir, 'tmp')
    makedirsp(commit_tmp)

    apply_dir = os.path.join(tmpdir, 'apply')
    # apply_dir must not yet exist
    shutil.copytree(os.path.join(test_path, source_dir), apply_dir)

    # Write out config
    state_tmp = os.path.join(tmpdir, 'state')
    makedirsp(state_tmp)
    config_dir = os.path.join(apply_dir, 'config', 'dev')
    makedirsp(config_dir)

    config = {
        'version': '0.0.1',
        'config': {
            'state1': os.path.join(state_tmp, 'one'),
            'state2': os.path.join(state_tmp, 'two'),
            'dbhostname': 'example.com'
        },
        'base_dir': os.path.join(tmpdir, 'basedir')
    }

    with open(os.path.join(config_dir, 'api.json'), 'w') as cfile:
        cfile.write(json.dumps(config))

    previous_dir = None
    if do_copy:
        previous_dir = os.path.join(tmpdir, 'previous', 'example', 'path')
        makedirsp(previous_dir)
        with open(os.path.join(previous_dir, 'test.txt'), 'w') as copy_file:
            copy_file.write('You did it!\n')

    results = commit.apply(apply_dir, 'node', commit_tmp, {}, previous_dir)

    assert len(results) == 1
    assert are_dir_trees_equal(results['api']['dir'],
                               os.path.join(test_path, dest_dir))

    checkfile(config['config']['state1'], '55')
    checkfile(config['config']['state2'], '0')

    if do_commit:
        makedirsp(results['api']['base_dir'])
        commit.commit(results)