Esempio n. 1
0
    def setUp(self):
        create_engine('sqlite:///:memory:?check_same_thread=False', echo=True)
        create_schema()
        time = datetime.now()
        self.timeStr = time.strftime('%Y-%m-%d %H:%M:%S')

        session = Session()
        self.appointment = Appointment(1, 'Test Appointment 1', self.timeStr,
                                       self.timeStr)
        session.add(self.appointment)
        session.commit()
class AppointmentTest(unittest.TestCase):
	def setUp(self):
		create_engine('sqlite:///:memory:?check_same_thread=False', echo=True)
		create_schema()
		time = datetime.now()
		self.timeStr = time.strftime('%Y-%m-%d %H:%M:%S')
		
		session = Session()
		self.appointment = Appointment(1, 'Test Appointment 1', self.timeStr, self.timeStr)
		session.add(self.appointment)
		session.commit()

	def testConstructor(self):
		self.assertEqual(self.appointment.tutor_id, 1)
		self.assertEqual(self.appointment.name, 'Test Appointment 1')
		self.assertEqual(self.appointment.start_time, self.timeStr)
		self.assertEqual(self.appointment.end_time, self.timeStr)

	def testToJSON(self):
		data = self.appointment.toJSON()
		self.assertEqual(data['tutor_id'], 1)
		self.assertEqual(data['name'], 'Test Appointment 1')
		self.assertEqual(data['start_time'], self.timeStr)
		self.assertEqual(data['end_time'], self.timeStr)

	def testFromJson(self):
		appointment = Appointment.FromJSON({'tutor_id': 1, 'name': 'Test Appointment 2', 'start_time': self.timeStr, 'end_time': self.timeStr})
		self.assertEqual(appointment.tutor_id, 1)
		self.assertEqual(appointment.name, 'Test Appointment 2')
		self.assertEqual(appointment.start_time, self.timeStr)
		self.assertEqual(appointment.end_time, self.timeStr)

	def testFromJsonValidationError(self):
		self.assertRaises(jsonschema.exceptions.ValidationError, Appointment.FromJSON, ({'tutor_id': 1}))
	def setUp(self):
		create_engine('sqlite:///:memory:?check_same_thread=False', echo=True)
		create_schema()
		time = datetime.now()
		self.timeStr = time.strftime('%Y-%m-%d %H:%M:%S')
		
		session = Session()
		self.appointment = Appointment(1, 'Test Appointment 1', self.timeStr, self.timeStr)
		session.add(self.appointment)
		session.commit()
Esempio n. 4
0
 def testFromJson(self):
     appointment = Appointment.FromJSON({
         'tutor_id': 1,
         'name': 'Test Appointment 2',
         'start_time': self.timeStr,
         'end_time': self.timeStr
     })
     self.assertEqual(appointment.tutor_id, 1)
     self.assertEqual(appointment.name, 'Test Appointment 2')
     self.assertEqual(appointment.start_time, self.timeStr)
     self.assertEqual(appointment.end_time, self.timeStr)
Esempio n. 5
0
class AppointmentTest(unittest.TestCase):
    def setUp(self):
        create_engine('sqlite:///:memory:?check_same_thread=False', echo=True)
        create_schema()
        time = datetime.now()
        self.timeStr = time.strftime('%Y-%m-%d %H:%M:%S')

        session = Session()
        self.appointment = Appointment(1, 'Test Appointment 1', self.timeStr,
                                       self.timeStr)
        session.add(self.appointment)
        session.commit()

    def testConstructor(self):
        self.assertEqual(self.appointment.tutor_id, 1)
        self.assertEqual(self.appointment.name, 'Test Appointment 1')
        self.assertEqual(self.appointment.start_time, self.timeStr)
        self.assertEqual(self.appointment.end_time, self.timeStr)

    def testToJSON(self):
        data = self.appointment.toJSON()
        self.assertEqual(data['tutor_id'], 1)
        self.assertEqual(data['name'], 'Test Appointment 1')
        self.assertEqual(data['start_time'], self.timeStr)
        self.assertEqual(data['end_time'], self.timeStr)

    def testFromJson(self):
        appointment = Appointment.FromJSON({
            'tutor_id': 1,
            'name': 'Test Appointment 2',
            'start_time': self.timeStr,
            'end_time': self.timeStr
        })
        self.assertEqual(appointment.tutor_id, 1)
        self.assertEqual(appointment.name, 'Test Appointment 2')
        self.assertEqual(appointment.start_time, self.timeStr)
        self.assertEqual(appointment.end_time, self.timeStr)

    def testFromJsonValidationError(self):
        self.assertRaises(jsonschema.exceptions.ValidationError,
                          Appointment.FromJSON, ({
                              'tutor_id': 1
                          }))
Esempio n. 6
0
def matches():
    if request.method == 'POST':
        teams = get_teams_db()
        match = Match(request.form['team_home'], request.form['team_away'])
        match_id = insert_match_db(match)
        stadiums = get_stadiums_db()
        stadium_id = get_stad_id_with_stad_name(request.form['stadium_name'])
        appointment = Appointment(request.form['appointment_name'], match_id, stadium_id, request.form['start_time'], request.form['end_time'], request.form['match_date'])
        if not request.form['appointment_name']:
            matchs = get_appointments_db()
            return render_template("matches.html", matchs=matchs, teams=teams, stadiums=stadiums, error="Appointment name can not be empty!")
        try:
            insert_appointments_db(appointment)
            flash("Appointment successfully created!")
            matchs = get_appointments_db()
        except psycopg2.errors.UniqueViolation:
            matchs = get_appointments_db()
            return render_template("matches.html", matchs=matchs, teams=teams, stadiums=stadiums, error="Appointment name already exists!")
        return render_template("matches.html", matchs=matchs, teams=teams, stadiums=stadiums)
    if request.method == 'GET':
        teams = get_teams_db()
        matchs = get_appointments_db()
        stadiums = get_stadiums_db()
        return render_template("matches.html", matchs=matchs, teams=teams, stadiums=stadiums)
Esempio n. 7
0
    def make_appt_and_add_appointment_to_manager(self, patient_email,
                                                 provider_email, centre_id,
                                                 date, time_slot, reason):
        try:
            date_and_time_valid(time_slot, date)
        except DateTimeValidityError as e:
            raise e

        if patient_email.lower() == provider_email.lower():
            raise BookingError(
                "Provider can't book an appointment with themselves")

        if not any(appt.provider_email == provider_email and appt.date == date
                   and appt.time_slot == time_slot
                   for appt in self._appointments):
            appointment = Appointment(self.__get_appt_id(), patient_email,
                                      provider_email, centre_id, date,
                                      time_slot, reason)
            # self._get_information(self, appointments)
            self._appointments.append(appointment)
            return appointment  # successful.
        else:
            raise BookingError(
                "Booking taken")  # Fail. Already in appointment list.
Esempio n. 8
0
 def post_appointment(self, data):
     appointment = Appointment.FromJSON(data)
     self.session.add(appointment)
     self.session.flush()
     return appointment.toJSON()