def test_enforce_unique_name(self, req, dbsession, check_csrf_token): """ It should make sure the name stays unique when adding new studies """ from datetime import date from pyramid.httpexceptions import HTTPBadRequest from occams import models study = models.Study(name='some-study', title=u'Some Study', short_title=u'sstudy', code=u'000', consent_date=date.today()) dbsession.add_all([study]) dbsession.flush() req.json_body = { 'title': u'Some Study', 'short_title': u'sfstudy', 'code': u'111', 'consent_date': str(date.today()) } with pytest.raises(HTTPBadRequest) as excinfo: self._call_fut(models.StudyFactory(None), req) assert 'Does not yield a unique URL.' in \ excinfo.value.json['errors']['title']
def test_no_params(self, req, dbsession, check_csrf_token): """ It should just return all schemata if there is not study context """ from datetime import date from webob.multidict import MultiDict from occams import models as datastore from occams import models dbsession.add_all([ datastore.Schema(name='v', title=u'V', publish_date=date.today()) ]) dbsession.flush() req.GET = MultiDict() res = self._call_fut(models.StudyFactory(req), req) assert 'v' == res['schemata'][0]['name']
def test_term(self, req, dbsession, check_csrf_token): """ It should filter schemata by title or publish_date """ from datetime import date from webob.multidict import MultiDict from occams import models as datastore from occams import models dbsession.add_all([ datastore.Schema(name='v', title=u'V', publish_date=date.today()), datastore.Schema(name='xyz', title=u'XYZ', publish_date=date.today()) ]) dbsession.flush() req.GET = MultiDict([('term', 'x')]) res = self._call_fut(models.StudyFactory(req), req) assert 'xyz' == res['schemata'][0]['name']
def test_add(self, req, dbsession, check_csrf_token): """ It should be able to add a new study """ from datetime import date from occams import models req.json_body = { 'title': u'Some study', 'short_title': u'sfstudy', 'code': u'111', 'consent_date': str(date.today()) } self._call_fut(models.StudyFactory(None), req) res = (dbsession.query( models.Study).filter_by(name=u'some-study').first()) assert res is not None
def test_schema(self, req, dbsession, check_csrf_token): """ It should just return all publish_dates for the specific "schema" """ from datetime import date, timedelta from webob.multidict import MultiDict from occams import models as datastore from occams import models today = date.today() tomorrow = date.today() + timedelta(days=1) dbsession.add_all([ datastore.Schema(name='v', title=u'V', publish_date=today), datastore.Schema(name='v', title=u'V', publish_date=tomorrow), datastore.Schema(name='x', title=u'x', publish_date=today) ]) dbsession.flush() req.GET = MultiDict([('schema', 'v')]) res = self._call_fut(models.StudyFactory(req), req) assert 2 == len(res['schemata'])