def directorcontrol_globaltagrestrictions_post_(request): tags = searchtag.parse_restricted_tags(request.params["tags"]) searchtag.edit_global_tag_restrictions(request.userid, tags) tags = searchtag.get_global_tag_restrictions(request.userid) return Response( d.webpage(request.userid, "directorcontrol/globaltagrestrictions.html", (tags, )))
def test_edit_global_tag_restrictions(monkeypatch): director_user_id = db_utils.create_user(username="******") monkeypatch.setattr(staff, 'DIRECTORS', frozenset([director_user_id])) tags = searchtag.parse_restricted_tags(", ".join(combined_tags)) searchtag.edit_global_tag_restrictions(director_user_id, tags) resultant_tags = searchtag.get_global_tag_restrictions(director_user_id) assert set(resultant_tags.keys()) == valid_tags assert set(resultant_tags.values()) == {"testdirector"}
def test_edit_global_tag_restrictions_fully_clear_entries_after_adding_items(monkeypatch): director_user_id = db_utils.create_user() monkeypatch.setattr(staff, 'DIRECTORS', frozenset([director_user_id])) tags = searchtag.parse_restricted_tags(", ".join(combined_tags)) searchtag.edit_global_tag_restrictions(director_user_id, tags) tags = set() searchtag.edit_global_tag_restrictions(director_user_id, tags) assert searchtag.get_global_tag_restrictions(director_user_id) == {}
def test_get_global_searchtag_restrictions(monkeypatch): director_user_id = db_utils.create_user(username="******") monkeypatch.setattr(staff, 'DIRECTORS', frozenset([director_user_id])) tags = searchtag.parse_restricted_tags(", ".join(combined_tags)) searchtag.edit_global_tag_restrictions(director_user_id, tags) resultant_tags = searchtag.get_global_tag_restrictions(director_user_id) assert set(resultant_tags.keys()) == valid_tags assert set(resultant_tags.values()) == {"testdirector"}
def test_edit_global_tag_restrictions_fully_clear_entries_after_adding_items(monkeypatch): director_user_id = db_utils.create_user() monkeypatch.setattr(staff, 'DIRECTORS', frozenset([director_user_id])) tags = searchtag.parse_restricted_tags(", ".join(combined_tags)) searchtag.edit_global_tag_restrictions(director_user_id, tags) tags = set() searchtag.edit_global_tag_restrictions(director_user_id, tags) assert searchtag.get_global_tag_restrictions(director_user_id) == []
def test_get_global_searchtag_restrictions(monkeypatch): director_user_id = db_utils.create_user(username="******") monkeypatch.setattr(staff, 'DIRECTORS', frozenset([director_user_id])) tags = searchtag.parse_restricted_tags(", ".join(combined_tags)) searchtag.edit_global_tag_restrictions(director_user_id, tags) resultant_tags = searchtag.get_global_tag_restrictions(director_user_id) resultant_tags_titles = [x.title for x in resultant_tags] assert resultant_tags_titles == valid_tags for user in resultant_tags: assert user.login_name == "testdirector"
def test_get_global_searchtag_restrictions_fails_for_non_directors( monkeypatch): # Setup the globally restricted tags list director_user_id = db_utils.create_user() monkeypatch.setattr(staff, 'DIRECTORS', frozenset([director_user_id])) tags = searchtag.parse_restricted_tags(", ".join(combined_tags)) searchtag.edit_global_tag_restrictions(director_user_id, tags) normal_user_id = db_utils.create_user() developer_user_id = db_utils.create_user() mod_user_id = db_utils.create_user() admin_user_id = db_utils.create_user() technical_user_id = db_utils.create_user() # Monkeypatch the staff global variables monkeypatch.setattr(staff, 'DEVELOPERS', frozenset([developer_user_id])) monkeypatch.setattr(staff, 'MODS', frozenset([mod_user_id])) monkeypatch.setattr(staff, 'ADMINS', frozenset([admin_user_id])) monkeypatch.setattr(staff, 'TECHNICAL', frozenset([technical_user_id])) with pytest.raises(WeasylError) as err: searchtag.get_global_tag_restrictions(normal_user_id) assert err.value.value == 'InsufficientPermissions' with pytest.raises(WeasylError) as err: searchtag.get_global_tag_restrictions(developer_user_id) assert err.value.value == 'InsufficientPermissions' with pytest.raises(WeasylError) as err: searchtag.get_global_tag_restrictions(mod_user_id) assert err.value.value == 'InsufficientPermissions' with pytest.raises(WeasylError) as err: searchtag.get_global_tag_restrictions(admin_user_id) assert err.value.value == 'InsufficientPermissions' with pytest.raises(WeasylError) as err: searchtag.get_global_tag_restrictions(technical_user_id) assert err.value.value == 'InsufficientPermissions'
def test_get_global_searchtag_restrictions_fails_for_non_directors(monkeypatch): # Setup the globally restricted tags list director_user_id = db_utils.create_user() monkeypatch.setattr(staff, 'DIRECTORS', frozenset([director_user_id])) tags = searchtag.parse_restricted_tags(", ".join(combined_tags)) searchtag.edit_global_tag_restrictions(director_user_id, tags) normal_user_id = db_utils.create_user() developer_user_id = db_utils.create_user() mod_user_id = db_utils.create_user() admin_user_id = db_utils.create_user() technical_user_id = db_utils.create_user() # Monkeypatch the staff global variables monkeypatch.setattr(staff, 'DEVELOPERS', frozenset([developer_user_id])) monkeypatch.setattr(staff, 'MODS', frozenset([mod_user_id])) monkeypatch.setattr(staff, 'ADMINS', frozenset([admin_user_id])) monkeypatch.setattr(staff, 'TECHNICAL', frozenset([technical_user_id])) with pytest.raises(WeasylError) as err: searchtag.get_global_tag_restrictions(normal_user_id) assert err.value.value == 'InsufficientPermissions' with pytest.raises(WeasylError) as err: searchtag.get_global_tag_restrictions(developer_user_id) assert err.value.value == 'InsufficientPermissions' with pytest.raises(WeasylError) as err: searchtag.get_global_tag_restrictions(mod_user_id) assert err.value.value == 'InsufficientPermissions' with pytest.raises(WeasylError) as err: searchtag.get_global_tag_restrictions(admin_user_id) assert err.value.value == 'InsufficientPermissions' with pytest.raises(WeasylError) as err: searchtag.get_global_tag_restrictions(technical_user_id) assert err.value.value == 'InsufficientPermissions'
def directorcontrol_globaltagrestrictions_get_(request): tags = searchtag.get_global_tag_restrictions(request.userid) return Response(d.webpage(request.userid, "directorcontrol/globaltagrestrictions.html", ( tags, ), title="Edit Global Community Tagging Restrictions"))
def directorcontrol_globaltagrestrictions_get_(request): tags = searchtag.get_global_tag_restrictions(request.userid) return Response( d.webpage(request.userid, "directorcontrol/globaltagrestrictions.html", (tags, )))