Skip to content

Instantly share code, notes, and snippets.

@davidread
Created December 23, 2014 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidread/5a229795dada6681ed0c to your computer and use it in GitHub Desktop.
Save davidread/5a229795dada6681ed0c to your computer and use it in GitHub Desktop.
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