def test_one_slot(self):
        day = arrow.get('2015-11-30')

        user = models.User(id='uuid-id', fullname='Joe', username='******', password='******')
        coach = models.Coach(id='uuid-coach', user_id=user.id)
        client = models.Client(id='uuid-client', user_id=user.id, coach_id=coach.id)
        call = models.Call(
            id='uuid',
            coach_id=coach.id,
            client_id=client.id,
            timeslot=day.replace(hour=10).datetime)
        db.session.add(client)
        db.session.add(coach)
        db.session.add(call)
        db.session.commit()

        actual = builder.schedule_for_day(day.date(), client=client)
        expected = [
            dict(hour=9, coach=None, client=None, availability="empty"),
            dict(hour=10, coach='uuid-coach', client='uuid-client', availability="past",
                 time='10:00 AM'),
            dict(hour=11, coach=None, client=None, availability="empty"),
            dict(hour=13, coach=None, client=None, availability="empty"),
            dict(hour=14, coach=None, client=None, availability="empty"),
            dict(hour=15, coach=None, client=None, availability="empty"),
            dict(hour=16, coach=None, client=None, availability="empty"),
        ]

        assert actual == expected, actual
    def test_only_one_coach_per_schedule(self):
        # a future date
        today = arrow.get(datetime.date.today())
        day = today + datetime.timedelta(days=30)

        client_1 = self.add_client(username='******')
        coach_2 = self.add_coach(username='******')
        client_2 = self.add_client(username='******', coach=coach_2)

        call_1 = models.Call.create(
            coach_id=client_1.coach.id,
            client_id=client_1.id,
            timeslot=day.replace(hour=10).datetime)
        call_2 = models.Call.create(
            coach_id=client_2.coach.id,
            client_id=client_2.id,
            timeslot=day.replace(hour=13).datetime)

        db.session.add(call_1)
        db.session.add(call_2)
        db.session.commit()

        actual = builder.schedule_for_day(day.date(), client=client_1)
        expected = [
            dict(hour=9, coach=None, client=None, availability="free"),
            dict(hour=10, coach=client_1.coach_id, client=client_1.id, availability="self",
                 time='10:00 AM'),
            dict(hour=11, coach=None, client=None, availability="free"),
            dict(hour=13, coach=None, client=None, availability="free"),
            dict(hour=14, coach=None, client=None, availability="free"),
            dict(hour=15, coach=None, client=None, availability="free"),
            dict(hour=16, coach=None, client=None, availability="free"),
        ]

        assert actual == expected, actual
    def test_empty(self):
        # future date
        today = arrow.utcnow().date()
        day = today + datetime.timedelta(days=30)
        actual = builder.schedule_for_day(day, self.add_client())
        expected = [
            dict(hour=9, coach=None, client=None, availability="free"),
            dict(hour=10, coach=None, client=None, availability="free"),
            dict(hour=11, coach=None, client=None, availability="free"),
            dict(hour=13, coach=None, client=None, availability="free"),
            dict(hour=14, coach=None, client=None, availability="free"),
            dict(hour=15, coach=None, client=None, availability="free"),
            dict(hour=16, coach=None, client=None, availability="free"),
        ]

        assert actual == expected, actual