class TestWorkout(unittest.TestCase): def setUp(self): self.date = datetime.date(2020, 12, 16) self.time = datetime.time(6, 15) self.workout_1 = Workout("Just Skate", "freestyle", self.date, self.time, 3) def test_workout_has_name(self): self.assertEqual("Just Skate", self.workout_1.name) def test_workout_has_category(self): self.assertEqual("freestyle", self.workout_1.category) def test_workout_has_no_members_booked(self): self.assertEqual(0, self.workout_1.booked) def test_workout_has_capacity(self): self.assertEqual(3, self.workout_1.capacity) # Date and time tests def test_workout_has_date(self): self.assertEqual(self.date, self.workout_1.date) def test_workout_has_start_time(self): self.assertEqual(self.time, self.workout_1.start_time) def test_date_time__returns_date_and_time(self): self.assertEqual("2020-12-16 06:15:00", self.workout_1.date_time()) def test_check_upcoming__returns_true(self): self.assertEqual(True, self.workout_1.check_upcoming()) def test_check_upcoming__returns_false(self): self.workout_1.date = datetime.date(2020, 12, 13) self.assertEqual(False, self.workout_1.check_upcoming()) # Capacity tests def test_increment_booked__returns_1(self): self.workout_1.increment_booked() self.assertEqual(1, self.workout_1.booked) def test_decrease_booked__returns_0(self): self.workout_1.increment_booked() self.workout_1.decrease_booked() self.assertEqual(0, self.workout_1.booked) def test_check_capacity__returns_true(self): self.assertEqual(True, self.workout_1.check_capacity()) def test_check_capacity__returns_false(self): self.workout_1.increment_booked() self.workout_1.increment_booked() self.workout_1.increment_booked() self.assertEqual(False, self.workout_1.check_capacity())
workout_repository.delete_all() # booking_repository.delete_all() member_1 = Member("Dario", "Cologna", "male", 34) member_repository.save(member_1) member_2 = Member("Guido", "Van Rossum", "male", 64) member_repository.save(member_2) workout_1 = Workout("Just Skate", "freestyle", datetime.date(2020, 12, 16), datetime.time(6, 15), 2) workout_repository.save(workout_1) workout_2 = Workout("Double Poling", "classic", datetime.date(2020, 12, 10), datetime.time(10, 30), 3) workout_repository.save(workout_2) booking_1 = Booking(member_1, workout_1) booking_repository.save(booking_1) workout_1.increment_booked() workout_repository.update(workout_1) # booking_2 = Booking(member_1, workout_2) # booking_repository.save(booking_2) # booking_3 = Booking(member_2, workout_1) # booking_repository.save(booking_3) # id = booking_1.id # booking = booking_repository.select(id) # workout_id = booking.workout.id # workout = workout_repository.select(workout_id) # # Decrease booked in workout # workout.decrease_booked() # workout_repository.update(workout) # # Delete booking # booking_repository.delete(id)