mirror of https://codeberg.org/dribdat/dribdat.git
Test event API
This commit is contained in:
parent
757cdad8dc
commit
65676a8746
|
@ -381,7 +381,7 @@ class Event(PkModel):
|
|||
desc = self.summary or re.sub('<[^>]*>', '', self.description or '')
|
||||
d = {
|
||||
"@context": "http://schema.org",
|
||||
"@type": "Event",
|
||||
"@type": "Hackathon",
|
||||
"name": self.name,
|
||||
"url": host_url + self.url,
|
||||
"description": desc,
|
||||
|
@ -395,7 +395,7 @@ class Event(PkModel):
|
|||
"name": self.hostname, "address": self.location
|
||||
}
|
||||
if self.logo_url:
|
||||
d["logo"] = self.logo_url
|
||||
d["image"] = self.logo_url
|
||||
if self.webpage_url:
|
||||
d["mainEntityOfPage"] = self.webpage_url
|
||||
d["offers"] = {"@type": "Offer", "url": self.webpage_url}
|
||||
|
@ -835,7 +835,7 @@ class Project(PkModel):
|
|||
"name": self.name,
|
||||
"description": cleansummary,
|
||||
"dateCreated": format_date(self.created_at, '%Y-%m-%dT%H:%M'),
|
||||
"dateUpdated": format_date(self.updated_at, '%Y-%m-%dT%H:%M'),
|
||||
"dateModified": format_date(self.updated_at, '%Y-%m-%dT%H:%M'),
|
||||
"discussionUrl": self.contact_url,
|
||||
"image": self.image_url,
|
||||
"license": content_license,
|
||||
|
|
26
manage.py
26
manage.py
|
@ -44,17 +44,31 @@ def create_app(script_info=None):
|
|||
return app
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument('name', nargs=-1, required=False)
|
||||
def test(name):
|
||||
"""Run all or just a subset of tests."""
|
||||
"""Parameter: which test set to run (features, functional, ..)"""
|
||||
def testrunner(name, warnings=None):
|
||||
"""Runs the name with warnings"""
|
||||
if len(name):
|
||||
feat_test = os.path.join(TEST_PATH, "test_%s.py" % name)
|
||||
else:
|
||||
feat_test = TEST_PATH
|
||||
import subprocess
|
||||
return subprocess.call(['pytest', '-W default', feat_test])
|
||||
if warnings is None:
|
||||
return subprocess.call(['pytest', feat_test])
|
||||
return subprocess.call(['pytest', warnings, feat_test])
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument('name', nargs=-1, required=False)
|
||||
def test(name):
|
||||
"""Run all or just a subset of tests."""
|
||||
"""Parameter: which test set to run (features, functional, ..)"""
|
||||
return testrunner(name)
|
||||
|
||||
|
||||
@click.command()
|
||||
@click.argument('name', nargs=-1, required=False)
|
||||
def testwarn(name):
|
||||
"""Run all or just a subset of tests with warnings."""
|
||||
return testrunner(name, "-W default")
|
||||
|
||||
|
||||
@click.group(cls=FlaskGroup, create_app=create_app)
|
||||
|
|
|
@ -5,6 +5,7 @@ from factory.alchemy import SQLAlchemyModelFactory
|
|||
|
||||
from dribdat.database import db
|
||||
from dribdat.user.models import User, Project, Event, Activity
|
||||
from datetime import datetime, timedelta
|
||||
|
||||
|
||||
class BaseFactory(SQLAlchemyModelFactory):
|
||||
|
@ -47,6 +48,8 @@ class EventFactory(BaseFactory):
|
|||
|
||||
name = Sequence(lambda n: 'Event {0}'.format(n))
|
||||
summary = "Just a sample event"
|
||||
starts_at = datetime.utcnow()
|
||||
ends_at = datetime.utcnow() + timedelta(days=2)
|
||||
|
||||
class Meta: # noqa: D106
|
||||
model = Event
|
||||
|
|
|
@ -2,25 +2,75 @@
|
|||
"""API tests using WebTest.
|
||||
"""
|
||||
import pytest
|
||||
import json
|
||||
|
||||
from dribdat.aggregation import ProjectActivity
|
||||
from dribdat.user.models import Event
|
||||
from dribdat.public.api import *
|
||||
|
||||
from .factories import EventFactory
|
||||
from .factories import EventFactory, ProjectFactory, UserFactory
|
||||
|
||||
|
||||
@pytest.mark.usefixtures('db')
|
||||
class TestEvents:
|
||||
"""Login."""
|
||||
|
||||
def test_api_events(self):
|
||||
"""Test event API functions."""
|
||||
event = EventFactory(name="hello")
|
||||
event.save()
|
||||
|
||||
# Test basic event metadata
|
||||
jsondata = json.loads(info_current_event_json().data)
|
||||
assert "hello" == jsondata["event"]["name"]
|
||||
jsondata = json.loads(info_event_json(event.id).data)
|
||||
assert "hello" == jsondata["event"]["name"]
|
||||
|
||||
# Test Schema.org compliance
|
||||
jsondata = json.loads(info_event_hackathon_json(event.id).data)
|
||||
# TODO: use https://github.com/schemaorg/schemarama for full validation
|
||||
assert "hello" == jsondata["name"]
|
||||
assert "Hackathon" == jsondata["@type"]
|
||||
assert "http://schema.org" == jsondata["@context"]
|
||||
|
||||
|
||||
def test_get_event_data(self, testapp):
|
||||
"""Get basic event data."""
|
||||
event = Event(name="test")
|
||||
event.save()
|
||||
|
||||
# Check event in JSON format
|
||||
res = testapp.get('/api/events.json')
|
||||
assert res.status_code == 200
|
||||
assert len(res.json['events']) == 1
|
||||
assert res.json['events'][0]['name'] == "test"
|
||||
|
||||
# Test the same in CSV format
|
||||
res = testapp.get('/api/events.csv')
|
||||
assert '"test"' in res
|
||||
|
||||
|
||||
def test_get_platform_data(self):
|
||||
"""More global data types."""
|
||||
event = EventFactory(name="hello")
|
||||
user = UserFactory()
|
||||
project = ProjectFactory()
|
||||
project.user = user
|
||||
project.event = event
|
||||
project.longtext = "Smee"
|
||||
project.save()
|
||||
ProjectActivity(project, 'update', user)
|
||||
|
||||
# Test all Event data
|
||||
csvdata = project_list_all_events_csv()
|
||||
csvdata = str(csvdata.get_data())
|
||||
assert "hello" in csvdata
|
||||
|
||||
# Test Activities data
|
||||
csvdata = event_activity_csv(event.id)
|
||||
csvdata = str(csvdata.get_data())
|
||||
assert "update" in csvdata
|
||||
|
||||
# Test project Activities
|
||||
jsondata = json.loads(projects_activity_json().get_data())
|
||||
assert len(jsondata['activities']) == 1
|
||||
|
|
Loading…
Reference in New Issue