def test_serialize_user_class_detailed(app, authed_client): user_class = UserClass.from_pk(1) data = NewJSONEncoder().default(user_class) check_dictionary( data, { 'id': 1, 'name': 'User', 'permissions': ['permissions_modify', 'users_edit_settings'], }, strict=True, )
def test_modify_secondary_user_class(app, authed_client): authed_client.put( '/user_classes/2', data=json.dumps({ 'permissions': { 'users_edit_settings': False }, 'secondary': True }), ) secondary_class = SecondaryClass.from_pk(2) assert not secondary_class.permissions user_class = UserClass.from_pk(2) assert 'users_edit_settings' in user_class.permissions
def test_create_user_class(app, authed_client): response = authed_client.post( '/user_classes', data=json.dumps({ 'name': 'user_v3', 'permissions': ['users_edit_settings', 'invites_send'], }), ) check_json_response( response, { 'id': 7, 'name': 'user_v3', 'permissions': ['users_edit_settings', 'invites_send'], }, ) user_class = UserClass.from_pk(7) assert user_class.name == 'user_v3' assert user_class.permissions == ['users_edit_settings', 'invites_send']
def test_modify_user_class(app, authed_client): response = authed_client.put( '/user_classes/1', data=json.dumps({ 'permissions': { 'users_edit_settings': False, 'invites_send': True, } }), ) check_json_response( response, { 'name': 'User', 'permissions': ['permissions_modify', 'invites_send'], }, ) user_class = UserClass.from_pk(1) assert set(user_class.permissions) == { 'permissions_modify', 'invites_send', }
def test_create_user_class_secondary(app, authed_client): response = authed_client.post( '/user_classes', data=json.dumps({ 'name': 'User', 'permissions': ['users_edit_settings', 'invites_send'], 'secondary': True, }), ) check_json_response( response, { 'id': 5, 'name': 'User', 'permissions': ['users_edit_settings', 'invites_send'], }, ) user_class = SecondaryClass.from_pk(5) assert user_class.name == 'User' assert user_class.permissions == ['users_edit_settings', 'invites_send'] assert not UserClass.from_pk(7)
def test_delete_user_class_with_user(app, authed_client): response = authed_client.delete('/user_classes/1').get_json() assert (response['response'] == 'You cannot delete a UserClass while users are assigned to it.') assert UserClass.from_pk(1)
def test_delete_user_class(app, authed_client): response = authed_client.delete('/user_classes/2').get_json() assert response['response'] == 'UserClass Power User has been deleted.' assert not UserClass.from_pk(2) assert not UserClass.from_name('Power User')
def user_class_model(self) -> 'UserClass_': from core.permissions.models import UserClass return UserClass.from_pk(self.user_class_id)
def populate(cls): UserClass.new(name='User') UserClass.new( name='Power User', permissions=['permissions_modify', 'users_edit_settings'], ) UserClass.new(name='Elite') UserClass.new(name='Torrent Masturbaiter') UserClass.new(name='Staff') UserClass.new(name='Administrator') SecondaryClass.new(name='FLS') SecondaryClass.new(name='Beans Team', permissions=['users_edit_settings']) SecondaryClass.new(name='Progressive Insurance') SecondaryClass.new(name='Jake from State Farom') db.engine.execute( # Generating password hash each time is slow, so raw SQL we go. f"""INSERT INTO users (username, passhash, email, invites, inviter_id, user_class_id) VALUES ('user_one', '{HASH_1}', '*****@*****.**', 1, NULL, 1), ('user_two', '{HASH_2}', '*****@*****.**', 0, 1, 1), ('user_three', '{HASH_3}', '*****@*****.**', 0, NULL, 1), ('user_four', '{HASH_1}', '*****@*****.**', 2, 2, 1), ('user_five', '{HASH_1}', '*****@*****.**', 1, 4, 1) """) db.engine.execute( f"""INSERT INTO api_keys (user_id, hash, keyhashsalt, revoked, permissions) VALUES (1, 'abcdefghij', '{HASHED_CODE_1}', 'f', '{{"sample_permission", "sample_2_permission", "sample_3_permission"}}'), (1, 'cdefghijkl', '{HASHED_CODE_3}', 'f', '{{}}'), (2, 'bcdefghijk', '{HASHED_CODE_3}', 'f', '{{}}'), (2, '1234567890', '{HASHED_CODE_2}', 't', '{{}}')""") db.engine.execute( f"""INSERT INTO invites (inviter_id, invitee_id, email, code, expired) VALUES (1, NULL, '*****@*****.**', '{CODE_1}', 'f'), (1, 2, '*****@*****.**', '{CODE_2}', 't'), (2, NULL, '*****@*****.**', '{CODE_3}', 'f'), (1, NULL, '*****@*****.**', '{CODE_4}', 't') """) db.session.execute(secondary_class_assoc_table.insert().values( user_id=1, secondary_class_id=1)) db.session.commit()
def test_is_valid_data(app, client, data, result): """Make sure the post-cache fetch function for valid data works.""" assert UserClass._valid_data(data) is result
def test_serialize_user_class_permless(app, client): user_class = UserClass.from_pk(1) data = NewJSONEncoder().default(user_class) check_dictionary(data, {'id': 1, 'name': 'User'})