예제 #1
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
예제 #2
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"
예제 #3
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"
예제 #4
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"
        
예제 #5
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()
예제 #6
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