Exemplo n.º 1
0
    def test_countdown_24_days(self, db):
        now = dt.datetime.now()
        event_dt = now + dt.timedelta(days=24)
        event = Event(name="test", starts_at=event_dt)
        event.save()

        assert event.starts_at == event_dt  # store as naive
        assert event.name == "test"
        assert event.countdown is not None
        assert event.countdown == event_dt.astimezone(pytz.timezone(Config.TIME_ZONE))
        assert timesince(event.countdown, until=True) == "3 weeks to go"
Exemplo n.º 2
0
    def test_countdown_10_days(self, db):
        timezone = pytz.timezone(Config.TIME_ZONE)
        now = dt.datetime.now()
        event_dt = now + dt.timedelta(days=10)
        event = Event(name="test", starts_at=event_dt)
        event.save()

        assert event.starts_at == event_dt  # store as naive
        assert event.name == "test"
        assert event.countdown is not None
        assert event.countdown == timezone.localize(event_dt)
        assert timesince(event.countdown, until=True) == "1 week to go"
Exemplo n.º 3
0
    def test_countdown_4_hours(self, db):
        now = dt.datetime.now()
        # need to add 10 seconds to avoid timesince to compute 3.9999h
        # formated to 3 by timesince
        event_dt = now + dt.timedelta(hours=4, seconds=10)
        event = Event(name="test", starts_at=event_dt)
        event.save()

        assert event.starts_at == event_dt  # store as naive
        assert event.name == "test"
        assert event.countdown is not None
        assert event.countdown == event_dt.astimezone(pytz.timezone(Config.TIME_ZONE))
        assert timesince(event.countdown, until=True) == "4 hours to go"
        
Exemplo n.º 4
0
def event_new():
    if not current_app.config['DRIBDAT_ALLOW_EVENTS']:
        if not current_user.is_admin:
            return redirect(url_for("public.event_start"))
    event = Event()
    form = NewEventForm(obj=event, next=request.args.get('next'))
    if form.validate_on_submit():
        del form.id
        form.populate_obj(event)
        event.starts_at = datetime.combine(
            form.starts_date.data, form.starts_time.data)
        event.ends_at = datetime.combine(
            form.ends_date.data, form.ends_time.data)
        # Load default event content
        event.boilerplate = EVENT_PRESET['quickstart']
        event.community_embed = EVENT_PRESET['codeofconduct']
        event.is_hidden = True
        db.session.add(event)
        db.session.commit()
        flash('A new event has been planned!', 'success')
        if not current_user.is_admin:
            flash(
                'Please contact an administrator to make changes or '
                + 'to promote this event on the home page.',
                'warning')
        cache.clear()
        return redirect(url_for("public.event", event_id=event.id))
    return render_template('public/eventnew.html', form=form)
Exemplo n.º 5
0
    def test_countdown_4_hours(self, db):
        timezone = pytz.timezone(Config.TIME_ZONE)
        now = dt.datetime.now()
        tz_now = timezone.localize(dt.datetime.utcnow())
        # need to add 10 seconds to avoid timesince to compute 3.9999h
        # formated to 3 by timesince
        event_dt = now + dt.timedelta(hours=4, seconds=10)
        event = Event(name="test", starts_at=event_dt)
        event.save()

        tz_event = timezone.localize(event_dt)
        timediff = tz_event - tz_now
        timediff_hours = timediff.total_seconds() // 3600

        assert event.starts_at == event_dt  # store as naive
        assert event.name == "test"
        assert event.countdown is not None
        assert event.countdown == tz_event
        assert timesince(event.countdown,
                         until=True) == "%d hours to go" % timediff_hours
Exemplo n.º 6
0
    def test_datapackage(self, project, testapp):
        """Create a data package."""

        event = Event(name="Test Event", summary="Just testin")
        event.save()

        role = Role(name="Test Role")
        role.save()

        user = UserFactory(username="******")
        user.roles.append(role)
        user.save()

        proj1 = Project(name="Test Project")
        proj1.event = event
        proj1.user = user
        proj1.save()

        acty1 = Activity("review", proj1.id)
        acty1.content = "Hello World!"
        acty1.save()

        dp_json = PackageEvent(event, user)
        assert dp_json.title == "Test Event"

        acty1.delete()
        proj1.delete()
        event.delete()

        assert Event.query.filter_by(name="Test Event").count() == 0

        ImportEventPackage(dp_json)
        assert Event.query.filter_by(name="Test Event").count() == 1
Exemplo n.º 7
0
    def test_user_schema(self, project, testapp):
        """Test user schema."""

        event = Event(name="Test Event", summary="Just testin")
        event.save()
        user = UserFactory(username="******")
        user.save()

        # Generate importable schema for local host
        hosturl = "https://localhost"

        # Initially just a warning message
        schema = get_schema_for_user_projects(user, hosturl)
        assert 'message' in schema

        # Join a project
        proj1 = Project(name="Test Project")
        proj1.event = event
        proj1.user = user
        proj1.save()
        ProjectActivity(proj1, "star", user)

        # Now we are a member of one project
        schema = get_schema_for_user_projects(user, hosturl)
        assert len(schema) == 1
        assert len(schema[0]["workPerformed"]) == 1

        # Create another project
        proj2 = Project(name="Another Project")
        proj2.event = event
        proj2.user = user
        proj2.save()
        ProjectActivity(proj2, "star", user)

        # Now we are a member of two projects
        schema = get_schema_for_user_projects(user, hosturl)
        assert len(schema[0]["workPerformed"]) == 2

        # Clean up
        proj1.delete()
        proj2.delete()
        event.delete()
        user.delete()
Exemplo n.º 8
0
def current_event(): return Event.current()


@blueprint.route("/dashboard/")
Exemplo n.º 9
0
def current_event():
    return Event.current()