Example #1
0
 def setUp(self):
     self.patient = Patient.objects.all()[0]
     self.patient.save()
     self.language = self.patient.language
     self.clinic = Clinic.objects.all()[0]
     self.group = Group.objects.get(name="Temba Lethu")
     self.user = User.objects.get(username="******")
     self.user.groups.add(self.group)
     gateway.load_backend("txtalert.apps.gateway.backends.dummy")
Example #2
0
 def setUp(self):
     self.patient = Patient.objects.all()[0]
     self.patient.save()
     self.language = self.patient.language
     self.clinic = Clinic.objects.all()[0]
     self.group = Group.objects.get(name='Temba Lethu')
     self.user = User.objects.get(username='******')
     self.user.groups.add(self.group)
     gateway.load_backend('txtalert.apps.gateway.backends.dummy')
Example #3
0
    def handle(self, *args, **options):
        group_name = options.get('group')
        if not group_name:
            sys.exit('Please provide --group')

        backend, selected_gateway, sms_receipt_handler = gateway.load_backend(options['gateway'])
        today = datetime.now().date()
        reminders.all(selected_gateway, [group_name])
        reminders.send_stats(selected_gateway, [group_name], today)
Example #4
0
    def setUp(self):
        # use dummy gateway
        from txtalert.apps import gateway

        gateway.load_backend("txtalert.apps.gateway.backends.dummy")

        self.user = User.objects.get(username="******")

        self.patient = Patient.objects.all()[0]
        self.patient.save()  # save to specify the active_msisdn

        # create a number of visits for this patient at a clinic
        for i in range(0, 10):
            self.patient.visit_set.create(
                clinic=Clinic.objects.get(name="Test Clinic"), date=datetime.now() + timedelta(days=i), status="s"
            )

        self.assertTrue(self.patient.visit_set.all())
        self.assertTrue(self.patient.active_msisdn)  # make sure that actually worked
        self.assertTrue(self.patient.get_last_clinic())
        self.assertTrue(self.patient.last_clinic)
Example #5
0
    def setUp(self):
        # use dummy gateway
        from txtalert.apps import gateway
        gateway.load_backend('txtalert.apps.gateway.backends.dummy')

        self.user = User.objects.get(username="******")

        self.patient = Patient.objects.all()[0]
        self.patient.save()  # save to specify the active_msisdn

        # create a number of visits for this patient at a clinic
        for i in range(0, 10):
            self.patient.visit_set.create(
                clinic=Clinic.objects.get(name='Test Clinic'),
                date=datetime.now() + timedelta(days=i),
                status='s')

        self.assertTrue(self.patient.visit_set.all())
        self.assertTrue(
            self.patient.active_msisdn)  # make sure that actually worked
        self.assertTrue(self.patient.get_last_clinic())
        self.assertTrue(self.patient.last_clinic)
Example #6
0
    def handle(self, *args, **options):
        group_name = options.get('group')
        if not group_name:
            sys.exit('Please provide --group')

        backend, selected_gateway, sms_receipt_handler = gateway.load_backend(options['gateway'])
        date_string = options.get('date')
        if date_string:
            today = datetime.strptime(date_string, '%d/%m/%Y').date()
        else:
            today = datetime.now().date()

        clinic_name = options.get('clinic_name')

        reminders.all(selected_gateway, [group_name], today, clinic_name)
        reminders.send_stats(selected_gateway, [group_name], today)
Example #7
0
    def handle(self, *args, **options):
        group_name = options.get('group')
        if not group_name:
            sys.exit('Please provide --group')

        backend, selected_gateway, sms_receipt_handler = gateway.load_backend(
            options['gateway'])
        date_string = options.get('date')
        if date_string:
            today = datetime.strptime(date_string, '%d/%m/%Y').date()
        else:
            today = datetime.now().date()

        clinic_name = options.get('clinic_name')

        reminders.all(selected_gateway, [group_name], today, clinic_name)
        reminders.send_stats(selected_gateway, [group_name], today)
Example #8
0
    def handle(self, *args, **options):
        group_name = options.get('group')
        if not group_name:
            sys.exit('Please provide --group')

        backend, selected_gateway, sms_receipt_handler = gateway.load_backend(options['gateway'])

        # Iterate over installed apps for sender module and call it's handle method.
        for app in settings.INSTALLED_APPS:
            mod = import_module(app)
            try:
                sender = import_module('%s.sender' % app)
                sender.handle(backend, selected_gateway, sms_receipt_handler, group_name)
            except:
                # Decide whether to bubble up this error. If the app just
                # doesn't have a sender module we can ignore the error
                # attempting to import it, otherwise we want it to bubble up.
                if module_has_submodule(mod, 'sender'):
                    raise
Example #9
0
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User, Permission
from django.contrib.contenttypes.models import ContentType
from django.utils import simplejson
from django.db.models.signals import post_save
from txtalert.apps.gateway.backends.opera.utils import element_to_namedtuple, OPERA_TIMESTAMP_FORMAT
from txtalert.apps.gateway.models import SendSMS, PleaseCallMe
from txtalert.core.models import Visit, ChangeRequest, PleaseCallMe as CorePleaseCallMe

import xml.etree.ElementTree as ET
from datetime import datetime, timedelta
import base64
import iso8601
from txtalert.apps import gateway

backend, gateway, receipt_handler = gateway.load_backend("txtalert.apps.gateway.backends.dummy")


def basic_auth_string(username, password):
    """
    Encode a username and password for use in an HTTP Basic Authentication
    header
    """
    b64 = base64.encodestring("%s:%s" % (username, password)).strip()
    return "Basic %s" % b64


def add_perms_to_user(username, permission):  # perms as in permissions, not the hair
    """
    Helper function to get a user and add permissions to it
    """
Example #10
0
from django.test import TestCase
from django.contrib.auth.models import User
from django.conf import settings
from os.path import join
from txtalert.apps.cd4.utils import read_cd4_document
from txtalert.apps.cd4.models import CD4Document, CD4Record, CD4_MESSAGE_TEMPLATE
from txtalert.apps.gateway.models import SendSMS
from txtalert.apps import gateway
gateway.load_backend('txtalert.apps.gateway.backends.dummy')

class CD4TestCase(TestCase):

    fixtures = ['patients']

    def setUp(self):
        self.sample_file = join(settings.MEDIA_ROOT, settings.UPLOAD_ROOT,
                                    'sample.xls')
        self.document = read_cd4_document(self.sample_file)
        self.user = User.objects.get(username='******')

    def tearDown(self):
        pass

    def test_parsing_of_sample_excel(self):
        """
        We should be able to read the sample MS Excel document
        """
        # there should be 4 rows
        self.assertEquals(len(self.document), 4)
        for row in self.document:
            # each with 5 columns
 def handle(self, *args, **options):
     backend, selected_gateway, sms_receipt_handler = gateway.load_backend(options['gateway'])
     today = datetime.now().date()
     reminders.all(selected_gateway, ['Temba Lethu'])
     reminders.send_stats(selected_gateway, ['Temba Lethu'], today)
Example #12
0
from django.core.urlresolvers import reverse
from django.contrib.auth.models import User, Permission
from django.contrib.contenttypes.models import ContentType
from django.utils import simplejson
from django.db.models.signals import post_save
from txtalert.apps.gateway.backends.opera.utils import element_to_namedtuple, OPERA_TIMESTAMP_FORMAT
from txtalert.apps.gateway.models import SendSMS, PleaseCallMe
from txtalert.core.models import Visit, ChangeRequest, PleaseCallMe as CorePleaseCallMe

import xml.etree.ElementTree as ET
from datetime import datetime, timedelta
import base64
import iso8601
import json
from txtalert.apps import gateway
backend, gateway, receipt_handler = gateway.load_backend(
    'txtalert.apps.gateway.backends.dummy')


def basic_auth_string(username, password):
    """
    Encode a username and password for use in an HTTP Basic Authentication
    header
    """
    b64 = base64.encodestring('%s:%s' % (username, password)).strip()
    return 'Basic %s' % b64


def add_perms_to_user(username,
                      permission):  # perms as in permissions, not the hair
    """
    Helper function to get a user and add permissions to it
Example #13
0
 def test_loading_of_dummy_gateway(self):
     # load dummy
     gateway.load_backend('txtalert.apps.gateway.backends.dummy')
     # make sure it's been loaded
     self.assertTrue(isinstance(gateway.gateway, backend.Gateway))
Example #14
0
 def test_loading_of_dummy_gateway(self):
     # load dummy
     gateway.load_backend('txtalert.apps.gateway.backends.dummy')
     # make sure it's been loaded
     self.assertTrue(isinstance(gateway.gateway, backend.Gateway))