Exemplo n.º 1
0
    def test_bake_reminder(self, several_users, client, mocker):
        upcoming_date = datetime.date.today() + datetime.timedelta(days=3)
        clubsessions.create(date=upcoming_date)

        reminders.send_email = mocker.stub()
        email_spy = mocker.spy(reminders, "send_bake_reminder_email")

        token = TestingConfig.ADMIN_KEY
        response = client.get(f"/api/bakereminder/{token}")

        assert "1" in str(response.data)
        email_spy.assert_called_once()
        reminders.send_email.assert_called_once()
Exemplo n.º 2
0
    def test_create_next_session(self):
        first_session = clubsessions.create(auto_assign=False)
        next_session = clubsessions.create_next_session(auto_assign=False)

        period_between = next_session.date - first_session.date

        assert period_between == datetime.timedelta(days=7)
Exemplo n.º 3
0
    def test_delete_session(self):
        new_session = clubsessions.create(auto_assign=False)
        session_id = new_session.session_id

        clubsessions.delete(session_id)

        assert clubsessions.get_by_id(session_id) is None
Exemplo n.º 4
0
    def test_join_all_future_sessions(self):
        today = datetime.date.today()
        past = today - datetime.timedelta(days=7)
        future = today + datetime.timedelta(days=7)

        today_session = clubsessions.create(date=today, auto_assign=False)
        past_session = clubsessions.create(date=past, auto_assign=False)
        future_session = clubsessions.create(date=future, auto_assign=False)

        user_dict = dict(username="******",
                         email="*****@*****.**")
        new_user = user_module.create(user_dict, "password")

        clubsessions.join_all_future_sessions(new_user)

        assert new_user not in past_session.participants.all()
        assert new_user in today_session.participants.all()
        assert new_user in future_session.participants.all()
Exemplo n.º 5
0
def create_session(data):
    date = None
    if "date" in data:
        date = datetime.datetime.strptime(data["date"], "%Y-%m-%d").date()
    if date is not None and date < datetime.date.today():
        raise InvalidDateError

    new_session = clubsessions.create(date=date)
    broadcast_session_update()
Exemplo n.º 6
0
 def test_session(self):
     return clubsessions.create(auto_assign=False)
Exemplo n.º 7
0
    def test_create(self):
        new_session = clubsessions.create(auto_assign=False)

        assert new_session.date == datetime.date.today()
        assert new_session.max_bakers == 2
Exemplo n.º 8
0
    def test_create_next_session_without_future_session(self):
        past = datetime.date.today() - datetime.timedelta(days=1)
        past_session = clubsessions.create(date=past, auto_assign=False)

        with pytest.raises(clubsessions.NoLastSessionError):
            clubsessions.create_next_session(auto_assign=False)
Exemplo n.º 9
0
    def test_create_adds_users_as_participants(self, several_users):
        new_session = clubsessions.create()
        participants = new_session.participants.all()

        assert several_users[0] in participants
        assert len(participants) == len(several_users)
Exemplo n.º 10
0
 def test_create_autoassign_insufficient_bakers(self):
     with pytest.raises(clubsessions.InsufficientBakersError):
         new_session = clubsessions.create()
Exemplo n.º 11
0
    def test_create_autoassign(self, several_users):
        new_session = clubsessions.create()

        assert len(new_session.bakers.all()) == new_session.max_bakers
        assert new_session.needs_bakers() is False
Exemplo n.º 12
0
    def test_create_at_date(self):
        date = datetime.datetime.strptime("2020-02-01", "%Y-%m-%d").date()
        new_session = clubsessions.create(date=date, auto_assign=False)

        assert new_session.date == date