Skip to content

Commit

Permalink
Test nested upsert/update
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Oct 3, 2012
1 parent c97e6ec commit 2d966fb
Showing 1 changed file with 27 additions and 15 deletions.
42 changes: 27 additions & 15 deletions ckanext/datastore/tests/test_datastore.py
Expand Up @@ -601,14 +601,15 @@ def setup_class(cls):
'resource_id': resource.id,
'fields': [{'id': u'b\xfck', 'type': 'text'},
{'id': 'author', 'type': 'text'},
{'id': 'characters', 'type': 'json'},
{'id': 'published'}],
'primary_key': u'b\xfck',
'records': [{u'b\xfck': 'annakarenina', 'author': 'tolstoy',
'published': '2005-03-01', 'nested': ['b', {'moo': 'moo'}]},
'published': '2005-03-01', 'characters': ['b', {'moo': 'moo'}]},
{u'b\xfck': 'warandpeace', 'author': 'tolstoy',
'nested': {'a':'b'}}
'characters': {'a':'b'}}
]
}
}
postparams = '%s=1' % json.dumps(cls.data)
auth = {'Authorization': str(cls.sysadmin_user.apikey)}
res = cls.app.post('/api/action/datastore_create', params=postparams,
Expand Down Expand Up @@ -656,7 +657,10 @@ def test_upsert_basic(self):
data = {
'resource_id': self.data['resource_id'],
'method': 'upsert',
'records': [{'author': 'adams', u'b\xfck': hhguide}]
'records': [{
'author': 'adams',
'characters': {'main': 'Arthur Dent', 'other': 'Marvin'},
u'b\xfck': hhguide}]
}

postparams = '%s=1' % json.dumps(data)
Expand All @@ -674,6 +678,7 @@ def test_upsert_basic(self):
records = results.fetchall()
assert records[2][u'b\xfck'] == hhguide
assert records[2].author == 'adams'
assert records[2].characters == None
self.Session.remove()

c = self.Session.connection()
Expand Down Expand Up @@ -816,14 +821,15 @@ def setup_class(cls):
'resource_id': resource.id,
'fields': [{'id': u'b\xfck', 'type': 'text'},
{'id': 'author', 'type': 'text'},
{'id': 'characters', 'type': 'json'},
{'id': 'published'}],
'primary_key': u'b\xfck',
'records': [{u'b\xfck': 'annakarenina', 'author': 'tolstoy',
'published': '2005-03-01', 'nested': ['b', {'moo': 'moo'}]},
'published': '2005-03-01', 'characters': ['b', {'moo': 'moo'}]},
{u'b\xfck': 'warandpeace', 'author': 'tolstoy',
'nested': {'a':'b'}}
'characters': {'a':'b'}}
]
}
}
postparams = '%s=1' % json.dumps(cls.data)
auth = {'Authorization': str(cls.sysadmin_user.apikey)}
res = cls.app.post('/api/action/datastore_create', params=postparams,
Expand All @@ -843,10 +849,14 @@ def teardown_class(cls):
rebuild_all_dbs(cls.Session)

def test_insert_basic(self):
hhguide = u"hitchhiker's guide to the galaxy"
data = {
'resource_id': self.data['resource_id'],
'method': 'insert',
'records': [{u'b\xfck': 'hitchhikers guide to the galaxy', 'author': 'tolstoy'}]
'records': [{
'author': 'adams',
'characters': {'main': 'Arthur Dent', 'other': 'Marvin'},
u'b\xfck': hhguide}]
}

postparams = '%s=1' % json.dumps(data)
Expand Down Expand Up @@ -895,15 +905,15 @@ def setup_class(cls):
'resource_id': resource.id,
'fields': [{'id': u'b\xfck', 'type': 'text'},
{'id': 'author', 'type': 'text'},
{'id': 'characters', 'type': 'json'},
{'id': 'published'}],
'primary_key': u'b\xfck',
'records': [{u'b\xfck': 'annakarenina', 'author': 'tolstoy',
'published': '2005-03-01', 'nested': ['b', {'moo': 'moo'}]},
'published': '2005-03-01', 'characters': ['b', {'moo': 'moo'}]},
{u'b\xfck': 'warandpeace', 'author': 'tolstoy',
'nested': {'a':'b'}},
{u'b\xfck': 'hitchhikers guide to the galaxy', 'author': 'tolstoy'}
'characters': {'a':'b'}}
]
}
}
postparams = '%s=1' % json.dumps(cls.data)
auth = {'Authorization': str(cls.sysadmin_user.apikey)}
res = cls.app.post('/api/action/datastore_create', params=postparams,
Expand All @@ -928,12 +938,14 @@ def test_update_basic(self):
assert results.rowcount == 3
self.Session.remove()

hhguide = u"hitchhikers guide to the galaxy"

hhguide = u"hitchhiker's guide to the galaxy"
data = {
'resource_id': self.data['resource_id'],
'method': 'update',
'records': [{'author': 'adams', u'b\xfck': hhguide}]
'records': [{
'author': 'adams',
'characters': {'main': 'Arthur Dent', 'other': 'Marvin'},
u'b\xfck': hhguide}]
}

postparams = '%s=1' % json.dumps(data)
Expand Down

0 comments on commit 2d966fb

Please sign in to comment.