def test_react_to_post_reaction_dne_exception(user_setup): user = User.objects.get(name='user1') with pytest.raises(Exception) as e: react_to_post(user.id, post_id=1, reaction_type=ReactionType.LOL.value) print(e.value) assert 'Post does not exist' in str(e.value)
def test_given_reaction_type_exists_reaction(post_setup): u = create_user('mohan', '*****@*****.**') p = Post.objects.all()[0] with pytest.raises(Exception) as e: react_to_post(u.id, post_id=p.id, reaction_type='LAUGH') assert "Reaction does not exist" in str(e.value)
def test_react_to_post_user_cooresponding_post_same_reaction(): u1 = create_user('kmk', 'xyz.com') post = Post.objects.create(posted_by=u1, content="post1") post.reactions.create(user=u1, reaction=ReactionType.HAHA.value) react_to_post(u1.id, post.id, ReactionType.HAHA.value) reactions = Reaction.objects.all() assert len(reactions) == 0
def test_react_to_post_user_corresponding_post_change_reaction(): u1 = create_user('kmk', 'xyz.com') post = Post.objects.create(posted_by=u1, content="post1") post.reactions.create(user=u1, reaction=ReactionType.HAHA.value) react_to_post(u1.id, post.id, ReactionType.WOW.value) r = Reaction.objects.get(post=post.id) assert r.reaction == ReactionType.WOW.value
def test_react_to_post_reaction_not_corresponding_user_post_create_reaction(): u1 = create_user('kmk', 'xyz.com') post = Post.objects.create(posted_by=u1, content="post1") u2 = create_user('mohan', '*****@*****.**') with pytest.raises(Reaction.DoesNotExist): Reaction.objects.get(user=u2) react_to_post(u2.id, post_id=post.id, reaction_type=ReactionType.LOL.value) r = Reaction.objects.get(user=u2) assert r.user.name == "mohan" assert r.user.profile_pic_url == "*****@*****.**" assert r.reaction == ReactionType.LOL.value
def test_react_to_post_user_dne_exception(): with pytest.raises(Exception) as e: react_to_post(1, 1, reaction_type=ReactionType.LOL.value) assert 'User does not exist' in str(e.value)