# Path: appointment/forms.py
# class AppointmentForm(ModelForm):
# 
#     class Meta(object):
#         model = Appointment
#         fields = ['clindate', 'clintime', 'appointment_type', 'comment',
#                   'patient']
# 
#         widgets = {
#             'clindate': DateTimePicker(options={"format": "YYYY-MM-DD"}),
#             'clintime': TimeInput(format='%H:%M')}
# 
#     def __init__(self, *args, **kwargs):
#         super(AppointmentForm, self).__init__(*args, **kwargs)
#         self.helper = FormHelper(self)
#         self.helper.add_input(Submit('submit', 'Submit'))


from django.test import TestCase
from django.utils.timezone import now
from pttrack.models import Provider, ProviderType, Patient
from datetime import time
from .forms import AppointmentForm
def apt_dict():
    apt = {'clindate': now().date(),
           'clintime': time(9, 0),
           'appointment_type': 'PSYCH_NIGHT',
           'comment': 'stuff',
           'author': Provider.objects.first(),
           'author_type': ProviderType.objects.first(),
           'patient': Patient.objects.first().id}

    return(apt)


class TestAppointmentForm(TestCase):

    fixtures = ['pttrack.json']

    def setUp(self):
        apt = apt_dict()
        self.apt = apt

        form = AppointmentForm(data=apt)
        self.assertTrue(form.is_valid(), msg=form.errors)

    # create appointment fails if Patient name is unspecified
    def test_appointment_no_patient_error(self):
        apt = self.apt.copy()
        apt['patient'] = None
        form = AppointmentForm(data=apt)
        self.assertFalse(form.is_valid(), msg=form.errors)
        del(apt['patient'])

# Path: appointment/forms.py
# class AppointmentForm(ModelForm):
# 
#     class Meta(object):
#         model = Appointment
#         fields = ['clindate', 'clintime', 'appointment_type', 'comment',
#                   'patient']
# 
#         widgets = {
#             'clindate': DateTimePicker(options={"format": "YYYY-MM-DD"}),
#             'clintime': TimeInput(format='%H:%M')}
# 
#     def __init__(self, *args, **kwargs):
#         super(AppointmentForm, self).__init__(*args, **kwargs)
#         self.helper = FormHelper(self)
#         self.helper.add_input(Submit('submit', 'Submit'))


# Path: appointment/test_forms.py
from django.test import TestCase
from django.utils.timezone import now
from pttrack.models import Provider, ProviderType, Patient
from datetime import time
from .forms import AppointmentForm

def apt_dict():
    apt = {'clindate': now().date(),
           'clintime': time(9, 0),
           'appointment_type': 'PSYCH_NIGHT',
           'comment': 'stuff',
           'author': Provider.objects.first(),
           'author_type': ProviderType.objects.first(),
           'patient': Patient.objects.first().id}

    return(apt)


class TestAppointmentForm(TestCase):

    fixtures = ['pttrack.json']

    def setUp(self):
        apt = apt_dict()
        self.apt = apt

        form = AppointmentForm(data=apt)
        self.assertTrue(form.is_valid(), msg=form.errors)

    # create appointment fails if Patient name is unspecified
    def test_appointment_no_patient_error(self):
        apt = self.apt.copy()
        apt['patient'] = None
        form = AppointmentForm(data=apt)
        self.assertFalse(form.is_valid(), msg=form.errors)
        del(apt['patient'])

        form = AppointmentForm(data=apt)