Skip to content

Commit

Permalink
Merge branch 'master' of github.com:CuriousLearner/django-phone-verif…
Browse files Browse the repository at this point in the history
…y into kavenegar-api
  • Loading branch information
gutsytechster committed Mar 10, 2020
2 parents e4532ba + 5a1aad2 commit c59e927
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 305 deletions.
24 changes: 22 additions & 2 deletions conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,20 @@
"""

# Standard Library
import copy
import functools

import django

# Third Party Stuff
import pytest
import django
from django.conf import settings

from tests import test_settings

backends = {"twilio.TwilioBackend", "nexmo.NexmoBackend", "kavenegar.KavenegarBackend"}
sandbox_backends = {"twilio.TwilioSandboxBackend", "nexmo.NexmoSandboxBackend"}
all_backends = list(backends) + list(sandbox_backends)


class PartialMethodCaller:
def __init__(self, obj, **partial_params):
Expand Down Expand Up @@ -48,6 +54,20 @@ def json(self):
return _Client()


@pytest.fixture(params=all_backends)
def backend(request):
phone_verification_settings = copy.deepcopy(
test_settings.DJANGO_SETTINGS.get("PHONE_VERIFICATION")
)
phone_verification_settings["BACKEND"] = f"phone_verify.backends.{request.param}"
if (
request.param == "nexmo.NexmoSandboxBackend"
or request.param == "nexmo.NexmoBackend"
):
phone_verification_settings["OPTIONS"]["KEY"] = "fake"
return phone_verification_settings


def pytest_configure():
from tests import test_settings

Expand Down
13 changes: 2 additions & 11 deletions phone_verify/backends/nexmo.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


class NexmoBackend(BaseBackend):

def __init__(self, **options):
super().__init__(**options)

Expand All @@ -23,11 +22,7 @@ def __init__(self, **options):
self.client = nexmo.Client(key=self._key, secret=self._secret)

def send_sms(self, number, message):
self.client.send_message({
'from': self._from,
'to': number,
'text': message,
})
self.client.send_message({"from": self._from, "to": number, "text": message})

def send_bulk_sms(self, numbers, message):
for number in numbers:
Expand All @@ -47,11 +42,7 @@ def __init__(self, **options):
self.client = nexmo.Client(key=self._key, secret=self._secret)

def send_sms(self, number, message):
self.client.send_message({
'from': self._from,
'to': number,
'text': message,
})
self.client.send_message({"from": self._from, "to": number, "text": message})

def send_bulk_sms(self, numbers, message):
for number in numbers:
Expand Down
4 changes: 0 additions & 4 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1 @@
# -*- coding: utf-8 -*-
BACKEND_SERVICES = [
("phone_verify.backends.twilio.TwilioBackend", "twilio.rest.Client"),
('phone_verify.backends.kavenegar.KavenegarBackend', "kavenegar.KavenegarAPI")
]
Loading

0 comments on commit c59e927

Please sign in to comment.