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)
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'])
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()
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()
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"])
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)
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()
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)
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'])