Created
December 23, 2014 12:48
-
-
Save davidread/5a229795dada6681ed0c to your computer and use it in GitHub Desktop.
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
import nose.tools | |
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): | |
model.repo.rebuild_db() | |
def setup(self): | |
model.repo.rebuild_db() | |
def test_edit_url(self): | |
res = model.Resource(package_id='fake', url='http://first') | |
model.Session.add(res) | |
model.repo.new_revision() | |
model.Session.flush() | |
res_id = res.id | |
model.repo.commit_and_remove() | |
res = model.Resource.get(res_id) | |
res.url = 'http://second' | |
model.repo.new_revision() | |
model.repo.commit_and_remove() | |
res = Resource.get(res_id) | |
assert_equals(res.url, 'http://second') | |
def test_edit_extra(self): | |
res = model.Resource(package_id='fake', extras={'newfield': 'first'}) | |
model.Session.add(res) | |
model.repo.new_revision() | |
model.Session.flush() | |
res_id = res.id | |
model.repo.commit_and_remove() | |
res = model.Resource.get(res_id) | |
res.extras['newfield'] = 'second' | |
model.repo.new_revision() | |
print 'KEY FLUSH' | |
model.repo.commit_and_remove() | |
res = model.Resource.get(res_id) | |
assert_equals(res.extras['newfield'], 'second') | |
def test_edit_url_and_extra(self): | |
res = model.Resource(package_id='fake', url='http://first', extras={'newfield': 'first'}) | |
model.Session.add(res) | |
model.repo.new_revision() | |
model.Session.flush() | |
res_id = res.id | |
model.repo.commit_and_remove() | |
res = model.Resource.get(res_id) | |
res.url = 'http://second' | |
res.extras['newfield'] = 'second' | |
model.repo.new_revision() | |
print 'KEY FLUSH' | |
model.repo.commit_and_remove() | |
res = model.Resource.get(res_id) | |
assert_equals(res.url, 'http://second') | |
assert_equals(res.extras['newfield'], 'second') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment