Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1251] Refactor cli.py moving SQL queries to Resource model
I've also used SQLAlchemy instead of writing bare SQL.
- Loading branch information
1 parent
fd71934
commit 4577c24
Showing
3 changed files
with
78 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import nose.tools | ||
|
||
import ckan.new_tests.helpers as helpers | ||
import ckan.new_tests.factories as factories | ||
import ckan.model as model | ||
|
||
assert_equals = nose.tools.assert_equals | ||
assert_not_equals = nose.tools.assert_not_equals | ||
Resource = model.Resource | ||
|
||
|
||
class TestResource(object): | ||
@classmethod | ||
def setup_class(cls): | ||
helpers.reset_db() | ||
|
||
def setup(self): | ||
model.repo.rebuild_db() | ||
|
||
def test_get_all_without_views_returns_all_resources_without_views(self): | ||
# Create resource with resource_view | ||
factories.ResourceView() | ||
|
||
expected_resources = [ | ||
factories.Resource(format='format'), | ||
factories.Resource(format='other_format') | ||
] | ||
|
||
resources = Resource.get_all_without_views() | ||
|
||
expected_resources_ids = [r['id'] for r in expected_resources] | ||
resources_ids = [r.id for r in resources] | ||
|
||
assert_equals(expected_resources_ids.sort(), resources_ids.sort()) | ||
|
||
def test_get_all_without_views_accepts_list_of_formats_ignoring_case(self): | ||
factories.Resource(format='other_format') | ||
resource_id = factories.Resource(format='format')['id'] | ||
|
||
resources = Resource.get_all_without_views(['FORMAT']) | ||
|
||
length = len(resources) | ||
assert length == 1, 'Expected 1 resource, but got %d' % length | ||
assert_equals([resources[0].id], [resource_id]) |