Example #1
0
def test_get_users_from_json():
    """ Test creation of a Users collection based on a json document. """
    users = Users.from_json(file_path='{0}/json_input/basic.json'.format(
        os.path.dirname(os.path.abspath(__file__))))
    assert isinstance(users, Users)
    assert isinstance(users[0], User)
    assert isinstance(users[0].uid, int)
Example #2
0
def test_users_json_export(tmpdir):
    """ Test the exporting of a Users sequence to yaml. """
    export_file = tmpdir.mkdir("export").join("export.json")
    users = Users.from_dict(SAMPLE_DICT)
    assert users.export(file_path=export_file.strpath, export_format='json')
    exported_users = Users.from_json(export_file.strpath)
    for index, _ in enumerate(users):
        assert users[index].name == exported_users[index].name
        assert users[index].passwd == exported_users[index].passwd
        assert users[index].uid == exported_users[index].uid
        assert users[index].gid == exported_users[index].gid
        assert users[index].gecos == exported_users[index].gecos
        assert users[index].home_dir == exported_users[index].home_dir
        assert users[index].shell == exported_users[index].shell
        for pk_index, _ in enumerate(users[index].public_keys):
            assert users[index].public_keys[pk_index].raw == exported_users[index].public_keys[pk_index].raw
            assert users[index].public_keys[pk_index].b64encoded == exported_users[index].public_keys[
                pk_index].b64encoded
Example #3
0
def test_users_json_export(tmpdir):
    """ Test the exporting of a Users sequence to yaml. """
    export_file = tmpdir.mkdir("export").join("export.json")
    users = Users.from_dict(SAMPLE_DICT)
    assert users.export(file_path=export_file.strpath, export_format='json')
    exported_users = Users.from_json(export_file.strpath)
    for index, _ in enumerate(users):
        assert users[index].name == exported_users[index].name
        assert users[index].passwd == exported_users[index].passwd
        assert users[index].uid == exported_users[index].uid
        assert users[index].gid == exported_users[index].gid
        assert users[index].gecos == exported_users[index].gecos
        assert users[index].home_dir == exported_users[index].home_dir
        assert users[index].shell == exported_users[index].shell
        for pk_index, _ in enumerate(users[index].public_keys):
            assert users[index].public_keys[pk_index].raw == exported_users[
                index].public_keys[pk_index].raw
            assert users[index].public_keys[
                pk_index].b64encoded == exported_users[index].public_keys[
                    pk_index].b64encoded
Example #4
0
def test_get_users_from_invalid_json():
    """ Test a ValueError is raised if loading a json file of users with invalid syntax. """
    with pytest.raises(ValueError):
        Users.from_json(file_path='{0}/json_input/invalid.json'.format(os.path.dirname(os.path.abspath(__file__))))
Example #5
0
def test_get_users_from_json():
    """ Test creation of a Users collection based on a json document. """
    users = Users.from_json(file_path='{0}/json_input/basic.json'.format(os.path.dirname(os.path.abspath(__file__))))
    assert isinstance(users, Users)
    assert isinstance(users[0], User)
    assert isinstance(users[0].uid, int)
Example #6
0
def test_get_users_from_invalid_json():
    """ Test a ValueError is raised if loading a json file of users with invalid syntax. """
    with pytest.raises(ValueError):
        Users.from_json(file_path='{0}/json_input/invalid.json'.format(
            os.path.dirname(os.path.abspath(__file__))))