Esempio n. 1
0
def make_role(user):
    return Role(user=user, role_id=int(RoleIds.Administrator))
Esempio n. 2
0
def make_activity_role(user, activity, role_id=RoleIds.EventLeader):
    return Role(user=user, activity_id=activity.id, role_id=int(role_id))
Esempio n. 3
0
    def test_event_validity():
        user1 = create_test_user("email1", "license1")
        user2 = create_test_user("email2", "license2")
        activity1 = create_test_activity("1")
        activity2 = create_test_activity("2")

        user1.roles.append(Role(role_id=RoleIds.EventLeader, activity_id=activity1.id))
        user2.roles.append(Role(role_id=RoleIds.EventLeader, activity_id=activity2.id))
        db.session.commit()

        event = make_event()
        # Event has no activity, not valid
        assert not event.is_valid()

        # Test leaders
        event.activity_types.append(activity1)
        assert not event.has_valid_leaders()
        event.leaders.append(user1)
        assert event.has_valid_leaders()

        event.activity_types.append(activity2)
        assert not event.has_valid_leaders()
        event.leaders.append(user2)
        assert event.has_valid_leaders()

        assert event.is_valid()

        # Test slots
        event.num_slots = 0
        event.num_online_slots = 1
        assert not event.is_valid()
        event.num_online_slots = 0
        assert event.is_valid()
        event.num_slots = -1
        assert not event.is_valid()
        event.num_slots = 0
        assert event.is_valid()

        # Test dates
        event.end = datetime.datetime.now()
        assert not event.is_valid()
        event.end = event.start
        assert event.is_valid()

        event.num_online_slots = 1
        event.registration_open_time = datetime.datetime.now()
        event.registration_close_time = datetime.datetime.now() + datetime.timedelta(
            days=1
        )

        assert event.is_registration_open_at_time(datetime.datetime.now())

        event.registration_open_time = (
            event.registration_close_time + datetime.timedelta(hours=1)
        )
        assert not event.opens_before_closes()
        assert not event.is_valid()

        event.registration_open_time = datetime.datetime.combine(
            event.end, datetime.datetime.min.time()
        ) + datetime.timedelta(days=1)
        event.registration_close_time = (
            event.registration_open_time + datetime.timedelta(hours=1)
        )
        assert event.opens_before_closes()
        assert not event.opens_before_ends()
        assert not event.is_valid()

        assert not event.is_registration_open_at_time(datetime.datetime.now())