Пример #1
0
 def test_create_a_reservation_missing_key(self):
     reservation = Reservation()
     error = False
     try:
         reservation.deserialize({
                 'resource_id' : 1,
                 'user_id' : 1,
                 'start_time' : datetime.now(),
                 'end_time': datetime.now() + timedelta(minutes=30),
                 'duration': '00:30'
                 })
     except KeyError as e:
         self.assertTrue("Invalid reservation: missing" in e.message)
         error = True
     self.assertTrue(error)
Пример #2
0
 def test_create_a_reservation_wrong_value(self):
     reservation = Reservation()
     error = False
     try:
         reservation.deserialize({
                 'resource_id' : 1,
                 'resource_name' : "test_res",
                 'user_id' : "not_integer",
                 'start_time' : datetime.now(),
                 'end_time': datetime.now() + timedelta(minutes=30),
                 'duration': '00:30'
                 })
     except ValueError as e:
         self.assertTrue("body of request contained bad or no data" in e.message)
         error = True
     self.assertTrue(error)
Пример #3
0
 def add_one_reservation(self, resource_id, resource_name, user_id):
     reservation = Reservation()
     reservation.deserialize({
         'resource_id':
         resource_id,
         'resource_name':
         resource_name,
         'user_id':
         user_id,
         'start_time':
         datetime.now(),
         'end_time':
         datetime.now() + timedelta(minutes=90),
         'duration':
         '01:30'
     })
     db.session.add(reservation)
     db.session.commit()
     return reservation.id
Пример #4
0
 def test_create_a_reservation(self):
     user, resource, tag, tag_2 = self.setup_dummy_data()
     reservation = Reservation()
     # business logic in enforced in server level.
     reservation.deserialize({
             'resource_id' : resource.id,
             'resource_name' : resource.name,
             'user_id' : user.id,
             'start_time' : datetime.now(),
             'end_time': datetime.now() + timedelta(minutes=30),
             'duration': '00:30'
             })
     db.session.add(reservation)
     db.session.commit()
     user = User.query.filter_by(email="*****@*****.**").first()
     resource = [res for res in user.resources][0]
     user_res = [res for res in user.reservations][0]
     resource_res = [res for res in resource.reservations][0]
     self.assertEqual(user_res, resource_res)
     self.assertEqual(user_res.resource_id, resource.id)
     self.assertEqual(user_res.user_id, user.id)
     self.assertEqual(user_res.resource_name, resource.name)
     self.assertEqual(user_res.duration, '00:30')