def test_show(self):
        """Tests that GET /syntacticcategories/id returns the syntactic category with id=id or an appropriate error."""

        # Create an syntactic category to show.
        params = json.dumps({'name': u'name', 'type': u'lexical', 'description': u'description'})
        response = self.app.post(url('syntacticcategories'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        syntactic_category_id = resp['id']

        # Try to get a syntactic_category using an invalid id
        id = 100000000000
        response = self.app.get(url('syntacticcategory', id=id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin,
            status=404)
        resp = json.loads(response.body)
        assert u'There is no syntactic category with id %s' % id in json.loads(response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('syntacticcategory', id=''), status=404,
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == 'The resource could not be found.'
        assert response.content_type == 'application/json'

        # Valid id
        response = self.app.get(url('syntacticcategory', id=syntactic_category_id), headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['name'] == u'name'
        assert resp['description'] == u'description'
        assert response.content_type == 'application/json'
    def test_new(self):
        """Tests that GET /applicationsettings/new returns an appropriate JSON object for creating a new application settings object.

        The properties of the JSON object are 'languages', 'users' and
        'orthographies' and their values are arrays/lists.
        """

        # Add some orthographies.
        orthography1 = h.generate_default_orthography1()
        orthography2 = h.generate_default_orthography2()
        Session.add_all([orthography1, orthography2])
        Session.commit()

        # Get the data currently in the db (see websetup.py for the test data).
        data = {
            'languages': h.get_languages(),
            'users': h.get_mini_dicts_getter('User')(),
            'orthographies': h.get_mini_dicts_getter('Orthography')()
        }

        # JSON.stringify and then re-Python-ify the data.  This is what the data
        # should look like in the response to a simulated GET request.
        data = json.loads(json.dumps(data, cls=h.JSONOLDEncoder))

        # GET /applicationsettings/new without params.  Expect a JSON array for
        # every store.
        response = self.app.get(url('new_applicationsetting'),
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert response.content_type == 'application/json'
        assert resp['languages'] == data['languages']
        assert resp['users'] == data['users']
        assert resp['orthographies'] == data['orthographies']
        assert response.content_type == 'application/json'

        # GET /applicationsettings/new with params.  Param values are treated as
        # strings, not JSON.  If any params are specified, the default is to
        # return a JSON array corresponding to store for the param.  There are
        # three cases that will result in an empty JSON array being returned:
        # 1. the param is not specified
        # 2. the value of the specified param is an empty string
        # 3. the value of the specified param is an ISO 8601 UTC datetime
        #    string that matches the most recent datetime_modified value of the
        #    store in question.
        params = {
            # Value is empty string: 'languages' will not be in response.
            'languages': '',
            # Value is any string: 'users' will be in response.
            'users': 'anything can go here!',
            # Value is ISO 8601 UTC datetime string that does not match the most
            # recent Orthography.datetime_modified value: 'orthographies' *will*
            # be in the response.
            'orthographies': datetime.datetime.utcnow().isoformat(),
        }
        response = self.app.get(url('new_applicationsetting'), params,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['languages'] == []
        assert resp['users'] == data['users']
        assert resp['orthographies'] == data['orthographies']
Beispiel #3
0
    def test_authenticate(self):
        """Tests that POST /login/authenticate correctly handles authentication attempts."""

        # Invalid username & password
        params = json.dumps({'username': '******', 'password': '******'})
        response = self.app.post(url(controller='login', action='authenticate'),
                                params, self.json_headers, status=401)
        resp = json.loads(response.body)
        assert resp['error'] == u'The username and password provided are not valid.'
        assert response.content_type == 'application/json'

        # Valid username & password
        params = json.dumps({'username': '******', 'password': '******'})
        response = self.app.post(url(controller='login', action='authenticate'),
                                params, self.json_headers)
        resp = json.loads(response.body)
        assert resp['authenticated'] == True
        assert response.content_type == 'application/json'

        # Invalid POST params
        params = json.dumps({'usernamex': 'admin', 'password': '******'})
        response = self.app.post(url(controller='login', action='authenticate'),
                                params, self.json_headers, status=400)
        resp = json.loads(response.body)
        assert resp['errors']['username'] == 'Missing value'
        assert response.content_type == 'application/json'
Beispiel #4
0
    def test_show(self):
        """Tests that GET /elicitationmethods/id returns the elicitation method with id=id or an appropriate error."""

        # Create an elicitation method to show.
        params = json.dumps({'name': u'name', 'description': u'description'})
        response = self.app.post(url('elicitationmethods'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        elicitation_method_id = resp['id']

        # Try to get a elicitation_method using an invalid id
        id = 100000000000
        response = self.app.get(url('elicitationmethod', id=id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin,
            status=404)
        resp = json.loads(response.body)
        assert u'There is no elicitation method with id %s' % id in json.loads(response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('elicitationmethod', id=''), status=404,
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == 'The resource could not be found.'

        # Valid id
        response = self.app.get(url('elicitationmethod', id=elicitation_method_id), headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['name'] == u'name'
        assert resp['description'] == u'description'
        assert response.content_type == 'application/json'
Beispiel #5
0
    def test_authenticate(self):
        """Tests that POST /login/authenticate correctly handles authentication attempts."""

        # Invalid username & password
        params = json.dumps({'username': '******', 'password': '******'})
        response = self.app.post(url(controller='login',
                                     action='authenticate'),
                                 params,
                                 self.json_headers,
                                 status=401)
        resp = json.loads(response.body)
        assert resp[
            'error'] == u'The username and password provided are not valid.'
        assert response.content_type == 'application/json'

        # Valid username & password
        params = json.dumps({'username': '******', 'password': '******'})
        response = self.app.post(
            url(controller='login', action='authenticate'), params,
            self.json_headers)
        resp = json.loads(response.body)
        assert resp['authenticated'] == True
        assert response.content_type == 'application/json'

        # Invalid POST params
        params = json.dumps({'usernamex': 'admin', 'password': '******'})
        response = self.app.post(url(controller='login',
                                     action='authenticate'),
                                 params,
                                 self.json_headers,
                                 status=400)
        resp = json.loads(response.body)
        assert resp['errors']['username'] == 'Missing value'
        assert response.content_type == 'application/json'
Beispiel #6
0
    def test_create(self):
        """Tests that POST /elicitationmethods creates a new elicitation method
        or returns an appropriate error if the input is invalid.
        """

        original_EM_count = Session.query(ElicitationMethod).count()

        # Create a valid one
        params = json.dumps({'name': u'em', 'description': u'Described.'})
        response = self.app.post(url('elicitationmethods'), params, self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        new_EM_count = Session.query(ElicitationMethod).count()
        assert new_EM_count == original_EM_count + 1
        assert resp['name'] == u'em'
        assert resp['description'] == u'Described.'
        assert response.content_type == 'application/json'

        # Invalid because name is not unique
        params = json.dumps({'name': u'em', 'description': u'Described.'})
        response = self.app.post(url('elicitationmethods'), params, self.json_headers, self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        assert resp['errors']['name'] == u'The submitted value for ElicitationMethod.name is not unique.'
        assert response.content_type == 'application/json'

        # Invalid because name is empty
        params = json.dumps({'name': u'', 'description': u'Described.'})
        response = self.app.post(url('elicitationmethods'), params, self.json_headers, self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        assert resp['errors']['name'] == u'Please enter a value'

        # Invalid because name is too long
        params = json.dumps({'name': u'name' * 400, 'description': u'Described.'})
        response = self.app.post(url('elicitationmethods'), params, self.json_headers, self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        assert resp['errors']['name'] == u'Enter a value not more than 255 characters long'
    def test_show(self):
        """Tests that GET /applicationsettings/id returns the JSON application settings object with id=id
        or a 404 status code depending on whether the id is valid or
        invalid/unspecified, respectively.
        """

        # Invalid id
        id = 100000000000
        response = self.app.get(url('applicationsetting', id=id),
                            extra_environ=self.extra_environ_admin, status=404)
        assert json.loads(response.body)['error'] == u'There is no application settings with id %s' % id
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('applicationsetting', id=''), status=404,
                                extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == \
            'The resource could not be found.'

        # Add the default application settings.
        application_settings = add_default_application_settings()
        application_settings = h.get_application_settings()
        application_settings_id = application_settings.id

        # Valid id
        response = self.app.get(url('applicationsetting', id=application_settings_id),
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert response.content_type == 'application/json'
        assert type(resp) == type({})
        assert resp['object_language_name'] == \
            application_settings.object_language_name
        assert resp['storage_orthography']['name'] == \
            application_settings.storage_orthography.name
    def test_show(self):
        """Tests that GET /syntacticcategories/id returns the syntactic category with id=id or an appropriate error."""

        # Create an syntactic category to show.
        params = json.dumps({'name': u'name', 'type': u'lexical', 'description': u'description'})
        response = self.app.post(url('syntacticcategories'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        syntactic_category_id = resp['id']

        # Try to get a syntactic_category using an invalid id
        id = 100000000000
        response = self.app.get(url('syntacticcategory', id=id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin,
            status=404)
        resp = json.loads(response.body)
        assert u'There is no syntactic category with id %s' % id in json.loads(response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('syntacticcategory', id=''), status=404,
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == 'The resource could not be found.'
        assert response.content_type == 'application/json'

        # Valid id
        response = self.app.get(url('syntacticcategory', id=syntactic_category_id), headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['name'] == u'name'
        assert resp['description'] == u'description'
        assert response.content_type == 'application/json'
Beispiel #9
0
    def test_edit(self):
        """Tests that GET /formsearches/id/edit returns a JSON object of data necessary to edit the form search with id=id.

        The JSON object is of the form {'form_search': {...}, 'data': {...}} or
        {'error': '...'} (with a 404 status code) depending on whether the id is
        valid or invalid/unspecified, respectively.
        """

        # Create a form search to edit.
        query = {'filter': ['Form', 'transcription', 'regex', u'[a-g]{3,}']}
        params = self.form_search_create_params.copy()
        params.update({
            'name': u'form search',
            'description': u'This one\'s worth saving!',
            'search': query
        })
        params = json.dumps(params)
        response = self.app.post(url('formsearches'), params,
                                 self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        form_search_id = resp['id']
        assert resp['name'] == u'form search'
        assert resp['description'] == u"This one's worth saving!"
        assert resp['search'] == query

        # Not logged in: expect 401 Unauthorized
        response = self.app.get(url('edit_formsearch', id=form_search_id),
                                status=401)
        resp = json.loads(response.body)
        assert resp[
            'error'] == u'Authentication is required to access this resource.'
        assert response.content_type == 'application/json'

        # Invalid id
        id = 9876544
        response = self.app.get(url('edit_formsearch', id=id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin,
                                status=404)
        assert u'There is no form search with id %s' % id in json.loads(
            response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('edit_formsearch', id=''),
                                status=404,
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        assert json.loads(
            response.body)['error'] == 'The resource could not be found.'

        # Valid id
        response = self.app.get(url('edit_formsearch', id=form_search_id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['form_search']['name'] == u'form search'
        assert 'attributes' in resp['data']['search_parameters']
        assert 'relations' in resp['data']['search_parameters']
        assert response.content_type == 'application/json'
Beispiel #10
0
    def test_update(self):
        """Tests that PUT /speakers/id updates the speaker with id=id."""

        # Create a speaker to update.
        params = self.speaker_create_params.copy()
        params.update({
            'first_name': u'first_name',
            'last_name': u'last_name',
            'page_content': u'page_content',
            'dialect': u'dialect'
        })
        params = json.dumps(params)
        response = self.app.post(url('speakers'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        speaker_count = Session.query(Speaker).count()
        speaker_id = resp['id']
        original_datetime_modified = resp['datetime_modified']

        # Update the speaker
        sleep(
            1
        )  # sleep for a second to ensure that MySQL registers a different datetime_modified for the update
        params = self.speaker_create_params.copy()
        params.update({
            'first_name': u'first_name',
            'last_name': u'last_name',
            'page_content': u'page_content',
            'dialect': u'updated dialect.'
        })
        params = json.dumps(params)
        response = self.app.put(url('speaker', id=speaker_id), params,
                                self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        datetime_modified = resp['datetime_modified']
        new_speaker_count = Session.query(Speaker).count()
        assert speaker_count == new_speaker_count
        assert datetime_modified != original_datetime_modified
        assert response.content_type == 'application/json'

        # Attempt an update with no new input and expect to fail
        sleep(
            1
        )  # sleep for a second to ensure that MySQL could register a different datetime_modified for the update
        response = self.app.put(url('speaker', id=speaker_id),
                                params,
                                self.json_headers,
                                self.extra_environ_admin,
                                status=400)
        resp = json.loads(response.body)
        speaker_count = new_speaker_count
        new_speaker_count = Session.query(Speaker).count()
        our_speaker_datetime_modified = Session.query(Speaker).get(
            speaker_id).datetime_modified
        assert our_speaker_datetime_modified.isoformat() == datetime_modified
        assert speaker_count == new_speaker_count
        assert resp[
            'error'] == u'The update request failed because the submitted data were not new.'
        assert response.content_type == 'application/json'
Beispiel #11
0
    def test_edit(self):
        """Tests that GET /orthographies/id/edit returns a JSON object of data necessary to edit the orthography with id=id.

        The JSON object is of the form {'orthography': {...}, 'data': {...}} or
        {'error': '...'} (with a 404 status code) depending on whether the id is
        valid or invalid/unspecified, respectively.
        """

        # Create an orthography to edit.
        params = self.orthography_create_params.copy()
        params.update({'name': u'orthography', 'orthography': u'a, b, c'})
        params = json.dumps(params)
        response = self.app.post(url('orthographies'), params,
                                 self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['name'] == u'orthography'
        assert resp['orthography'] == u'a, b, c'
        assert resp[
            'lowercase'] == False  # default value from model/orthography.py
        assert resp[
            'initial_glottal_stops'] == True  # default value from model/orthography.py
        orthography_id = resp['id']

        # Not logged in: expect 401 Unauthorized
        response = self.app.get(url('edit_orthography', id=orthography_id),
                                status=401)
        resp = json.loads(response.body)
        assert resp[
            'error'] == u'Authentication is required to access this resource.'
        assert response.content_type == 'application/json'

        # Invalid id
        id = 9876544
        response = self.app.get(url('edit_orthography', id=id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin,
                                status=404)
        assert u'There is no orthography with id %s' % id in json.loads(
            response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('edit_orthography', id=''),
                                status=404,
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        assert json.loads(
            response.body)['error'] == 'The resource could not be found.'

        # Valid id
        response = self.app.get(url('edit_orthography', id=orthography_id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['orthography']['name'] == u'orthography'
        assert resp['orthography']['orthography'] == u'a, b, c'
        assert resp['data'] == {}
        assert response.content_type == 'application/json'
Beispiel #12
0
    def test_update(self):
        """Tests that PUT /pages/id updates the page with id=id."""

        # Create a page to update.
        params = self.page_create_params.copy()
        params.update({
            'name': u'page',
            'markup_language': u'Markdown',
            'content': self.md_contents
        })
        params = json.dumps(params)
        response = self.app.post(url('pages'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        page_count = Session.query(Page).count()
        page_id = resp['id']
        original_datetime_modified = resp['datetime_modified']

        # Update the page
        sleep(
            1
        )  # sleep for a second to ensure that MySQL registers a different datetime_modified for the update
        params = self.page_create_params.copy()
        params.update({
            'name': u'Awesome Page',
            'markup_language': u'Markdown',
            'content': self.md_contents
        })
        params = json.dumps(params)
        response = self.app.put(url('page', id=page_id), params,
                                self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        datetime_modified = resp['datetime_modified']
        new_page_count = Session.query(Page).count()
        assert page_count == new_page_count
        assert datetime_modified != original_datetime_modified
        assert resp['name'] == u'Awesome Page'
        assert response.content_type == 'application/json'

        # Attempt an update with no new input and expect to fail
        sleep(
            1
        )  # sleep for a second to ensure that MySQL could register a different datetime_modified for the update
        response = self.app.put(url('page', id=page_id),
                                params,
                                self.json_headers,
                                self.extra_environ_admin,
                                status=400)
        resp = json.loads(response.body)
        page_count = new_page_count
        new_page_count = Session.query(Page).count()
        our_page_datetime_modified = Session.query(Page).get(
            page_id).datetime_modified
        assert our_page_datetime_modified.isoformat() == datetime_modified
        assert page_count == new_page_count
        assert resp[
            'error'] == u'The update request failed because the submitted data were not new.'
        assert response.content_type == 'application/json'
Beispiel #13
0
    def test_edit(self):
        """Tests that GET /speakers/id/edit returns a JSON object of data necessary to edit the speaker with id=id.

        The JSON object is of the form {'speaker': {...}, 'data': {...}} or
        {'error': '...'} (with a 404 status code) depending on whether the id is
        valid or invalid/unspecified, respectively.
        """

        # Create a speaker to edit.
        params = self.speaker_create_params.copy()
        params.update({
            'first_name': u'first_name',
            'last_name': u'last_name',
            'page_content': u'page_content',
            'dialect': u'dialect'
        })
        params = json.dumps(params)
        response = self.app.post(url('speakers'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        speaker_id = resp['id']

        # Not logged in: expect 401 Unauthorized
        response = self.app.get(url('edit_speaker', id=speaker_id), status=401)
        resp = json.loads(response.body)
        assert resp[
            'error'] == u'Authentication is required to access this resource.'
        assert response.content_type == 'application/json'

        # Invalid id
        id = 9876544
        response = self.app.get(url('edit_speaker', id=id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin,
                                status=404)
        assert u'There is no speaker with id %s' % id in json.loads(
            response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('edit_speaker', id=''),
                                status=404,
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        assert json.loads(
            response.body)['error'] == 'The resource could not be found.'
        assert response.content_type == 'application/json'

        # Valid id
        response = self.app.get(url('edit_speaker', id=speaker_id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['speaker']['first_name'] == u'first_name'
        assert resp['data'] == {}
        assert response.content_type == 'application/json'
Beispiel #14
0
    def test_delete(self):
        """Tests that DELETE /tags/id deletes the tag with id=id."""

        # Create a tag to delete.
        params = json.dumps({'name': u'name', 'description': u'description'})
        response = self.app.post(url('tags'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        tag_count = Session.query(Tag).count()
        tag_id = resp['id']

        # Now delete the tag
        response = self.app.delete(url('tag', id=tag_id), headers=self.json_headers,
            extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        new_tag_count = Session.query(Tag).count()
        assert new_tag_count == tag_count - 1
        assert resp['id'] == tag_id
        assert response.content_type == 'application/json'

        # Trying to get the deleted tag from the db should return None
        deleted_tag = Session.query(Tag).get(tag_id)
        assert deleted_tag == None

        # Delete with an invalid id
        id = 9999999999999
        response = self.app.delete(url('tag', id=id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin,
            status=404)
        assert u'There is no tag with id %s' % id in json.loads(response.body)['error']
        assert response.content_type == 'application/json'

        # Delete without an id
        response = self.app.delete(url('tag', id=''), status=404,
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == 'The resource could not be found.'
        assert response.content_type == 'application/json'

        # Create a form, tag it, delete the tag and show that the form no longer
        # has the tag.
        tag = model.Tag()
        tag.name = u'tag'
        form = model.Form()
        form.transcription = u'test'
        form.tags.append(tag)
        Session.add_all([form, tag])
        Session.commit()
        form_id = form.id
        tag_id = tag.id
        response = self.app.delete(url('tag', id=tag_id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        deleted_tag = Session.query(Tag).get(tag_id)
        form = Session.query(model.Form).get(form_id)
        assert response.content_type == 'application/json'
        assert deleted_tag == None
        assert form.tags == []
Beispiel #15
0
    def test_create(self):
        """Tests that POST /tags creates a new tag
        or returns an appropriate error if the input is invalid.
        """

        original_tag_count = Session.query(Tag).count()

        # Create a valid one
        params = json.dumps({'name': u'tag', 'description': u'Described.'})
        response = self.app.post(url('tags'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        new_tag_count = Session.query(Tag).count()
        assert new_tag_count == original_tag_count + 1
        assert resp['name'] == u'tag'
        assert resp['description'] == u'Described.'
        assert response.content_type == 'application/json'

        # Invalid because name is not unique
        params = json.dumps({'name': u'tag', 'description': u'Described.'})
        response = self.app.post(url('tags'),
                                 params,
                                 self.json_headers,
                                 self.extra_environ_admin,
                                 status=400)
        resp = json.loads(response.body)
        assert resp['errors'][
            'name'] == u'The submitted value for Tag.name is not unique.'

        # Invalid because name is empty
        params = json.dumps({'name': u'', 'description': u'Described.'})
        response = self.app.post(url('tags'),
                                 params,
                                 self.json_headers,
                                 self.extra_environ_admin,
                                 status=400)
        resp = json.loads(response.body)
        assert resp['errors']['name'] == u'Please enter a value'
        assert response.content_type == 'application/json'

        # Invalid because name is too long
        params = json.dumps({
            'name': u'name' * 400,
            'description': u'Described.'
        })
        response = self.app.post(url('tags'),
                                 params,
                                 self.json_headers,
                                 self.extra_environ_admin,
                                 status=400)
        resp = json.loads(response.body)
        assert resp['errors'][
            'name'] == u'Enter a value not more than 255 characters long'
        assert response.content_type == 'application/json'
Beispiel #16
0
    def test_delete(self):
        """Tests that DELETE /formsearches/id deletes the form search with id=id."""

        # Create a form search to delete.
        query = {'filter': ['Form', 'transcription', 'regex', u'[a-g]{3,}']}
        params = self.form_search_create_params.copy()
        params.update({
            'name': u'form search',
            'description': u'This one\'s worth saving!',
            'search': query
        })
        params = json.dumps(params)
        response = self.app.post(url('formsearches'), params,
                                 self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        form_search_count = Session.query(FormSearch).count()
        form_search_id = resp['id']
        assert resp['name'] == u'form search'
        assert resp['description'] == u"This one's worth saving!"
        assert resp['search'] == query

        # Now delete the form_search
        response = self.app.delete(url('formsearch', id=form_search_id),
                                   headers=self.json_headers,
                                   extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        new_form_search_count = Session.query(FormSearch).count()
        assert new_form_search_count == form_search_count - 1
        assert resp['id'] == form_search_id
        assert response.content_type == 'application/json'

        # Trying to get the deleted form_search from the db should return None
        deleted_form_search = Session.query(FormSearch).get(form_search_id)
        assert deleted_form_search == None

        # Delete with an invalid id
        id = 9999999999999
        response = self.app.delete(url('formsearch', id=id),
                                   headers=self.json_headers,
                                   extra_environ=self.extra_environ_admin,
                                   status=404)
        assert u'There is no form search with id %s' % id in json.loads(
            response.body)['error']
        assert response.content_type == 'application/json'

        # Delete without an id
        response = self.app.delete(url('formsearch', id=''),
                                   status=404,
                                   headers=self.json_headers,
                                   extra_environ=self.extra_environ_admin)
        assert json.loads(
            response.body)['error'] == 'The resource could not be found.'
Beispiel #17
0
    def test_update(self):
        """Tests that PUT /formsearches/id updates the form search with id=id."""

        # Create a form search to update.
        query = {'filter': ['Form', 'transcription', 'regex', u'[a-g]{3,}']}
        params = self.form_search_create_params.copy()
        params.update({
            'name': u'form search',
            'description': u'This one\'s worth saving!',
            'search': query
        })
        params = json.dumps(params)
        response = self.app.post(url('formsearches'), params, self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        form_search_count = Session.query(FormSearch).count()
        form_search_id = resp['id']
        original_datetime_modified = resp['datetime_modified']
        assert resp['name'] == u'form search'
        assert resp['description'] == u"This one's worth saving!"
        assert resp['search'] == query

        # Update the form search
        sleep(1)    # sleep for a second to ensure that MySQL registers a different datetime_modified for the update
        params = self.form_search_create_params.copy()
        params.update({
            'name': u'form search for keeping',
            'description': u'This one\'s worth saving!',
            'search': query
        })
        params = json.dumps(params)
        response = self.app.put(url('formsearch', id=form_search_id), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        datetime_modified = resp['datetime_modified']
        new_form_search_count = Session.query(FormSearch).count()
        assert form_search_count == new_form_search_count
        assert datetime_modified != original_datetime_modified
        assert response.content_type == 'application/json'

        # Attempt an update with no new input and expect to fail
        sleep(1)    # sleep for a second to ensure that MySQL could register a different datetime_modified for the update
        response = self.app.put(url('formsearch', id=form_search_id), params, self.json_headers,
                                 self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        form_search_count = new_form_search_count
        new_form_search_count = Session.query(FormSearch).count()
        our_form_search_datetime_modified = Session.query(FormSearch).get(form_search_id).datetime_modified
        assert our_form_search_datetime_modified.isoformat() == datetime_modified
        assert form_search_count == new_form_search_count
        assert resp['error'] == u'The update request failed because the submitted data were not new.'
        assert response.content_type == 'application/json'
Beispiel #18
0
    def test_create(self):
        """Tests that POST /pages creates a new page
        or returns an appropriate error if the input is invalid.
        """

        original_page_count = Session.query(Page).count()

        # Create a valid one
        params = self.page_create_params.copy()
        params.update({
            'name': u'page',
            'markup_language': u'Markdown',
            'content': self.md_contents
        })
        params = json.dumps(params)
        response = self.app.post(url('pages'), params, self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        new_page_count = Session.query(Page).count()
        assert new_page_count == original_page_count + 1
        assert resp['name'] == u'page'
        assert resp['content'] == self.md_contents
        assert resp['html'] == h.get_HTML_from_contents(self.md_contents, 'Markdown')
        assert response.content_type == 'application/json'

        # Invalid because name is empty and markup language is invalid
        params = self.page_create_params.copy()
        params.update({
            'name': u'',
            'markup_language': u'markdownable',
            'content': self.md_contents
        })
        params = json.dumps(params)
        response = self.app.post(url('pages'), params, self.json_headers, self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        assert resp['errors']['name'] == u'Please enter a value'
        assert resp['errors']['markup_language'] == \
            u"Value must be one of: Markdown; reStructuredText (not u'markdownable')"
        assert response.content_type == 'application/json'

        # Invalid because name is too long
        params = self.page_create_params.copy()
        params.update({
            'name': u'name' * 200,
            'markup_language': u'Markdown',
            'content': self.md_contents
        })
        params = json.dumps(params)
        response = self.app.post(url('pages'), params, self.json_headers, self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        assert resp['errors']['name'] == u'Enter a value not more than 255 characters long'
        assert response.content_type == 'application/json'
Beispiel #19
0
    def test_edit(self):
        """Tests that GET /elicitationmethods/id/edit returns a JSON object of data necessary to edit the elicitation method with id=id.

        The JSON object is of the form {'elicitation_method': {...}, 'data': {...}} or
        {'error': '...'} (with a 404 status code) depending on whether the id is
        valid or invalid/unspecified, respectively.
        """

        # Create an elicitation method to edit.
        params = json.dumps({'name': u'name', 'description': u'description'})
        response = self.app.post(url('elicitationmethods'), params,
                                 self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        elicitation_method_id = resp['id']

        # Not logged in: expect 401 Unauthorized
        response = self.app.get(url('edit_elicitationmethod',
                                    id=elicitation_method_id),
                                status=401)
        resp = json.loads(response.body)
        assert resp[
            'error'] == u'Authentication is required to access this resource.'
        assert response.content_type == 'application/json'

        # Invalid id
        id = 9876544
        response = self.app.get(url('edit_elicitationmethod', id=id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin,
                                status=404)
        assert u'There is no elicitation method with id %s' % id in json.loads(
            response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('edit_elicitationmethod', id=''),
                                status=404,
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == \
            'The resource could not be found.'

        # Valid id
        response = self.app.get(url('edit_elicitationmethod',
                                    id=elicitation_method_id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['elicitation_method']['name'] == u'name'
        assert resp['data'] == {}
        assert response.content_type == 'application/json'
Beispiel #20
0
    def test_delete(self):
        """Tests that DELETE /speakers/id deletes the speaker with id=id."""

        # Create a speaker to delete.
        params = self.speaker_create_params.copy()
        params.update({
            'first_name': u'first_name',
            'last_name': u'last_name',
            'page_content': u'page_content',
            'dialect': u'dialect'
        })
        params = json.dumps(params)
        response = self.app.post(url('speakers'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        speaker_count = Session.query(Speaker).count()
        speaker_id = resp['id']

        # Now delete the speaker
        response = self.app.delete(url('speaker', id=speaker_id),
                                   headers=self.json_headers,
                                   extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        new_speaker_count = Session.query(Speaker).count()
        assert new_speaker_count == speaker_count - 1
        assert resp['id'] == speaker_id
        assert response.content_type == 'application/json'

        # Trying to get the deleted speaker from the db should return None
        deleted_speaker = Session.query(Speaker).get(speaker_id)
        assert deleted_speaker == None
        assert response.content_type == 'application/json'

        # Delete with an invalid id
        id = 9999999999999
        response = self.app.delete(url('speaker', id=id),
                                   headers=self.json_headers,
                                   extra_environ=self.extra_environ_admin,
                                   status=404)
        assert u'There is no speaker with id %s' % id in json.loads(
            response.body)['error']
        assert response.content_type == 'application/json'

        # Delete without an id
        response = self.app.delete(url('speaker', id=''),
                                   status=404,
                                   headers=self.json_headers,
                                   extra_environ=self.extra_environ_admin)
        assert json.loads(
            response.body)['error'] == 'The resource could not be found.'
        assert response.content_type == 'application/json'
Beispiel #21
0
    def test_update(self):
        """Tests that PUT /speakers/id updates the speaker with id=id."""

        # Create a speaker to update.
        params = self.speaker_create_params.copy()
        params.update({
            'first_name': u'first_name',
            'last_name': u'last_name',
            'page_content': u'page_content',
            'dialect': u'dialect'
        })
        params = json.dumps(params)
        response = self.app.post(url('speakers'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        speaker_count = Session.query(Speaker).count()
        speaker_id = resp['id']
        original_datetime_modified = resp['datetime_modified']

        # Update the speaker
        sleep(1)    # sleep for a second to ensure that MySQL registers a different datetime_modified for the update
        params = self.speaker_create_params.copy()
        params.update({
            'first_name': u'first_name',
            'last_name': u'last_name',
            'page_content': u'page_content',
            'dialect': u'updated dialect.'
        })
        params = json.dumps(params)
        response = self.app.put(url('speaker', id=speaker_id), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        datetime_modified = resp['datetime_modified']
        new_speaker_count = Session.query(Speaker).count()
        assert speaker_count == new_speaker_count
        assert datetime_modified != original_datetime_modified
        assert response.content_type == 'application/json'

        # Attempt an update with no new input and expect to fail
        sleep(1)    # sleep for a second to ensure that MySQL could register a different datetime_modified for the update
        response = self.app.put(url('speaker', id=speaker_id), params, self.json_headers,
                                 self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        speaker_count = new_speaker_count
        new_speaker_count = Session.query(Speaker).count()
        our_speaker_datetime_modified = Session.query(Speaker).get(speaker_id).datetime_modified
        assert our_speaker_datetime_modified.isoformat() == datetime_modified
        assert speaker_count == new_speaker_count
        assert resp['error'] == u'The update request failed because the submitted data were not new.'
        assert response.content_type == 'application/json'
Beispiel #22
0
    def test_update(self):
        """Tests that PUT /elicitationmethods/id updates the elicitationmethod with id=id."""

        # Create an elicitation method to update.
        params = json.dumps({'name': u'name', 'description': u'description'})
        response = self.app.post(url('elicitationmethods'), params,
                                 self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        elicitation_method_count = Session.query(ElicitationMethod).count()
        elicitation_method_id = resp['id']
        original_datetime_modified = resp['datetime_modified']

        # Update the elicitation method
        sleep(
            1
        )  # sleep for a second to ensure that MySQL registers a different datetime_modified for the update
        params = json.dumps({
            'name': u'name',
            'description': u'More content-ful description.'
        })
        response = self.app.put(
            url('elicitationmethod', id=elicitation_method_id), params,
            self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        datetime_modified = resp['datetime_modified']
        new_elicitation_method_count = Session.query(ElicitationMethod).count()
        assert elicitation_method_count == new_elicitation_method_count
        assert datetime_modified != original_datetime_modified
        assert response.content_type == 'application/json'

        # Attempt an update with no new input and expect to fail
        sleep(
            1
        )  # sleep for a second to ensure that MySQL could register a different datetime_modified for the update
        response = self.app.put(url('elicitationmethod',
                                    id=elicitation_method_id),
                                params,
                                self.json_headers,
                                self.extra_environ_admin,
                                status=400)
        resp = json.loads(response.body)
        elicitation_method_count = new_elicitation_method_count
        new_elicitation_method_count = Session.query(ElicitationMethod).count()
        our_EM_datetime_modified = Session.query(ElicitationMethod).get(
            elicitation_method_id).datetime_modified
        assert our_EM_datetime_modified.isoformat() == datetime_modified
        assert elicitation_method_count == new_elicitation_method_count
        assert resp[
            'error'] == u'The update request failed because the submitted data were not new.'
        assert response.content_type == 'application/json'
Beispiel #23
0
    def test_edit(self):
        """Tests that GET /formsearches/id/edit returns a JSON object of data necessary to edit the form search with id=id.

        The JSON object is of the form {'form_search': {...}, 'data': {...}} or
        {'error': '...'} (with a 404 status code) depending on whether the id is
        valid or invalid/unspecified, respectively.
        """

        # Create a form search to edit.
        query = {'filter': ['Form', 'transcription', 'regex', u'[a-g]{3,}']}
        params = self.form_search_create_params.copy()
        params.update({
            'name': u'form search',
            'description': u'This one\'s worth saving!',
            'search': query
        })
        params = json.dumps(params)
        response = self.app.post(url('formsearches'), params, self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        form_search_id = resp['id']
        assert resp['name'] == u'form search'
        assert resp['description'] == u"This one's worth saving!"
        assert resp['search'] == query

        # Not logged in: expect 401 Unauthorized
        response = self.app.get(url('edit_formsearch', id=form_search_id), status=401)
        resp = json.loads(response.body)
        assert resp['error'] == u'Authentication is required to access this resource.'
        assert response.content_type == 'application/json'

        # Invalid id
        id = 9876544
        response = self.app.get(url('edit_formsearch', id=id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin, status=404)
        assert u'There is no form search with id %s' % id in json.loads(response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('edit_formsearch', id=''), status=404,
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == 'The resource could not be found.'

        # Valid id
        response = self.app.get(url('edit_formsearch', id=form_search_id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['form_search']['name'] == u'form search'
        assert 'attributes' in resp['data']['search_parameters']
        assert 'relations' in resp['data']['search_parameters']
        assert response.content_type == 'application/json'
Beispiel #24
0
    def test_edit(self):
        """Tests that GET /speakers/id/edit returns a JSON object of data necessary to edit the speaker with id=id.

        The JSON object is of the form {'speaker': {...}, 'data': {...}} or
        {'error': '...'} (with a 404 status code) depending on whether the id is
        valid or invalid/unspecified, respectively.
        """

        # Create a speaker to edit.
        params = self.speaker_create_params.copy()
        params.update({
            'first_name': u'first_name',
            'last_name': u'last_name',
            'page_content': u'page_content',
            'dialect': u'dialect'
        })
        params = json.dumps(params)
        response = self.app.post(url('speakers'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        speaker_id = resp['id']

        # Not logged in: expect 401 Unauthorized
        response = self.app.get(url('edit_speaker', id=speaker_id), status=401)
        resp = json.loads(response.body)
        assert resp['error'] == u'Authentication is required to access this resource.'
        assert response.content_type == 'application/json'

        # Invalid id
        id = 9876544
        response = self.app.get(url('edit_speaker', id=id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin,
            status=404)
        assert u'There is no speaker with id %s' % id in json.loads(response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('edit_speaker', id=''), status=404,
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == 'The resource could not be found.'
        assert response.content_type == 'application/json'

        # Valid id
        response = self.app.get(url('edit_speaker', id=speaker_id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['speaker']['first_name'] == u'first_name'
        assert resp['data'] == {}
        assert response.content_type == 'application/json'
Beispiel #25
0
    def test_delete(self):
        """Tests that DELETE /pages/id deletes the page with id=id."""

        # Create a page to delete.
        params = self.page_create_params.copy()
        params.update({
            'name': u'page',
            'markup_language': u'Markdown',
            'content': self.md_contents
        })
        params = json.dumps(params)
        response = self.app.post(url('pages'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        page_count = Session.query(Page).count()
        page_id = resp['id']

        # Now delete the page
        response = self.app.delete(url('page', id=page_id),
                                   headers=self.json_headers,
                                   extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        new_page_count = Session.query(Page).count()
        assert new_page_count == page_count - 1
        assert resp['id'] == page_id
        assert response.content_type == 'application/json'

        # Trying to get the deleted page from the db should return None
        deleted_page = Session.query(Page).get(page_id)
        assert deleted_page == None
        assert response.content_type == 'application/json'

        # Delete with an invalid id
        id = 9999999999999
        response = self.app.delete(url('page', id=id),
                                   headers=self.json_headers,
                                   extra_environ=self.extra_environ_admin,
                                   status=404)
        assert u'There is no page with id %s' % id in json.loads(
            response.body)['error']
        assert response.content_type == 'application/json'

        # Delete without an id
        response = self.app.delete(url('page', id=''),
                                   status=404,
                                   headers=self.json_headers,
                                   extra_environ=self.extra_environ_admin)
        assert json.loads(
            response.body)['error'] == 'The resource could not be found.'
Beispiel #26
0
    def test_update(self):
        """Tests that PUT /pages/id updates the page with id=id."""

        # Create a page to update.
        params = self.page_create_params.copy()
        params.update({
            'name': u'page',
            'markup_language': u'Markdown',
            'content': self.md_contents
        })
        params = json.dumps(params)
        response = self.app.post(url('pages'), params, self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        page_count = Session.query(Page).count()
        page_id = resp['id']
        original_datetime_modified = resp['datetime_modified']

        # Update the page
        sleep(1)    # sleep for a second to ensure that MySQL registers a different datetime_modified for the update
        params = self.page_create_params.copy()
        params.update({
            'name': u'Awesome Page',
            'markup_language': u'Markdown',
            'content': self.md_contents
        })
        params = json.dumps(params)
        response = self.app.put(url('page', id=page_id), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        datetime_modified = resp['datetime_modified']
        new_page_count = Session.query(Page).count()
        assert page_count == new_page_count
        assert datetime_modified != original_datetime_modified
        assert resp['name'] == u'Awesome Page'
        assert response.content_type == 'application/json'

        # Attempt an update with no new input and expect to fail
        sleep(1)    # sleep for a second to ensure that MySQL could register a different datetime_modified for the update
        response = self.app.put(url('page', id=page_id), params, self.json_headers,
                                 self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        page_count = new_page_count
        new_page_count = Session.query(Page).count()
        our_page_datetime_modified = Session.query(Page).get(page_id).datetime_modified
        assert our_page_datetime_modified.isoformat() == datetime_modified
        assert page_count == new_page_count
        assert resp['error'] == u'The update request failed because the submitted data were not new.'
        assert response.content_type == 'application/json'
Beispiel #27
0
 def test_new(self):
     """Tests that GET /pages/new returns the list of accepted markup languages."""
     response = self.app.get(url('new_page'), headers=self.json_headers,
                             extra_environ=self.extra_environ_contrib)
     resp = json.loads(response.body)
     assert resp == {'markup_languages': list(h.markup_languages)}
     assert response.content_type == 'application/json'
Beispiel #28
0
 def test_new_search(self):
     """Tests that GET /languages/new_search returns the search parameters for searching the languages resource."""
     query_builder = SQLAQueryBuilder('Language')
     response = self.app.get(url('/languages/new_search'), headers=self.json_headers,
                             extra_environ=self.extra_environ_view)
     resp = json.loads(response.body)
     assert resp['search_parameters'] == h.get_search_parameters(query_builder)
Beispiel #29
0
 def test_new(self):
     """Tests that GET /speakers/new returns an empty JSON object."""
     response = self.app.get(url('new_speaker'), headers=self.json_headers,
                             extra_environ=self.extra_environ_contrib)
     resp = json.loads(response.body)
     assert resp == {}
     assert response.content_type == 'application/json'
Beispiel #30
0
 def test_new_search(self):
     """Tests that GET /collectionbackups/new_search returns the search parameters for searching the collection backups resource."""
     query_builder = SQLAQueryBuilder('CollectionBackup')
     response = self.app.get(url('/collectionbackups/new_search'), headers=self.json_headers,
                             extra_environ=self.extra_environ_view)
     resp = json.loads(response.body)
     assert resp['search_parameters'] == h.get_search_parameters(query_builder)
 def test_new(self):
     """Tests that GET /syntacticcategories/new returns an empty JSON object."""
     response = self.app.get(url('new_syntacticcategory'), headers=self.json_headers,
                             extra_environ=self.extra_environ_contrib)
     resp = json.loads(response.body)
     assert resp['syntactic_category_types'] == list(h.syntactic_category_types)
     assert response.content_type == 'application/json'
    def test_create_invalid(self):
        """Tests that POST /applicationsettings responds with an appropriate error when invalid params are submitted in the request."""

        params = self.application_settings_create_params.copy()
        params.update({
            'object_language_name': u'!' * 256,   # too long
            'object_language_id': u'too long',    # too long also
            'orthographic_validation': u'No Way!', # not a valid value
            # formencode.validators.StringBoolean accepts 'true', 'false' (with
            # any character in uppercase) as well as any int or float.  'Truish'
            # is unacceptable.
            'morpheme_break_is_orthographic': u'Truish',
            'storage_orthography': 'accept me!'  # integer (orth.id) required
        })
        params = json.dumps(params)
        response = self.app.post(url('applicationsettings'), params,
                        self.json_headers, self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        assert response.content_type == 'application/json'
        assert resp['errors']['object_language_id'] == \
            u'Enter a value not more than 3 characters long'
        assert resp['errors']['object_language_name'] == \
            u'Enter a value not more than 255 characters long'
        assert u'Value must be one of: None; Warning; Error' in \
            resp['errors']['orthographic_validation']
        assert u"Value should be 'true' or 'false'" in \
            resp['errors']['morpheme_break_is_orthographic']
        assert resp['errors']['storage_orthography'] == \
            u'Please enter an integer value'
Beispiel #33
0
 def test_new(self):
     """Tests that GET /syntacticcategories/new returns an empty JSON object."""
     response = self.app.get(url('new_syntacticcategory'), headers=self.json_headers,
                             extra_environ=self.extra_environ_contrib)
     resp = json.loads(response.body)
     assert resp['syntactic_category_types'] == list(h.syntactic_category_types)
     assert response.content_type == 'application/json'
Beispiel #34
0
    def test_show(self):
        """Tests that GET /formsearches/id returns the formsearch with id=id or an appropriate error."""

        # Create a form search to show.
        query = {'filter': ['Form', 'transcription', 'regex', u'[a-g]{3,}']}
        params = self.form_search_create_params.copy()
        params.update({
            'name': u'form search',
            'description': u'This one\'s worth saving!',
            'search': query
        })
        params = json.dumps(params)
        response = self.app.post(url('formsearches'), params,
                                 self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        form_search_id = resp['id']
        assert resp['name'] == u'form search'
        assert resp['description'] == u"This one's worth saving!"
        assert resp['search'] == query

        # Try to get a form search using an invalid id
        id = 100000000000
        response = self.app.get(url('formsearch', id=id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin,
                                status=404)
        resp = json.loads(response.body)
        assert u'There is no form search with id %s' % id in json.loads(
            response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('formsearch', id=''),
                                status=404,
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        assert json.loads(
            response.body)['error'] == 'The resource could not be found.'

        # Valid id
        response = self.app.get(url('formsearch', id=form_search_id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['name'] == u'form search'
        assert resp['description'] == u"This one's worth saving!"
        assert response.content_type == 'application/json'
    def test_create(self):
        """Tests that POST /applicationsettings correctly creates a new application settings."""

        # Add some orthographies.
        orthography1 = h.generate_default_orthography1()
        orthography2 = h.generate_default_orthography2()
        Session.add_all([orthography1, orthography2])
        Session.commit()
        orthography2_id = orthography2.id
        orthography2_orthography = orthography2.orthography

        params = self.application_settings_create_params.copy()
        params.update({
            'object_language_name': u'test_create object language name',
            'object_language_id': u'tco',
            'metalanguage_name': u'test_create metalanguage name',
            'metalanguage_id': u'tcm',
            'orthographic_validation': u'Warning',
            'narrow_phonetic_validation': u'Error',
            'morpheme_break_is_orthographic': False,
            'morpheme_delimiters': u'-,+',
            'punctuation': u'!?.,;:-_',
            'grammaticalities': u'*,**,***,?,??,???,#,##,###',
            'unrestricted_users': [Session.query(User).filter(
                User.role==u'viewer').first().id],
            'storage_orthography': orthography2_id,
            'input_orthography': orthography2_id,
            'output_orthography': orthography2_id
        })
        params = json.dumps(params)

        response = self.app.post(url('applicationsettings'), params,
                                 self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['object_language_name'] == u'test_create object language name'
        assert resp['morpheme_break_is_orthographic'] is False
        assert resp['storage_orthography']['orthography'] == orthography2_orthography
        assert resp['unrestricted_users'][0]['first_name'] == u'Viewer'
        assert 'password' not in resp['unrestricted_users'][0]
        assert response.content_type == 'application/json'

        # Attempt the same above creation as a contributor and expect to fail.
        response = self.app.post(url('applicationsettings'), params,
            self.json_headers, self.extra_environ_contrib, status=403)
        resp = json.loads(response.body)
        assert response.content_type == 'application/json'
        assert resp['error'] == u'You are not authorized to access this resource.'
Beispiel #36
0
    def test_edit(self):
        """Tests that GET /orthographies/id/edit returns a JSON object of data necessary to edit the orthography with id=id.

        The JSON object is of the form {'orthography': {...}, 'data': {...}} or
        {'error': '...'} (with a 404 status code) depending on whether the id is
        valid or invalid/unspecified, respectively.
        """

        # Create an orthography to edit.
        params = self.orthography_create_params.copy()
        params.update({'name': u'orthography', 'orthography': u'a, b, c'})
        params = json.dumps(params)
        response = self.app.post(url('orthographies'), params, self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['name'] == u'orthography'
        assert resp['orthography'] == u'a, b, c'
        assert resp['lowercase'] == False   # default value from model/orthography.py
        assert resp['initial_glottal_stops'] == True    # default value from model/orthography.py
        orthography_id = resp['id']

        # Not logged in: expect 401 Unauthorized
        response = self.app.get(url('edit_orthography', id=orthography_id), status=401)
        resp = json.loads(response.body)
        assert resp['error'] == u'Authentication is required to access this resource.'
        assert response.content_type == 'application/json'

        # Invalid id
        id = 9876544
        response = self.app.get(url('edit_orthography', id=id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin,
            status=404)
        assert u'There is no orthography with id %s' % id in json.loads(response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('edit_orthography', id=''), status=404,
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == 'The resource could not be found.'

        # Valid id
        response = self.app.get(url('edit_orthography', id=orthography_id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['orthography']['name'] == u'orthography'
        assert resp['orthography']['orthography'] == u'a, b, c'
        assert resp['data'] == {}
        assert response.content_type == 'application/json'
Beispiel #37
0
 def test_new(self):
     """Tests that GET /elicitationmethods/new returns an empty JSON object."""
     response = self.app.get(url('new_elicitationmethod'),
                             headers=self.json_headers,
                             extra_environ=self.extra_environ_contrib)
     resp = json.loads(response.body)
     assert resp == {}
     assert response.content_type == 'application/json'
Beispiel #38
0
 def test_new(self):
     """Tests that GET /formsearches/new returns the data necessary to create a new form search."""
     response = self.app.get(url('new_formsearch'), headers=self.json_headers,
                             extra_environ=self.extra_environ_contrib)
     resp = json.loads(response.body)
     assert 'attributes' in resp['search_parameters']
     assert 'relations' in resp['search_parameters']
     assert response.content_type == 'application/json'
Beispiel #39
0
 def test_new(self):
     """Tests that GET /pages/new returns the list of accepted markup languages."""
     response = self.app.get(url('new_page'),
                             headers=self.json_headers,
                             extra_environ=self.extra_environ_contrib)
     resp = json.loads(response.body)
     assert resp == {'markup_languages': list(h.markup_languages)}
     assert response.content_type == 'application/json'
Beispiel #40
0
    def test_logout(self):
        """Tests that GET /login/logout logs the user out."""

        # Logout while logged in.
        response = self.app.get(url(controller='login',
                        action='logout'), headers=self.json_headers,
                        extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['authenticated'] == False
        assert response.content_type == 'application/json'

        # Logout while not logged in.
        response = self.app.get(url(controller='login',
                        action='logout'), headers=self.json_headers, status=401)
        resp = json.loads(response.body)
        assert resp['error'] == u'Authentication is required to access this resource.'
        assert response.content_type == 'application/json'
Beispiel #41
0
    def test_show(self):
        """Tests that GET /orthographies/id returns the orthography with id=id or an appropriate error."""

        # Create an orthography to show.
        params = self.orthography_create_params.copy()
        params.update({'name': u'orthography', 'orthography': u'a, b, c'})
        params = json.dumps(params)
        response = self.app.post(url('orthographies'), params,
                                 self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['name'] == u'orthography'
        assert resp['orthography'] == u'a, b, c'
        assert resp[
            'lowercase'] == False  # default value from model/orthography.py
        assert resp[
            'initial_glottal_stops'] == True  # default value from model/orthography.py
        orthography_id = resp['id']

        # Try to get an orthography using an invalid id
        id = 100000000000
        response = self.app.get(url('orthography', id=id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin,
                                status=404)
        resp = json.loads(response.body)
        assert u'There is no orthography with id %s' % id in json.loads(
            response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('orthography', id=''),
                                status=404,
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        assert json.loads(
            response.body)['error'] == 'The resource could not be found.'
        assert response.content_type == 'application/json'

        # Valid id
        response = self.app.get(url('orthography', id=orthography_id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['name'] == u'orthography'
        assert resp['orthography'] == u'a, b, c'
        assert response.content_type == 'application/json'
Beispiel #42
0
    def test_delete(self):
        """Tests that DELETE /speakers/id deletes the speaker with id=id."""

        # Create a speaker to delete.
        params = self.speaker_create_params.copy()
        params.update({
            'first_name': u'first_name',
            'last_name': u'last_name',
            'page_content': u'page_content',
            'dialect': u'dialect'
        })
        params = json.dumps(params)
        response = self.app.post(url('speakers'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        speaker_count = Session.query(Speaker).count()
        speaker_id = resp['id']

        # Now delete the speaker
        response = self.app.delete(url('speaker', id=speaker_id), headers=self.json_headers,
            extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        new_speaker_count = Session.query(Speaker).count()
        assert new_speaker_count == speaker_count - 1
        assert resp['id'] == speaker_id
        assert response.content_type == 'application/json'

        # Trying to get the deleted speaker from the db should return None
        deleted_speaker = Session.query(Speaker).get(speaker_id)
        assert deleted_speaker == None
        assert response.content_type == 'application/json'

        # Delete with an invalid id
        id = 9999999999999
        response = self.app.delete(url('speaker', id=id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin,
            status=404)
        assert u'There is no speaker with id %s' % id in json.loads(response.body)['error']
        assert response.content_type == 'application/json'

        # Delete without an id
        response = self.app.delete(url('speaker', id=''), status=404,
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == 'The resource could not be found.'
        assert response.content_type == 'application/json'
Beispiel #43
0
    def test_delete(self):
        """Tests that DELETE /formsearches/id deletes the form search with id=id."""

        # Create a form search to delete.
        query = {'filter': ['Form', 'transcription', 'regex', u'[a-g]{3,}']}
        params = self.form_search_create_params.copy()
        params.update({
            'name': u'form search',
            'description': u'This one\'s worth saving!',
            'search': query
        })
        params = json.dumps(params)
        response = self.app.post(url('formsearches'), params, self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        form_search_count = Session.query(FormSearch).count()
        form_search_id = resp['id']
        assert resp['name'] == u'form search'
        assert resp['description'] == u"This one's worth saving!"
        assert resp['search'] == query

        # Now delete the form_search
        response = self.app.delete(url('formsearch', id=form_search_id), headers=self.json_headers,
            extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        new_form_search_count = Session.query(FormSearch).count()
        assert new_form_search_count == form_search_count - 1
        assert resp['id'] == form_search_id
        assert response.content_type == 'application/json'

        # Trying to get the deleted form_search from the db should return None
        deleted_form_search = Session.query(FormSearch).get(form_search_id)
        assert deleted_form_search == None

        # Delete with an invalid id
        id = 9999999999999
        response = self.app.delete(url('formsearch', id=id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin,
            status=404)
        assert u'There is no form search with id %s' % id in json.loads(response.body)['error']
        assert response.content_type == 'application/json'

        # Delete without an id
        response = self.app.delete(url('formsearch', id=''), status=404,
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == 'The resource could not be found.'
Beispiel #44
0
    def test_show(self):
        """Tests that GET /speakers/id returns the speaker with id=id or an appropriate error."""

        # Create a speaker to show.
        params = self.speaker_create_params.copy()
        params.update({
            'first_name': u'first_name',
            'last_name': u'last_name',
            'page_content': u'page_content',
            'dialect': u'dialect'
        })
        params = json.dumps(params)
        response = self.app.post(url('speakers'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        speaker_id = resp['id']

        # Try to get a speaker using an invalid id
        id = 100000000000
        response = self.app.get(url('speaker', id=id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin,
                                status=404)
        resp = json.loads(response.body)
        assert u'There is no speaker with id %s' % id in json.loads(
            response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('speaker', id=''),
                                status=404,
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        assert json.loads(
            response.body)['error'] == 'The resource could not be found.'
        assert response.content_type == 'application/json'

        # Valid id
        response = self.app.get(url('speaker', id=speaker_id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['first_name'] == u'first_name'
        assert resp['dialect'] == u'dialect'
        assert response.content_type == 'application/json'
Beispiel #45
0
 def test_new(self):
     """Tests that GET /formsearches/new returns the data necessary to create a new form search."""
     response = self.app.get(url('new_formsearch'),
                             headers=self.json_headers,
                             extra_environ=self.extra_environ_contrib)
     resp = json.loads(response.body)
     assert 'attributes' in resp['search_parameters']
     assert 'relations' in resp['search_parameters']
     assert response.content_type == 'application/json'
Beispiel #46
0
    def test_show(self):
        """Tests that GET /pages/id returns the page with id=id or an appropriate error."""

        # Create a page to show.
        params = self.page_create_params.copy()
        params.update({
            'name': u'page',
            'markup_language': u'Markdown',
            'content': self.md_contents
        })
        params = json.dumps(params)
        response = self.app.post(url('pages'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        page_id = resp['id']

        # Try to get a page using an invalid id
        id = 100000000000
        response = self.app.get(url('page', id=id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin,
                                status=404)
        resp = json.loads(response.body)
        assert u'There is no page with id %s' % id in json.loads(
            response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('page', id=''),
                                status=404,
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        assert json.loads(
            response.body)['error'] == 'The resource could not be found.'
        assert response.content_type == 'application/json'

        # Valid id
        response = self.app.get(url('page', id=page_id),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['name'] == u'page'
        assert resp['content'] == self.md_contents
        assert response.content_type == 'application/json'
Beispiel #47
0
    def test_delete(self):
        """Tests that DELETE /elicitationmethods/id deletes the elicitation_method with id=id."""

        # Create an elicitation method to delete.
        params = json.dumps({'name': u'name', 'description': u'description'})
        response = self.app.post(url('elicitationmethods'), params,
                                 self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        elicitation_method_count = Session.query(ElicitationMethod).count()
        elicitation_method_id = resp['id']

        # Now delete the elicitation method
        response = self.app.delete(url('elicitationmethod',
                                       id=elicitation_method_id),
                                   headers=self.json_headers,
                                   extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        new_elicitation_method_count = Session.query(ElicitationMethod).count()
        assert new_elicitation_method_count == elicitation_method_count - 1
        assert resp['id'] == elicitation_method_id
        assert response.content_type == 'application/json'

        # Trying to get the deleted elicitation method from the db should return None
        deleted_elicitation_method = Session.query(ElicitationMethod).get(
            elicitation_method_id)
        assert deleted_elicitation_method == None

        # Delete with an invalid id
        id = 9999999999999
        response = self.app.delete(url('elicitationmethod', id=id),
                                   headers=self.json_headers,
                                   extra_environ=self.extra_environ_admin,
                                   status=404)
        assert u'There is no elicitation method with id %s' % id in json.loads(
            response.body)['error']
        assert response.content_type == 'application/json'

        # Delete without an id
        response = self.app.delete(url('elicitationmethod', id=''),
                                   status=404,
                                   headers=self.json_headers,
                                   extra_environ=self.extra_environ_admin)
        assert json.loads(
            response.body)['error'] == 'The resource could not be found.'
Beispiel #48
0
    def test_create(self):
        """Tests that POST /speakers creates a new speaker
        or returns an appropriate error if the input is invalid.
        """

        original_speaker_count = Session.query(Speaker).count()

        # Create a valid one
        params = self.speaker_create_params.copy()
        params.update({
            'first_name': u'John',
            'last_name': u'Doe',
            'page_content': u'page_content',
            'dialect': u'dialect'
        })
        params = json.dumps(params)
        response = self.app.post(url('speakers'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        new_speaker_count = Session.query(Speaker).count()
        assert new_speaker_count == original_speaker_count + 1
        assert resp['first_name'] == u'John'
        assert resp['dialect'] == u'dialect'
        assert response.content_type == 'application/json'

        # Invalid because first_name is too long
        params = self.speaker_create_params.copy()
        params.update({
            'first_name': u'John' * 400,
            'last_name': u'Doe',
            'page_content': u'page_content',
            'dialect': u'dialect'
        })
        params = json.dumps(params)
        response = self.app.post(url('speakers'),
                                 params,
                                 self.json_headers,
                                 self.extra_environ_admin,
                                 status=400)
        resp = json.loads(response.body)
        assert resp['errors'][
            'first_name'] == u'Enter a value not more than 255 characters long'
        assert response.content_type == 'application/json'
Beispiel #49
0
    def test_create(self):
        """Tests that POST /syntacticcategories creates a new syntactic category
        or returns an appropriate error if the input is invalid.
        """

        original_SC_count = Session.query(SyntacticCategory).count()

        # Create a valid one
        params = json.dumps({'name': u'sc', 'type': u'lexical', 'description': u'Described.'})
        response = self.app.post(url('syntacticcategories'), params, self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        new_SC_count = Session.query(SyntacticCategory).count()
        assert new_SC_count == original_SC_count + 1
        assert resp['name'] == u'sc'
        assert resp['description'] == u'Described.'
        assert resp['type'] == u'lexical'
        assert response.content_type == 'application/json'

        # Invalid because name is not unique
        params = json.dumps({'name': u'sc', 'type': u'lexical', 'description': u'Described.'})
        response = self.app.post(url('syntacticcategories'), params, self.json_headers, self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        assert resp['errors']['name'] == u'The submitted value for SyntacticCategory.name is not unique.'
        assert response.content_type == 'application/json'

        # Invalid because name is empty
        params = json.dumps({'name': u'', 'type': u'lexical', 'description': u'Described.'})
        response = self.app.post(url('syntacticcategories'), params, self.json_headers, self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        assert resp['errors']['name'] == u'Please enter a value'

        # Invalid because name is too long
        params = json.dumps({'name': u'name' * 400, 'type': u'lexical', 'description': u'Described.'})
        response = self.app.post(url('syntacticcategories'), params, self.json_headers, self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        assert resp['errors']['name'] == u'Enter a value not more than 255 characters long'

        # Invalid because type is not in utils.syntactic_category_types
        params = json.dumps({'name': u'name' * 400, 'type': u'spatial', 'description': u'Described.'})
        response = self.app.post(url('syntacticcategories'), params, self.json_headers, self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        assert resp['errors']['type'] == u"Value must be one of: lexical; phrasal; sentential (not u'spatial')"
        assert response.content_type == 'application/json'
Beispiel #50
0
    def test_logout(self):
        """Tests that GET /login/logout logs the user out."""

        # Logout while logged in.
        response = self.app.get(url(controller='login', action='logout'),
                                headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['authenticated'] == False
        assert response.content_type == 'application/json'

        # Logout while not logged in.
        response = self.app.get(url(controller='login', action='logout'),
                                headers=self.json_headers,
                                status=401)
        resp = json.loads(response.body)
        assert resp[
            'error'] == u'Authentication is required to access this resource.'
        assert response.content_type == 'application/json'
    def test_create(self):
        """Tests that POST /syntacticcategories creates a new syntactic category
        or returns an appropriate error if the input is invalid.
        """

        original_SC_count = Session.query(SyntacticCategory).count()

        # Create a valid one
        params = json.dumps({'name': u'sc', 'type': u'lexical', 'description': u'Described.'})
        response = self.app.post(url('syntacticcategories'), params, self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        new_SC_count = Session.query(SyntacticCategory).count()
        assert new_SC_count == original_SC_count + 1
        assert resp['name'] == u'sc'
        assert resp['description'] == u'Described.'
        assert resp['type'] == u'lexical'
        assert response.content_type == 'application/json'

        # Invalid because name is not unique
        params = json.dumps({'name': u'sc', 'type': u'lexical', 'description': u'Described.'})
        response = self.app.post(url('syntacticcategories'), params, self.json_headers, self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        assert resp['errors']['name'] == u'The submitted value for SyntacticCategory.name is not unique.'
        assert response.content_type == 'application/json'

        # Invalid because name is empty
        params = json.dumps({'name': u'', 'type': u'lexical', 'description': u'Described.'})
        response = self.app.post(url('syntacticcategories'), params, self.json_headers, self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        assert resp['errors']['name'] == u'Please enter a value'

        # Invalid because name is too long
        params = json.dumps({'name': u'name' * 400, 'type': u'lexical', 'description': u'Described.'})
        response = self.app.post(url('syntacticcategories'), params, self.json_headers, self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        assert resp['errors']['name'] == u'Enter a value not more than 255 characters long'

        # Invalid because type is not in utils.syntactic_category_types
        params = json.dumps({'name': u'name' * 400, 'type': u'spatial', 'description': u'Described.'})
        response = self.app.post(url('syntacticcategories'), params, self.json_headers, self.extra_environ_admin, status=400)
        resp = json.loads(response.body)
        assert resp['errors']['type'] == u"Value must be one of: lexical; phrasal; sentential (not u'spatial')"
        assert response.content_type == 'application/json'
Beispiel #52
0
    def test_delete(self):
        """Tests that DELETE /pages/id deletes the page with id=id."""

        # Create a page to delete.
        params = self.page_create_params.copy()
        params.update({
            'name': u'page',
            'markup_language': u'Markdown',
            'content': self.md_contents
        })
        params = json.dumps(params)
        response = self.app.post(url('pages'), params, self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        page_count = Session.query(Page).count()
        page_id = resp['id']

        # Now delete the page
        response = self.app.delete(url('page', id=page_id), headers=self.json_headers,
            extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        new_page_count = Session.query(Page).count()
        assert new_page_count == page_count - 1
        assert resp['id'] == page_id
        assert response.content_type == 'application/json'

        # Trying to get the deleted page from the db should return None
        deleted_page = Session.query(Page).get(page_id)
        assert deleted_page == None
        assert response.content_type == 'application/json'

        # Delete with an invalid id
        id = 9999999999999
        response = self.app.delete(url('page', id=id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin,
            status=404)
        assert u'There is no page with id %s' % id in json.loads(response.body)['error']
        assert response.content_type == 'application/json'

        # Delete without an id
        response = self.app.delete(url('page', id=''), status=404,
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == 'The resource could not be found.'
Beispiel #53
0
    def test_edit(self):
        """Tests that GET /elicitationmethods/id/edit returns a JSON object of data necessary to edit the elicitation method with id=id.

        The JSON object is of the form {'elicitation_method': {...}, 'data': {...}} or
        {'error': '...'} (with a 404 status code) depending on whether the id is
        valid or invalid/unspecified, respectively.
        """

        # Create an elicitation method to edit.
        params = json.dumps({'name': u'name', 'description': u'description'})
        response = self.app.post(url('elicitationmethods'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        elicitation_method_id = resp['id']

        # Not logged in: expect 401 Unauthorized
        response = self.app.get(url('edit_elicitationmethod', id=elicitation_method_id), status=401)
        resp = json.loads(response.body)
        assert resp['error'] == u'Authentication is required to access this resource.'
        assert response.content_type == 'application/json'

        # Invalid id
        id = 9876544
        response = self.app.get(url('edit_elicitationmethod', id=id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin,
            status=404)
        assert u'There is no elicitation method with id %s' % id in json.loads(response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('edit_elicitationmethod', id=''), status=404,
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == \
            'The resource could not be found.'

        # Valid id
        response = self.app.get(url('edit_elicitationmethod', id=elicitation_method_id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['elicitation_method']['name'] == u'name'
        assert resp['data'] == {}
        assert response.content_type == 'application/json'
 def test_index(self):
     """Tests that GET /applicationsettings returns a JSON array of application settings objects."""
     # Add the default application settings.
     application_settings = add_default_application_settings()
     response = self.app.get(url('applicationsettings'),
         headers=self.json_headers, extra_environ=self.extra_environ_admin)
     resp = json.loads(response.body)
     assert len(resp) == 1
     assert resp[0]['object_language_name'] == application_settings.object_language_name
     assert resp[0]['storage_orthography']['name'] == application_settings.storage_orthography.name
     assert resp[0]['unrestricted_users'][0]['role'] == application_settings.unrestricted_users[0].role
Beispiel #55
0
    def test_show(self):
        """Tests that GET /formsearches/id returns the formsearch with id=id or an appropriate error."""

        # Create a form search to show.
        query = {'filter': ['Form', 'transcription', 'regex', u'[a-g]{3,}']}
        params = self.form_search_create_params.copy()
        params.update({
            'name': u'form search',
            'description': u'This one\'s worth saving!',
            'search': query
        })
        params = json.dumps(params)
        response = self.app.post(url('formsearches'), params, self.json_headers, self.extra_environ_admin)
        resp = json.loads(response.body)
        form_search_id = resp['id']
        assert resp['name'] == u'form search'
        assert resp['description'] == u"This one's worth saving!"
        assert resp['search'] == query

        # Try to get a form search using an invalid id
        id = 100000000000
        response = self.app.get(url('formsearch', id=id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin, status=404)
        resp = json.loads(response.body)
        assert u'There is no form search with id %s' % id in json.loads(response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('formsearch', id=''), status=404,
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == 'The resource could not be found.'

        # Valid id
        response = self.app.get(url('formsearch', id=form_search_id), headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['name'] == u'form search'
        assert resp['description'] == u"This one's worth saving!"
        assert response.content_type == 'application/json'
Beispiel #56
0
    def test_show(self):
        """Tests that GET /speakers/id returns the speaker with id=id or an appropriate error."""

        # Create a speaker to show.
        params = self.speaker_create_params.copy()
        params.update({
            'first_name': u'first_name',
            'last_name': u'last_name',
            'page_content': u'page_content',
            'dialect': u'dialect'
        })
        params = json.dumps(params)
        response = self.app.post(url('speakers'), params, self.json_headers,
                                 self.extra_environ_admin)
        resp = json.loads(response.body)
        speaker_id = resp['id']

        # Try to get a speaker using an invalid id
        id = 100000000000
        response = self.app.get(url('speaker', id=id),
            headers=self.json_headers, extra_environ=self.extra_environ_admin,
            status=404)
        resp = json.loads(response.body)
        assert u'There is no speaker with id %s' % id in json.loads(response.body)['error']
        assert response.content_type == 'application/json'

        # No id
        response = self.app.get(url('speaker', id=''), status=404,
            headers=self.json_headers, extra_environ=self.extra_environ_admin)
        assert json.loads(response.body)['error'] == 'The resource could not be found.'
        assert response.content_type == 'application/json'

        # Valid id
        response = self.app.get(url('speaker', id=speaker_id), headers=self.json_headers,
                                extra_environ=self.extra_environ_admin)
        resp = json.loads(response.body)
        assert resp['first_name'] == u'first_name'
        assert resp['dialect'] == u'dialect'
        assert response.content_type == 'application/json'