Skip to content

Commit

Permalink
lint and test fix
Browse files Browse the repository at this point in the history
  • Loading branch information
calellowitz committed Sep 13, 2023
1 parent bad92b5 commit b4d2a20
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
8 changes: 5 additions & 3 deletions commcare_connect/opportunity/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,11 @@ def add_connect_users(user_list: list[str], opportunity_id: str):
)
data = result.json()
for user in data["found_users"]:
u, _ = User.objects.get_or_create(username=user["username"], phone_number=user["phone_number"], name=user["name"])
opportunity_access = OpportunityAccess.objects.get_or_create(user=u, opportunity_id=opportunity_id)
invite_user(user, opportunity_access)
u, _ = User.objects.get_or_create(
username=user["username"], phone_number=user["phone_number"], name=user["name"]
)
opportunity_access, _ = OpportunityAccess.objects.get_or_create(user=u, opportunity_id=opportunity_id)
invite_user(u, opportunity_access)


@celery_app.task()
Expand Down
7 changes: 5 additions & 2 deletions commcare_connect/opportunity/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ class TestConnectUserCreation:
@pytest.mark.django_db
def test_add_connect_user(self):
opportunity = OpportunityFactory()
with mock.patch("commcare_connect.opportunity.tasks.requests.get") as request:
with (
mock.patch("commcare_connect.opportunity.tasks.requests.get") as request,
mock.patch("commcare_connect.users.helpers.send_sms") as send_sms
):
request.return_value.json.return_value = {
"found_users": [
{"username": "test", "phone_number": "+15555555555", "name": "a"},
Expand All @@ -22,7 +25,7 @@ def test_add_connect_user(self):
add_connect_users(["+15555555555", "+12222222222"], opportunity.id)

user_list = User.objects.filter(username="test")
assert len(user) == 1
assert len(user_list) == 1
user = user_list[0]
assert user.name == "a"
assert user.phone_number == "+15555555555"
Expand Down
4 changes: 3 additions & 1 deletion commcare_connect/opportunity/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,6 @@ def accept_invite(request, invite_id):
return HttpResponse("This link is invalid. Please try again", status=404)
o.accepted = True
o.save()
return HttpResponse("Thank you for accepting the invitation. Open your CommCare Connect App to see more information about the opportunity and begin learning")
return HttpResponse(
"Thank you for accepting the invitation. Open your CommCare Connect App to see more information about the opportunity and begin learning"
)
2 changes: 0 additions & 2 deletions commcare_connect/users/helpers.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from uuid import uuid4

import requests
from twilio.rest import Client

from django.conf import settings

from commcare_connect.organization.models import Organization
Expand Down
3 changes: 1 addition & 2 deletions commcare_connect/users/models.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
from phonenumber_field.modelfields import PhoneNumberField

from django.contrib.auth.models import AbstractUser
from django.contrib.auth.validators import UnicodeUsernameValidator
from django.db import models
from django.db.models import Q, UniqueConstraint
from django.urls import reverse
from django.utils.translation import gettext_lazy as _
from phonenumber_field.modelfields import PhoneNumberField

from commcare_connect.users.managers import UserManager

Expand Down
9 changes: 3 additions & 6 deletions commcare_connect/utils/sms.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import twilio.rest import Client
from django.conf import settings
from twilio.rest import Client


def send_sms(to, body):
client = Client(settings.TWILIO_ACCOUNT_SID, settings.TWILIO_AUTH_TOKEN)
message = client.messages.create(
body=body,
to=to,
messaging_service_sid=settings.TWILIO_MESSAGING_SERVICE
)
client.messages.create(body=body, to=to, messaging_service_sid=settings.TWILIO_MESSAGING_SERVICE)

0 comments on commit b4d2a20

Please sign in to comment.