# Path: sendinel/settings.py
# DEBUG = True        #for scheduling set to false
# TEMPLATE_DEBUG = DEBUG
# PROJECT_PATH = dirname(abspath(__file__))
# LOGGING_LEVEL = logging.INFO
# LOGGING_LEVEL_TEST = logging.CRITICAL
# ADMINS = (
# )
# MANAGERS = ADMINS
# DATABASE_ENGINE = 'sqlite3'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
# DATABASE_NAME = PROJECT_PATH + '/sendinel.db'             # Or path to database file if using sqlite3.
# DATABASE_USER = ''             # Not used with sqlite3.
# DATABASE_PASSWORD = ''         # Not used with sqlite3.
# DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
# DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
# TIME_ZONE = 'Europe/Berlin'
# LANGUAGE_CODE = 'en-us'
# SITE_ID = 1
# USE_I18N = True
# MEDIA_ROOT = PROJECT_PATH + '/media'
# MEDIA_URL = '/mediaweb/'
# ADMIN_MEDIA_PREFIX = '/admin_media/'
# SECRET_KEY = '4ztf1p=e9d*ns^d*f@bs3mu#37p)$jp(%lzo2a+-%j8^=eq852'
# TEMPLATE_LOADERS = (
#     'django.template.loaders.filesystem.load_template_source',
#     'django.template.loaders.app_directories.load_template_source',
# #     'django.template.loaders.eggs.load_template_source',
# )
# TEMPLATE_CONTEXT_PROCESSORS = ("django.core.context_processors.auth",
#     "django.core.context_processors.debug",
#     "django.core.context_processors.i18n",
#     "django.core.context_processors.media",
#     "django.contrib.messages.context_processors.messages")
# MIDDLEWARE_CLASSES = (
#     'django.middleware.common.CommonMiddleware',
#     'django.contrib.sessions.middleware.SessionMiddleware',
#     'django.middleware.locale.LocaleMiddleware',
#     'django.contrib.auth.middleware.AuthenticationMiddleware',
#     'django.contrib.csrf.middleware.CsrfMiddleware'
# )
# ROOT_URLCONF = 'sendinel.urls'
# TEMPLATE_DIRS = (
#     PROJECT_PATH + "/templates",
#     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
#     # Always use forward slashes, even on Windows.
#     # Don't forget to use absolute paths, not relative paths.
# )
# INSTALLED_APPS = (
#     'django.contrib.admin',
#     'django.contrib.auth',
#     'django.contrib.contenttypes',
#     'django.contrib.sessions',
#     'django.contrib.sites',
#     'sendinel',
#     'sendinel.web',
#     'sendinel.backend',
#     'sendinel.groups',
#     'sendinel.infoservices',
#     'sendinel.notifications',
#     'sendinel.medicines'
# )
# REMINDER_TIME_BEFORE_APPOINTMENT = timedelta(days = 1)
# DEFAULT_APPOINTMENT_DURATION = timedelta(minutes = 60)
# DEFAULT_HOSPITAL_NAME = 'your hospital'
# DEFAULT_SEND_TIME = '12:00' #hh:mm in 24-hours format
# COUNTRY_CODE_PHONE = "0049" #"0027" for South Africa
# START_MOBILE_PHONE = "0" # "0" for South Africa (07/08..), "01" for Germany
# ASTERISK_USER = "sendinel"
# ASTERISK_GROUP = "sendinel"
# ASTERISK_SPOOL_DIR = "/var/spool/asterisk/outgoing/"
# ASTERISK_DONE_SPOOL_DIR = "/var/spool/asterisk/outgoing_done/"
# ASTERISK_RETRY = 5
# ASTERISK_RETRY_TIME = 5
# ASTERISK_DATACARD = True 
# ASTERISK_EXTENSION = "s"
# ASTERISK_SIP_ACCOUNT = "datacard0"
# SERIALPORTSMS = '/dev/rfcomm0'
# FESTIVAL_CACHE = "/tmp"
# AUTH_NUMBER = "CHANGE ME"
# AUTHENTICATION_CALL_TIMEOUT = timedelta(minutes = 3)
# AUTHENTICATION_ENABLED = False
# BLUETOOTH_ENABLED = True
# SMS_SALUTATION = ''
# CALL_SALUTATION = "This is an automated call from your clinic"
# MEDICINE_MESSAGE_TEMPLATE = "Your medicine is now available " + \
#                             "at the $hospital. Please come and pick it up."
# VCAL_UID_SLUG = 'sendinel.org'
# 
# Path: sendinel/backend/models.py
# class Hospital(models.Model):
#     """
#     Represent a Hospital.
#     """
#     
#     name = models.CharField(max_length = 255)
#     current_hospital = models.BooleanField(default=True)
#     
#     def __unicode__(self):
#         return self.name
#     
#     @classmethod
#     def get_current_hospital(cls):
#         """
#         Return the standard current hospital
#         """
#         
#         try:
#             hospital = Hospital.objects.get(current_hospital = True)
#         except Hospital.DoesNotExist:
#             hospital = Hospital(name = DEFAULT_HOSPITAL_NAME, \
#             current_hospital = True)
#             hospital.save() 
#         return hospital    


from datetime import datetime
from django.test import TestCase
from django.db import IntegrityError
from sendinel import settings
from sendinel.backend.models import Hospital






class HospitalTest(TestCase):
    fixtures = ['backend_test']
    
    def test_get_hospital_no_hospital(self):
        Hospital.objects.all().delete()
        hospital = Hospital.get_current_hospital()
        self.assertTrue(1, Hospital.objects.all().count())
        self.assertEquals(Hospital.objects.all()[0].name, settings.DEFAULT_HOSPITAL_NAME)
        self.assertEquals(hospital.name, settings.DEFAULT_HOSPITAL_NAME)
    
    def test_get_hospital_with_hospital(self):

# Path: sendinel/settings.py
# DEBUG = True        #for scheduling set to false
# TEMPLATE_DEBUG = DEBUG
# PROJECT_PATH = dirname(abspath(__file__))
# LOGGING_LEVEL = logging.INFO
# LOGGING_LEVEL_TEST = logging.CRITICAL
# ADMINS = (
# )
# MANAGERS = ADMINS
# DATABASE_ENGINE = 'sqlite3'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
# DATABASE_NAME = PROJECT_PATH + '/sendinel.db'             # Or path to database file if using sqlite3.
# DATABASE_USER = ''             # Not used with sqlite3.
# DATABASE_PASSWORD = ''         # Not used with sqlite3.
# DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
# DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
# TIME_ZONE = 'Europe/Berlin'
# LANGUAGE_CODE = 'en-us'
# SITE_ID = 1
# USE_I18N = True
# MEDIA_ROOT = PROJECT_PATH + '/media'
# MEDIA_URL = '/mediaweb/'
# ADMIN_MEDIA_PREFIX = '/admin_media/'
# SECRET_KEY = '4ztf1p=e9d*ns^d*f@bs3mu#37p)$jp(%lzo2a+-%j8^=eq852'
# TEMPLATE_LOADERS = (
#     'django.template.loaders.filesystem.load_template_source',
#     'django.template.loaders.app_directories.load_template_source',
# #     'django.template.loaders.eggs.load_template_source',
# )
# TEMPLATE_CONTEXT_PROCESSORS = ("django.core.context_processors.auth",
#     "django.core.context_processors.debug",
#     "django.core.context_processors.i18n",
#     "django.core.context_processors.media",
#     "django.contrib.messages.context_processors.messages")
# MIDDLEWARE_CLASSES = (
#     'django.middleware.common.CommonMiddleware',
#     'django.contrib.sessions.middleware.SessionMiddleware',
#     'django.middleware.locale.LocaleMiddleware',
#     'django.contrib.auth.middleware.AuthenticationMiddleware',
#     'django.contrib.csrf.middleware.CsrfMiddleware'
# )
# ROOT_URLCONF = 'sendinel.urls'
# TEMPLATE_DIRS = (
#     PROJECT_PATH + "/templates",
#     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
#     # Always use forward slashes, even on Windows.
#     # Don't forget to use absolute paths, not relative paths.
# )
# INSTALLED_APPS = (
#     'django.contrib.admin',
#     'django.contrib.auth',
#     'django.contrib.contenttypes',
#     'django.contrib.sessions',
#     'django.contrib.sites',
#     'sendinel',
#     'sendinel.web',
#     'sendinel.backend',
#     'sendinel.groups',
#     'sendinel.infoservices',
#     'sendinel.notifications',
#     'sendinel.medicines'
# )
# REMINDER_TIME_BEFORE_APPOINTMENT = timedelta(days = 1)
# DEFAULT_APPOINTMENT_DURATION = timedelta(minutes = 60)
# DEFAULT_HOSPITAL_NAME = 'your hospital'
# DEFAULT_SEND_TIME = '12:00' #hh:mm in 24-hours format
# COUNTRY_CODE_PHONE = "0049" #"0027" for South Africa
# START_MOBILE_PHONE = "0" # "0" for South Africa (07/08..), "01" for Germany
# ASTERISK_USER = "sendinel"
# ASTERISK_GROUP = "sendinel"
# ASTERISK_SPOOL_DIR = "/var/spool/asterisk/outgoing/"
# ASTERISK_DONE_SPOOL_DIR = "/var/spool/asterisk/outgoing_done/"
# ASTERISK_RETRY = 5
# ASTERISK_RETRY_TIME = 5
# ASTERISK_DATACARD = True 
# ASTERISK_EXTENSION = "s"
# ASTERISK_SIP_ACCOUNT = "datacard0"
# SERIALPORTSMS = '/dev/rfcomm0'
# FESTIVAL_CACHE = "/tmp"
# AUTH_NUMBER = "CHANGE ME"
# AUTHENTICATION_CALL_TIMEOUT = timedelta(minutes = 3)
# AUTHENTICATION_ENABLED = False
# BLUETOOTH_ENABLED = True
# SMS_SALUTATION = ''
# CALL_SALUTATION = "This is an automated call from your clinic"
# MEDICINE_MESSAGE_TEMPLATE = "Your medicine is now available " + \
#                             "at the $hospital. Please come and pick it up."
# VCAL_UID_SLUG = 'sendinel.org'
# 
# Path: sendinel/backend/models.py
# class Hospital(models.Model):
#     """
#     Represent a Hospital.
#     """
#     
#     name = models.CharField(max_length = 255)
#     current_hospital = models.BooleanField(default=True)
#     
#     def __unicode__(self):
#         return self.name
#     
#     @classmethod
#     def get_current_hospital(cls):
#         """
#         Return the standard current hospital
#         """
#         
#         try:
#             hospital = Hospital.objects.get(current_hospital = True)
#         except Hospital.DoesNotExist:
#             hospital = Hospital(name = DEFAULT_HOSPITAL_NAME, \
#             current_hospital = True)
#             hospital.save() 
#         return hospital    


# Path: sendinel/backend/tests/models_test.py
from datetime import datetime
from django.test import TestCase
from django.db import IntegrityError
from sendinel import settings
from sendinel.backend.models import Hospital







class HospitalTest(TestCase):
    fixtures = ['backend_test']
    
    def test_get_hospital_no_hospital(self):
        Hospital.objects.all().delete()
        hospital = Hospital.get_current_hospital()
        self.assertTrue(1, Hospital.objects.all().count())
        self.assertEquals(Hospital.objects.all()[0].name, settings.DEFAULT_HOSPITAL_NAME)
        self.assertEquals(hospital.name, settings.DEFAULT_HOSPITAL_NAME)
    
    def test_get_hospital_with_hospital(self):

        hospital = Hospital.objects.get(current_hospital = True)