def test_revert_add_user_tags(session, user, sticker_set, tags): """Test that reverting the tags of a user works.""" ban_user = user_factory(session, 3, 'testuser2') for sticker in sticker_set.stickers: # Create a new tag for each sticker tag_sticker(session, f'tag-banned-{sticker.file_id}', sticker, ban_user) session.commit() # Revert the changes of malicious user revert_user_changes(session, ban_user) # Ensure that the mallicious user's tags have been removed and the old tags are in place for sticker in sticker_set.stickers: assert len(sticker.tags) == 1 assert sticker.tags[0].name == f'tag-{sticker.file_id}' for change in ban_user.changes: assert change.reverted # Undo the revert undo_user_changes_revert(session, ban_user) # Ensure that the mallicious user's tags have been removed and the old tags are in place for sticker in sticker_set.stickers: assert_sticker_contains_tags(sticker, [f'tag-{sticker.file_id}', f'tag-banned-{sticker.file_id}']) for change in ban_user.changes: assert not change.reverted
def test_add_tags(session, user, sticker_set): """Add new tags to a sticker.""" for sticker in sticker_set.stickers: # Create a new tag for each sticker tag_sticker(session, f"tag-{sticker.file_id}", sticker, user) session.commit() # Ensure that the mallicious user actually replaced the tag for sticker in sticker_set.stickers: assert sticker.tags[0].name == f"tag-{sticker.file_id}" # User got a new change assert len(user.changes) == len(sticker_set.stickers) for sticker in sticker_set.stickers: # Create a new tag for each sticker tag_sticker(session, f"tag-2-{sticker.file_id}", sticker, user) session.commit() # Ensure that the mallicious user actually replaced the tag for sticker in sticker_set.stickers: assert_sticker_contains_tags( sticker, [f"tag-{sticker.file_id}", f"tag-2-{sticker.file_id}"]) assert len(user.changes) == len(sticker_set.stickers) * 2
def test_original_emoji_stays_on_replace(session, user, sticker_set): """Original emojis will remain if tags are added in replace mode.""" sticker = sticker_set.stickers[0] # Add an original emoji tag to the sticker tag = Tag('😲', False, True) sticker.tags.append(tag) sticker.original_emojis.append(tag) session.commit() # Now tag the sticker in replace mode tag_sticker(session, 'new-tag', sticker, user, replace=True) assert_sticker_contains_tags(sticker, ['new-tag', '😲']) assert len(sticker.tags) == 2 assert sticker.original_emojis[0] in sticker.tags