Esempio n. 1
0
    def test_event_update(self):
        '''Sysadmins can update an existing event'''
        sysadmin = Sysadmin()

        event = factories.Event(name='My Test Event',
                                date='2010-09-21',
                                free=True)

        event_result = toolkit.get_action('event_show')(data_dict={
            'id': event['id']
        })

        nosetools.assert_true(event_result['name'] == 'My Test Event')
        nosetools.assert_true(event_result['date'] == '2010-09-21')
        nosetools.assert_true(event_result['free'])

        updated_event = toolkit.get_action('event_update')(
            context={
                'user': sysadmin['name']
            },
            data_dict={
                'id': event['id'],
                'name': 'My Updated Event',
                'date': '2013-09-21',
                'free': False
            })

        nosetools.assert_true(updated_event['name'] == 'My Updated Event')
        nosetools.assert_true(updated_event['date'] == '2013-09-21 00:00:00')
        nosetools.assert_false(updated_event['free'])
def _get_package_new_page_as_sysadmin(app):
    user = Sysadmin()
    env = {'REMOTE_USER': user['name'].encode('ascii')}
    response = app.get(
        url='/test-schema/new',
        extra_environ=env,
    )
    return env, response
def _get_group_new_page_as_sysadmin(app, type='group'):
    user = Sysadmin()
    env = {'REMOTE_USER': user['name'].encode('ascii')}
    response = app.get(
        url='/{0}/new'.format(type),
        extra_environ=env,
    )
    return env, response
Esempio n. 4
0
def _get_organization_new_page_as_sysadmin(app):
    user = Sysadmin()
    env = {'REMOTE_USER': user['name'].encode('ascii')}
    response = app.get(
        url='/organization/new',
        extra_environ=env,
    )
    return env, response
Esempio n. 5
0
def _get_resource_update_page_as_sysadmin(app, id, resource_id):
    user = Sysadmin()
    env = {"REMOTE_USER": user["name"].encode("ascii")}
    response = app.get(
        url="/dataset/{}/resource_edit/{}".format(id, resource_id),
        extra_environ=env,
    )
    return env, response
def _get_package_update_page_as_sysadmin(app, id):
    user = Sysadmin()
    env = {'REMOTE_USER': user['name'].encode('ascii')}
    response = app.get(
        url='/test-schema/edit/{}'.format(id),
        extra_environ=env,
    )
    return env, response
def _get_resource_update_page_as_sysadmin(app, id, resource_id):
    user = Sysadmin()
    env = {'REMOTE_USER': user['name'].encode('ascii')}
    response = app.get(
        url='/dataset/{}/resource_edit/{}'.format(id, resource_id),
        extra_environ=env,
    )
    return env, response
Esempio n. 8
0
 def test_choice_field_shows_labels(self, app):
     user = Sysadmin()
     Dataset(
         user=user,
         type="test-schema",
         name="with-choice",
         category="hybrid",
     )
     response = app.get("/dataset/with-choice")
     assert "Hybrid Camel" in response.body
Esempio n. 9
0
def _get_resource_new_page_as_sysadmin(app, id):
    user = Sysadmin()
    env = {"REMOTE_USER": user["name"].encode("ascii")}
    if ckantoolkit.check_ckan_version(min_version="2.9"):
        url = '/dataset/{}/resource/new'.format(id)
    else:
        url = '/dataset/new_resource/{}'.format(id)

    response = app.get(url, extra_environ=env)
    return env, response
    def test_group_displays_custom_fields(self):
        user = Sysadmin()
        Group(
            user=user,
            name='group-one',
            bookface='theoneandonly',
        )

        app = self._get_test_app()
        response = app.get(url='/group/about/group-one')
        assert_true('Bookface' in response.body)
Esempio n. 11
0
    def test_notes_field_displayed(self, app):
        user = Sysadmin()
        Dataset(
            user=user,
            type="dataset",
            name="plain-jane",
            notes="# styled notes",
        )

        response = app.get("/dataset/plain-jane")
        assert "<h1>styled notes" in response.body
 def test_notes_field_displayed(self):
     user = Sysadmin()
     d = Dataset(
         user=user,
         type='dataset',
         name='plain-jane',
         notes='# styled notes',
     )
     app = self._get_test_app()
     response = app.get(url='/dataset/plain-jane')
     assert_true('<h1>styled notes' in response.body)
 def test_choice_field_shows_labels(self):
     user = Sysadmin()
     d = Dataset(
         user=user,
         type='camel-photos',
         name='with-choice',
         category='hybrid',
     )
     app = self._get_test_app()
     response = app.get(url='/dataset/with-choice')
     assert_true('Hybrid Camel' in response.body)
    def test_organization_displays_custom_fields(self):
        user = Sysadmin()
        Organization(
            user=user,
            name='org-one',
            department_id='3008',
        )

        app = self._get_test_app()
        response = app.get(url='/organization/about/org-one')
        assert_true('Department ID' in response.body)
Esempio n. 15
0
    def test_event_update_bad_id(self):
        '''Bad event id raises ObjectNotFound.'''
        sysadmin = Sysadmin()

        with nosetools.assert_raises(toolkit.ObjectNotFound):
            toolkit.get_action('event_update')(context={
                'user': sysadmin['name']
            },
                                               data_dict={
                                                   'id': 'bad-id'
                                               })
Esempio n. 16
0
    def test_event_delete_invalid_id(self):
        '''
        Calling event delete with invalid id raises ObjectNotFound.
        '''
        sysadmin = Sysadmin()
        context = {'user': sysadmin['name']}

        with nosetools.assert_raises(toolkit.ObjectNotFound):
            toolkit.get_action('event_delete')(context=context,
                                               data_dict={
                                                   'id': 'blah-blah'
                                               })
    def test_choice_field_does_not_show_list_if_one_options(self):
        user = Sysadmin()
        d = Dataset(
            user=user,
            type='camel-photos',
            name='with-multiple-choice-one',
            personality=['friendly'],
        )
        app = self._get_test_app()
        response = app.get(url='/dataset/with-multiple-choice-one')

        assert_true('Often friendly' in response.body)
        assert_true('<ul><li>Often friendly</li></ul>' not in response.body)
    def test_choice_field_shows_list_if_multiple_options(self, app):
        user = Sysadmin()
        Dataset(
            user=user,
            type="test-schema",
            name="with-multiple-choice-n",
            personality=["friendly", "spits"],
        )

        response = app.get("/dataset/with-multiple-choice-n")

        assert ("<ul><li>Often friendly</li><li>Tends to spit</li></ul>"
                in response.body)
Esempio n. 19
0
    def test_choice_field_does_not_show_list_if_one_options(self, app):
        user = Sysadmin()
        Dataset(
            user=user,
            type="test-schema",
            name="with-multiple-choice-one",
            personality=["friendly"],
        )

        response = app.get("/dataset/with-multiple-choice-one")

        assert "Often friendly" in response.body
        assert "<ul><li>Often friendly</li></ul>" not in response.body
    def test_choice_field_shows_list_if_multiple_options(self):
        user = Sysadmin()
        d = Dataset(
            user=user,
            type='camel-photos',
            name='with-multiple-choice-n',
            personality=['friendly', 'spits'],
        )
        app = self._get_test_app()
        response = app.get(url='/dataset/with-multiple-choice-n')

        assert_true('<ul><li>Often friendly</li><li>Tends to spit</li></ul>' in
                    response.body)
    def test_dataset_displays_custom_fields(self):
        user = Sysadmin()
        Dataset(user=user,
                type='camel-photos',
                name='set-one',
                humps=3,
                resources=[{
                    'url': "http://example.com/camel.txt",
                    'camels_in_photo': 2
                }])

        app = self._get_test_app()
        response = app.get(url='/dataset/set-one')
        assert_true('Humps' in response.body)
Esempio n. 22
0
    def test_event_create(self):
        '''Creating an event returns a dict with expected values'''
        sysadmin = Sysadmin()

        event_result = toolkit.get_action('event_create')(
            context={
                'user': sysadmin['name']
            },
            data_dict=self._make_create_data_dict())

        nosetools.assert_true(isinstance(event_result, dict))
        nosetools.assert_true(event_result['name'] == 'Title')
        nosetools.assert_true(event_result['free'])
        nosetools.assert_true(event_result['date'] == '2012-09-21 00:00:00')
Esempio n. 23
0
    def test_dataset_displays_custom_fields(self, app):
        user = Sysadmin()
        Dataset(
            user=user,
            type="test-schema",
            name="set-one",
            humps=3,

            resources=[
                {"url": "http://example.com/camel.txt", "camels_in_photo": 2}
            ],
        )

        response = app.get("/dataset/set-one")
        assert "Humps" in response.body
    def test_dataset_displays_custom_fields(self):
        user = Sysadmin()
        Dataset(user=user,
                type='test-schema',
                name='set-one',
                humps=3,
                photographer='John Newton',
                photographer_email='*****@*****.**',
                resources=[{
                    'url': "http://example.com/camel.txt",
                    'camels_in_photo': 2
                }])

        app = self._get_test_app()
        response = app.get(url='/dataset/set-one')
        assert_true('Humps' in response.body)
    def test_resource_displays_custom_fields(self):
        user = Sysadmin()
        d = Dataset(user=user,
                    type='camel-photos',
                    name='set-two',
                    humps=3,
                    resources=[{
                        'url': "http://example.com/camel.txt",
                        'camels_in_photo': 2,
                        'date': '2015-01-01'
                    }])

        app = self._get_test_app()
        response = app.get(url='/dataset/set-two/resource/' +
                           d['resources'][0]['id'])
        assert_true('Camels in Photo' in response.body)
        assert_true('Date' in response.body)
    def test_resource_displays_custom_fields(self, app):
        user = Sysadmin()
        d = Dataset(
            user=user,
            type="test-schema",
            name="set-two",
            humps=3,
            resources=[{
                "url": "http://example.com/camel.txt",
                "camels_in_photo": 2,
                "date": "2015-01-01",
            }],
        )

        response = app.get("/dataset/set-two/resource/" +
                           d["resources"][0]["id"])
        assert "Camels in Photo" in response.body
        assert "Date" in response.body
Esempio n. 27
0
    def test_event_delete(self):
        '''
        Sysadmin can delete event.
        '''
        sysadmin = Sysadmin()
        event = factories.Event()

        # one event
        nosetools.assert_equal(Event.count(), 1)

        toolkit.get_action('event_delete')(context={
            'user': sysadmin['name']
        },
                                           data_dict={
                                               'id': event['id']
                                           })

        # No events
        nosetools.assert_equal(Event.count(), 0)
Esempio n. 28
0
    def test_json_field_displayed(self, app):
        user = Sysadmin()
        Dataset(
            user=user,
            type="test-schema",
            name="plain-json",
            a_json_field={"a": "1", "b": "2"},
        )
        response = app.get("/dataset/plain-json")

        if six.PY3:
            expected = """{\n  "a": "1",\n  "b": "2"\n}"""
        else:
            expected = """{\n  "a": "1", \n  "b": "2"\n}"""
        expected = expected.replace(
            '"', "&#34;"
        )  # Ask webhelpers

        assert expected in response.body
        assert "Example JSON" in response.body
    def test_json_field_displayed(self):
        user = Sysadmin()
        d = Dataset(
            user=user,
            type='test-schema',
            name='plain-json',
            a_json_field={
                'a': '1',
                'b': '2'
            },
        )
        app = self._get_test_app()
        response = app.get(url='/dataset/plain-json')

        expected = '''{
  "a": "1", 
  "b": "2"
}'''.replace('"', '&#34;')  # Ask webhelpers

        assert_in(expected, response.body)
        assert_in('Example JSON', response.body)
Esempio n. 30
0
    def test_organization_displays_custom_fields(self, app):
        user = Sysadmin()
        Organization(user=user, name="org-one", department_id="3008")

        response = app.get("/organization/about/org-one")
        assert "Department ID" in response.body