示例#1
0
    def test_one_shift_in_range_returns_none_for_other_days(self):

        user = User('*****@*****.**', 'u3', username='******', _id='u3')
        user.save_to_database()

        # USER HAS SHIFT FOT ONLY MONDAY
        start = beginning_of_week()
        end = start + timedelta(seconds=1)
        # create 1 second shift
        shift = Shift(user._id, start, end)
        shift.save_to_database()

        schedule = Schedule(user._id)

        # Monday is not None
        self.assertEqual(type(schedule.shifts[0]), type(shift))
        self.assertEqual(schedule.row[1], None)
        self.assertEqual(schedule.row[2], None)
        self.assertEqual(schedule.row[3], None)
        self.assertEqual(schedule.row[4], None)
        self.assertEqual(schedule.row[5], None)
        self.assertEqual(schedule.row[6], None)

        Database.remove('users', {'user_id': user._id})
        Database.remove('shifts', {'user_id': user._id})
示例#2
0
    def test_default_values_returns_current_weeks_shifts_even_if_none(self):
        user = User('*****@*****.**', 'u1', username='******', _id='u1')
        user.save_to_database()

        schedule = Schedule(user._id)

        self.assertEqual(len(schedule.row), 7)

        Database.remove('users', {'user_id': user._id})
示例#3
0
    def test_no_shifts_in_range_returns_none_for_each_day(self):
        user = User('*****@*****.**', 'u2', username='******', _id='u2')
        user.save_to_database()

        # USER HAS ZERO SHIFTS

        schedule = Schedule(user._id)

        self.assertEqual(schedule.row[0], None)
        self.assertEqual(schedule.row[1], None)
        self.assertEqual(schedule.row[2], None)
        self.assertEqual(schedule.row[3], None)
        self.assertEqual(schedule.row[4], None)
        self.assertEqual(schedule.row[5], None)
        self.assertEqual(schedule.row[6], None)

        Database.remove('users', {'user_id': user._id})
示例#4
0
    def test_monday_and_wednesday_day_are_shifts_rest_are_none(self):

        user = User('*****@*****.**', 'u4', username='******', _id='u4')
        user.save_to_database()

        # USER HAS SHIFT FOT ONLY MONDAY
        monday = beginning_of_week()
        wednesday = beginning_of_week(days=2)
        # create 1 second shift
        shift = Shift(user._id, monday, monday+timedelta(seconds=1))
        shift.save_to_database()
        shift = Shift(user._id, wednesday, wednesday+timedelta(seconds=1))
        shift.save_to_database()

        schedule = Schedule(user._id)

        # Monday is not None
        self.assertEqual(type(schedule.row[0]), type(shift))
        self.assertEqual(schedule.row[1], None)
        self.assertEqual(type(schedule.row[2]), type(shift))

        Database.remove('users', {'user_id': user._id})
        Database.remove('shifts', {'user_id': user._id})
 def validate_email(self, email):
     user = User.objects(email=email.data).first()
     if user is None:
         raise ValidationError(
             'There is no account with that email. You must register first.'
         )
 def validate_email(self, email):
     if email.data != current_user.email:
         user = User.objects(email=email.data).first()
         if user:
             raise ValidationError(
                 'That email is taken. Please choose a different one.')
 def validate_username(self, username):
     if username.data != current_user.username:
         user = User.objects(username=username.data).first()
         if user:
             raise ValidationError(
                 'That username is taken. Please choose a different one.')