Exemplo n.º 1
0
    def test_simple_call_with_defaults(self, LocalCKAN):
        lc = Mock()
        lc.action.datastore_search.return_value = {
            'fields': [{
                'id': '_id'
            }, {
                'id': 'a'
            }, {
                'id': 'b'
            }],
            'records': [{
                'a': 'one',
                'b': 'two'
            }, {
                'a': 'three',
                'b': 'four'
            }],
        }
        LocalCKAN.return_value = lc
        assert_equals(
            scheming_datastore_choices(
                {'datastore_choices_resource': 'simple-one'}), [{
                    'value': 'one',
                    'label': 'two'
                }, {
                    'value': 'three',
                    'label': 'four'
                }])

        LocalCKAN.asset_called_once_with(username='')
        lc.action.datastore_search.assert_called_once_with(
            resource_id='simple-one', limit=1000, fields=None)
Exemplo n.º 2
0
    def test_call_with_all_params(self, LocalCKAN):
        lc = Mock()
        lc.action.datastore_search.return_value = {
            'records': [{
                'a': 'one',
                'b': 'two'
            }, {
                'a': 'three',
                'b': 'four'
            }],
        }
        LocalCKAN.return_value = lc
        assert_equals(
            scheming_datastore_choices({
                'datastore_choices_resource': 'all-params',
                'datastore_choices_limit': 5,
                'datastore_choices_columns': {
                    'value': 'a',
                    'label': 'b'
                }
            }), [{
                'value': 'one',
                'label': 'two'
            }, {
                'value': 'three',
                'label': 'four'
            }])

        LocalCKAN.asset_called_once_with(username='')
        lc.action.datastore_search.assert_called_once_with(
            resource_id='all-params', limit=5, fields=['a', 'b'])
Exemplo n.º 3
0
 def test_no_choices_on_not_found(self, LocalCKAN):
     lc = Mock()
     lc.action.datastore_search.side_effect = NotFound()
     LocalCKAN.return_value = lc
     assert_equals(scheming_datastore_choices(
         {'datastore_choices_resource': 'not-found'}), [])
     lc.action.datastore_search.assert_called_once()
Exemplo n.º 4
0
 def test_no_choices_on_not_found(self, LocalCKAN):
     lc = Mock()
     lc.action.datastore_search.side_effect = NotFound()
     LocalCKAN.return_value = lc
     assert_equals(scheming_datastore_choices(
         {'datastore_choices_resource': 'not-found'}), [])
     lc.action.datastore_search.assert_called_once()
Exemplo n.º 5
0
    def test_call_with_all_params(self, LocalCKAN):
        lc = Mock()
        lc.action.datastore_search.return_value = {
            "records": [{
                "a": "one",
                "b": "two"
            }, {
                "a": "three",
                "b": "four"
            }]
        }
        LocalCKAN.return_value = lc
        assert scheming_datastore_choices({
            "datastore_choices_resource": "all-params",
            "datastore_choices_limit": 5,
            "datastore_choices_columns": {
                "value": "a",
                "label": "b"
            },
        }) == [
            {
                "value": "one",
                "label": "two"
            },
            {
                "value": "three",
                "label": "four"
            },
        ]

        LocalCKAN.asset_called_once_with(username="")
        lc.action.datastore_search.assert_called_once_with(
            resource_id="all-params", limit=5, fields=["a", "b"])
Exemplo n.º 6
0
    def test_simple_call_with_defaults(self, LocalCKAN):
        lc = Mock()
        lc.action.datastore_search.return_value = {
            "fields": [{
                "id": "_id"
            }, {
                "id": "a"
            }, {
                "id": "b"
            }],
            "records": [{
                "a": "one",
                "b": "two"
            }, {
                "a": "three",
                "b": "four"
            }],
        }
        LocalCKAN.return_value = lc
        assert scheming_datastore_choices(
            {"datastore_choices_resource": "simple-one"}) == [
                {
                    "value": "one",
                    "label": "two"
                },
                {
                    "value": "three",
                    "label": "four"
                },
            ]

        LocalCKAN.asset_called_once_with(username="")
        lc.action.datastore_search.assert_called_once_with(
            resource_id="simple-one", limit=1000, fields=None)
Exemplo n.º 7
0
 def test_no_choices_on_not_authorized(self, LocalCKAN):
     lc = Mock()
     lc.action.datastore_search.side_effect = NotFound()
     LocalCKAN.return_value = lc
     assert (scheming_datastore_choices(
         {"datastore_choices_resource": "not-allowed"}) == [])
     lc.action.datastore_search.assert_called_once()
Exemplo n.º 8
0
    def test_simple_call_with_defaults(self, LocalCKAN):
        lc = Mock()
        lc.action.datastore_search.return_value = {
            'fields': [{'id': '_id'}, {'id': 'a'}, {'id': 'b'}],
            'records': [{'a': 'one', 'b': 'two'}, {'a': 'three', 'b': 'four'}],
            }
        LocalCKAN.return_value = lc
        assert_equals(scheming_datastore_choices(
            {'datastore_choices_resource': 'simple-one'}),
            [{'value': 'one', 'label': 'two'}, {'value': 'three', 'label': 'four'}])

        LocalCKAN.asset_called_once_with(username='')
        lc.action.datastore_search.assert_called_once_with(
            resource_id='simple-one',
            limit=1000,
            fields=None)
Exemplo n.º 9
0
    def test_call_with_all_params(self, LocalCKAN):
        lc = Mock()
        lc.action.datastore_search.return_value = {
            'records': [{'a': 'one', 'b': 'two'}, {'a': 'three', 'b': 'four'}],
            }
        LocalCKAN.return_value = lc
        assert_equals(
            scheming_datastore_choices({
                'datastore_choices_resource': 'all-params',
                'datastore_choices_limit': 5,
                'datastore_choices_columns': {'value': 'a', 'label': 'b'}}),
            [{'value': 'one', 'label': 'two'}, {'value': 'three', 'label': 'four'}])

        LocalCKAN.asset_called_once_with(username='')
        lc.action.datastore_search.assert_called_once_with(
            resource_id='all-params',
            limit=5,
            fields=['a', 'b'])