Skip to content

Commit

Permalink
(OperationCode#47) Test for pushing changes in mil status to pybot.
Browse files Browse the repository at this point in the history
Tests that when an update is made to mil status or slack id the status is
pushed to pybot.

Doesn't push to pybot when those fields don't change or when only one
is present.
  • Loading branch information
brownnrl committed Oct 3, 2019
1 parent e45dbd3 commit 330e26f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
1 change: 0 additions & 1 deletion src/core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ def send_slack_invite_job(email: str) -> None:
a newly registered user
:param email: Email the user signed up with
:param military_status: Status that the user indicated in their profile
"""
try:
logger.info(f"Sending slack invite for email: {email}")
Expand Down
3 changes: 2 additions & 1 deletion src/tests/fixtures.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,5 +83,6 @@ def update_profile_params(request):
@pytest.fixture(params=factory.build_batch(dict, 5, FACTORY_CLASS=f.ProfileFactory))
def random_profile_dict(request):
profile = request.param
profile.pop("user")
if "user" in profile:
del profile["user"]
return request.param
33 changes: 30 additions & 3 deletions src/tests/integration/test_profile_updates.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import humps
import pytest
import requests
from django import test
from django.contrib.auth.models import User
from django.conf import settings
from django.urls import reverse
from pytest_mock import MockFixture

from ..unit.test_tasks import run_next_task

def test_update_profile_random_params(
authed_client: test.Client, user: User, random_profile_dict
Expand Down Expand Up @@ -38,10 +42,15 @@ def test_update_profile_frontend_params(


def test_update_profile_random_params_update_task_to_pybot(
authed_client: test.Client, user: User, random_profile_dict
authed_client: test.Client,
user: User,
random_profile_dict,
mocker: MockFixture,
):
random_profile_dict['military_status'] = 'current'
random_profile_dict['slack_id'] = 'slack1234'
mil_status = 'current'
slack_id = 'slack1234'
random_profile_dict['military_status'] = mil_status
random_profile_dict['slack_id'] = slack_id
res = authed_client.patch(
reverse("update_profile"), humps.camelize(random_profile_dict)
)
Expand All @@ -54,6 +63,24 @@ def test_update_profile_random_params_update_task_to_pybot(
for key, val in random_profile_dict.items():
assert getattr(profile, key) == val

mock = mocker.patch.object(requests, "post")
run_next_task()
assert mock.called
assert mock.call_args[0] == (f"{settings.PYBOT_URL}/pybot/api/v1/slack/update",)
assert "slack_id" in mock.call_args[1]["json"]
assert "military_status" in mock.call_args[1]["json"]
assert mock.call_args[1]["json"]["slack_id"] == slack_id
assert mock.call_args[1]["json"]["military_status"] == mil_status

# Try again not changing slack id or mil status
mock.reset_mock()
random_profile_dict['address_2'] = 'something else'
res = authed_client.patch(
reverse("update_profile"), humps.camelize(random_profile_dict)
)
run_next_task()
assert not mock.called

@pytest.mark.parametrize(
argnames="method, status", argvalues=[("post", 405), ("get", 200), ("patch", 200)]
)
Expand Down

0 comments on commit 330e26f

Please sign in to comment.