示例#1
0
def test_delete_models(db):
    subject_category_id, object_category_id, action_category_id, meta_rule_id1 = mock_data.create_new_meta_rule(
        subject_category_name="subject_category6",
        object_category_name="object_category6",
        action_category_name="action_category6",
        meta_rule_name="meta_rule_6")
    model_value1 = {
        "name": "MLS",
        "description": "test",
        "meta_rules": [meta_rule_id1]
    }
    model1 = model_helper.add_model(value=model_value1)
    subject_category_id, object_category_id, action_category_id, meta_rule_id2 = mock_data.create_new_meta_rule(
        subject_category_name="subject_category7",
        object_category_name="object_category7",
        action_category_name="action_category7",
        meta_rule_name="meta_rule_7")
    model_value2 = {
        "name": "rbac",
        "description": "test",
        "meta_rules": [meta_rule_id2]
    }
    model_helper.add_model(value=model_value2)

    id = list(model1)[0]
    model_helper.delete_models(id)
    # assert
    models = model_helper.get_models()
    assert id not in models
    model_helper.delete_all_models()
示例#2
0
def test_update_model(db):
    subject_category_id, object_category_id, action_category_id, meta_rule_id1 = mock_data.create_new_meta_rule(
        subject_category_name="subject_category8",
        object_category_name="object_category8",
        action_category_name="action_category8",
        meta_rule_name="meta_rule_8")
    # prepare
    model_value = {
        "name": "MLS",
        "description": "test",
        "meta_rules": [meta_rule_id1]
    }
    model = model_helper.add_model(value=model_value)
    model_id = list(model)[0]
    subject_category_id, object_category_id, action_category_id, meta_rule_id2 = mock_data.create_new_meta_rule(
        subject_category_name="subject_category9",
        object_category_name="object_category9",
        action_category_name="action_category9",
        meta_rule_name="meta_rule_9")
    new_model_value = {
        "name": "MLS2",
        "description": "test",
        "meta_rules": [meta_rule_id2]
    }
    # act
    model_helper.update_model(model_id=model_id, value=new_model_value)
    # assert
    model = model_helper.get_models(model_id)

    for key in ("name", "meta_rules", "description"):
        assert key in model[model_id]
        assert model[model_id][key] == new_model_value[key]
    model_helper.delete_all_models()
示例#3
0
def test_get_specific_model(db):
    # prepare
    model_helper.add_model(model_id="mls_model_id")
    # act
    models = model_helper.get_models(model_id="mls_model_id")
    # assert
    assert isinstance(models, dict)
    assert models  # assert model is not empty
    assert len(models) is 1
    model_helper.delete_all_models()
示例#4
0
def test_get_models_empty(db):
    # act
    models = model_helper.get_models()
    # assert
    assert isinstance(models, dict)
    assert not models