Exemplo n.º 1
0
    def test_enforce_unique_name(self, req, db_session, 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_studies import models

        study = models.Study(name='some-study',
                             title=u'Some Study',
                             short_title=u'sstudy',
                             code=u'000',
                             consent_date=date.today())

        db_session.add_all([study])
        db_session.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']
Exemplo n.º 2
0
    def test_no_params(self, req, db_session, 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_datastore import models as datastore
        from occams_studies import models

        db_session.add_all([
            datastore.Schema(name='v', title=u'V', publish_date=date.today())
        ])
        db_session.flush()

        req.GET = MultiDict()
        res = self._call_fut(models.StudyFactory(req), req)
        assert 'v' == res['schemata'][0]['name']
Exemplo n.º 3
0
    def test_term(self, req, db_session, check_csrf_token):
        """
        It should filter schemata by title or publish_date
        """
        from datetime import date
        from webob.multidict import MultiDict
        from occams_datastore import models as datastore
        from occams_studies import models

        db_session.add_all([
            datastore.Schema(name='v', title=u'V', publish_date=date.today()),
            datastore.Schema(name='xyz',
                             title=u'XYZ',
                             publish_date=date.today())
        ])
        db_session.flush()

        req.GET = MultiDict([('term', 'x')])
        res = self._call_fut(models.StudyFactory(req), req)
        assert 'xyz' == res['schemata'][0]['name']
Exemplo n.º 4
0
    def test_add(self, req, db_session, check_csrf_token):
        """
        It should be able to add a new study
        """
        from datetime import date
        from occams_studies 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 = (db_session.query(
            models.Study).filter_by(name=u'some-study').first())

        assert res is not None
Exemplo n.º 5
0
    def test_schema(self, req, db_session, 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_datastore import models as datastore
        from occams_studies import models

        today = date.today()
        tomorrow = date.today() + timedelta(days=1)

        db_session.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)
        ])
        db_session.flush()

        req.GET = MultiDict([('schema', 'v')])
        res = self._call_fut(models.StudyFactory(req), req)
        assert 2 == len(res['schemata'])