Skip to content

Commit

Permalink
refactor test for post_flag() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jer-Sch committed Sep 27, 2021
1 parent d61dcdc commit 88d21c4
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions app/grants/tests/models/test_flag.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
from unittest.mock import patch

import pytest
from dashboard.models import Profile
from dashboard.models import Activity, Profile
from grants.models.flag import Flag
from grants.models.grant import Grant
from townsquare.models import Comment

from .factories.flag_factory import FlagFactory
from .factories.profile_factory import ProfileFactory


@pytest.mark.django_db
Expand Down Expand Up @@ -66,11 +69,17 @@ def test_flag_has_tweet_attribute(self):
assert hasattr(flag, 'tweet')
assert flag.tweet == ''

def test_flag_has_a_post_flag_method(self):
"""Test post_flag method."""
def test_post_flag_method_calls_collaborators_with_appropriate_attributes(self):
"""Test post_flag() method calls filter() on Profile.objects, create() on Activity.objects, and create() on Comment.objects."""

flag = FlagFactory()

flag.post_flag()
with patch.object(Profile.objects, 'filter') as filter:
with patch.object(Activity.objects, 'create') as activity:
with patch.object(Comment.objects, 'create') as comment:

flag.post_flag()

assert Comment.objects.latest('id').comment == 'Comment from anonymous user: Test comment'
filter.assert_called_with(handle='gitcoinbot')
activity.assert_called_with(profile=filter().first(), activity_type='flagged_grant', grant=flag.grant)
comment.assert_called_with(profile=filter().first(), activity=activity(), comment=f"Comment from anonymous user: {flag.comments}")

0 comments on commit 88d21c4

Please sign in to comment.