-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[master][#1623]: CSV/JSON dumps to excludes deleted objects. Also add…
…ed first CLI test!
- Loading branch information
David Read
committed
Jan 18, 2012
1 parent
8314e97
commit c2c3427
Showing
2 changed files
with
47 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import os | ||
import csv | ||
|
||
from nose.tools import assert_equal | ||
|
||
from ckan import model | ||
from ckan.lib.cli import ManageDb | ||
from ckan.lib.create_test_data import CreateTestData | ||
from ckan.lib.helpers import json | ||
|
||
class TestDb: | ||
@classmethod | ||
def setup_class(cls): | ||
cls.db = ManageDb('db') | ||
CreateTestData.create() | ||
|
||
# delete warandpeace | ||
rev = model.repo.new_revision() | ||
model.Package.by_name(u'warandpeace').delete() | ||
model.repo.commit_and_remove() | ||
|
||
def test_simple_dump_csv(self): | ||
csv_filepath = '/tmp/dump.tmp' | ||
self.db.args = ('simple-dump-csv %s' % csv_filepath).split() | ||
self.db.simple_dump_csv() | ||
assert os.path.exists(csv_filepath), csv_filepath | ||
f_obj = open(csv_filepath, "r") | ||
reader = csv.reader(f_obj) | ||
rows = [row for row in reader] | ||
assert_equal(rows[0][:3], ['id', 'name', 'title']) | ||
pkg_names = set(row[1] for row in rows[1:]) | ||
assert 'annakarenina' in pkg_names, pkg_names | ||
assert 'warandpeace' not in pkg_names, pkg_names | ||
|
||
def test_simple_dump_json(self): | ||
json_filepath = '/tmp/dump.tmp' | ||
self.db.args = ('simple-dump-json %s' % json_filepath).split() | ||
self.db.simple_dump_json() | ||
assert os.path.exists(json_filepath), json_filepath | ||
f_obj = open(json_filepath, "r") | ||
rows = json.loads(f_obj.read()) | ||
assert set(rows[0].keys()) > set(('id', 'name', 'title')), rows[0].keys() | ||
pkg_names = set(row['name'] for row in rows) | ||
assert 'annakarenina' in pkg_names, pkg_names | ||
assert 'warandpeace' not in pkg_names, pkg_names |