def get_policy_id(model_name="test_model", policy_name="policy_1", meta_rule_name="meta_rule1", category_prefix=""): category_helper.add_subject_category( category_prefix + "subject_category_id1", value={"name": category_prefix + "subject_category_id1", "description": "description 1"}) category_helper.add_subject_category( category_prefix + "subject_category_id2", value={"name": category_prefix + "subject_category_id2", "description": "description 1"}) category_helper.add_object_category( category_prefix + "object_category_id1", value={"name": category_prefix + "object_category_id1", "description": "description 1"}) category_helper.add_action_category( category_prefix + "action_category_id1", value={"name": category_prefix + "action_category_id1", "description": "description 1"}) meta_rule = meta_rule_helper.add_meta_rule(value=create_meta_rule(meta_rule_name, category_prefix)) meta_rule_id = list(meta_rule.keys())[0] model = model_helper.add_model(value=create_model(meta_rule_id, model_name)) model_id = list(model.keys())[0] value = create_policy(model_id, policy_name) policy = policy_helper.add_policies(value=value) assert policy policy_id = list(policy.keys())[0] return policy_id
def test_delete_action_category(db): category_id = "category_id1" value = { "name": "action_category", "description": "description action_category" } category_helper.add_action_category(category_id, value) action_category = category_helper.delete_action_category(category_id) assert not action_category
def test_add_action_categories_with_existed_name(db): name = uuid4().hex value = {"name": name, "description": "description action_category"} action_category = category_helper.add_action_category(value=value) assert action_category assert len(action_category) == 1 with pytest.raises(ActionCategoryExisting) as exception_info: category_helper.add_action_category(value=value) assert str(exception_info.value) == '409: Action Category Existing'
def test_get_action_category(db): category_id = "category_id1" value = { "name": "action_category", "description": "description action_category" } category_helper.add_action_category(category_id, value) action_category = category_helper.get_action_category(category_id) assert action_category assert len(action_category) == 1
def test_add_action_category_with_same_category_id(db): category_id = "category_id1" value = { "name": "action_category", "description": "description action_category" } category_helper.add_action_category(category_id, value) with pytest.raises(ActionCategoryExisting) as exception_info: category_helper.add_action_category(category_id, value) assert str(exception_info.value) == '409: Action Category Existing'
def update_meta_rules(client, name, metaRuleId, data=None): if not data: subject_category = category_helper.add_subject_category( value={ "name": "subject category name update" + uuid4().hex, "description": "description 1" }) subject_category_id = list(subject_category.keys())[0] object_category = category_helper.add_object_category( value={ "name": "object category name update" + uuid4().hex, "description": "description 1" }) object_category_id = list(object_category.keys())[0] action_category = category_helper.add_action_category( value={ "name": "action category name update" + uuid4().hex, "description": "description 1" }) action_category_id = list(action_category.keys())[0] data = { "name": name, "subject_categories": [subject_category_id], "object_categories": [object_category_id], "action_categories": [action_category_id] } req = client.patch("/meta_rules/{}".format(metaRuleId), data=json.dumps(data), headers={'Content-Type': 'application/json'}) meta_rules = utilities.get_json(req.data) return req, meta_rules
def test_add_action_category_with_empty_name(db): category_id = "category_id1" value = {"name": "", "description": "description action_category"} with pytest.raises(CategoryNameInvalid) as exception_info: category_helper.add_action_category(category_id, value) assert str(exception_info.value) == '400: Category Name Invalid'
def test_update_meta_rule_with_different_combination_but_same_data(): client = utilities.register_client() meta_rule_name1 = uuid4().hex subject_category = category_helper.add_subject_category( value={ "name": "subject category name" + uuid4().hex, "description": "description 1" }) subject_category_id1 = list(subject_category.keys())[0] object_category = category_helper.add_object_category( value={ "name": "object category name" + uuid4().hex, "description": "description 1" }) object_category_id1 = list(object_category.keys())[0] action_category = category_helper.add_action_category( value={ "name": "action category name" + uuid4().hex, "description": "description 1" }) action_category_id1 = list(action_category.keys())[0] subject_category = category_helper.add_subject_category( value={ "name": "subject category name" + uuid4().hex, "description": "description 1" }) subject_category_id2 = list(subject_category.keys())[0] object_category = category_helper.add_object_category( value={ "name": "object category name" + uuid4().hex, "description": "description 1" }) object_category_id2 = list(object_category.keys())[0] action_category = category_helper.add_action_category( value={ "name": "action category name" + uuid4().hex, "description": "description 1" }) action_category_id2 = list(action_category.keys())[0] data = { "name": meta_rule_name1, "subject_categories": [subject_category_id1, subject_category_id2], "object_categories": [object_category_id1, object_category_id2], "action_categories": [action_category_id1, action_category_id2] } req, meta_rules = add_meta_rules(client, meta_rule_name1, data=data) assert req.status_code == 200 meta_rule_name2 = uuid4().hex req, meta_rules = add_meta_rules(client, meta_rule_name2) meta_rule_id2 = next(iter(meta_rules['meta_rules'])) data2 = { "name": meta_rule_name2, "subject_categories": [subject_category_id1, subject_category_id2], "object_categories": [object_category_id1], "action_categories": [action_category_id1, action_category_id2] } req_update = update_meta_rules(client, name=meta_rule_name2, metaRuleId=meta_rule_id2, data=data2) assert req_update[0].status_code == 200
def test_add_two_meta_rules_with_different_combination_but_similar_items(): client = utilities.register_client() meta_rule_name1 = uuid4().hex meta_rule_name2 = uuid4().hex subject_category = category_helper.add_subject_category( value={ "name": "subject category name" + uuid4().hex, "description": "description 1" }) subject_category_id1 = list(subject_category.keys())[0] object_category = category_helper.add_object_category( value={ "name": "object category name" + uuid4().hex, "description": "description 1" }) object_category_id1 = list(object_category.keys())[0] action_category = category_helper.add_action_category( value={ "name": "action category name" + uuid4().hex, "description": "description 1" }) action_category_id1 = list(action_category.keys())[0] subject_category = category_helper.add_subject_category( value={ "name": "subject category name" + uuid4().hex, "description": "description 1" }) subject_category_id2 = list(subject_category.keys())[0] object_category = category_helper.add_object_category( value={ "name": "object category name" + uuid4().hex, "description": "description 1" }) object_category_id2 = list(object_category.keys())[0] action_category = category_helper.add_action_category( value={ "name": "action category name" + uuid4().hex, "description": "description 1" }) action_category_id2 = list(action_category.keys())[0] data = { "name": meta_rule_name1, "subject_categories": [subject_category_id1, subject_category_id2], "object_categories": [object_category_id1, object_category_id2], "action_categories": [action_category_id1, action_category_id2] } req, meta_rules = add_meta_rules(client, meta_rule_name1, data=data) assert req.status_code == 200 data = { "name": meta_rule_name2, "subject_categories": [subject_category_id2], "object_categories": [object_category_id1], "action_categories": [action_category_id2] } req, meta_rules = add_meta_rules(client, meta_rule_name1, data=data) assert req.status_code == 200