Skip to content

Commit

Permalink
test array and nested types
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Oct 3, 2012
1 parent b7ab1f9 commit 0f223be
Showing 1 changed file with 25 additions and 15 deletions.
40 changes: 25 additions & 15 deletions ckanext/datastore/tests/test_datastore.py
Expand Up @@ -601,13 +601,14 @@ def setup_class(cls):
'resource_id': resource.id,
'fields': [{'id': u'b\xfck', 'type': 'text'},
{'id': 'author', 'type': 'text'},
{'id': 'characters', 'type': 'json'},
{'id': 'nested', 'type': 'json'},
{'id': 'characters', 'type': 'text[]'},
{'id': 'published'}],
'primary_key': u'b\xfck',
'records': [{u'b\xfck': 'annakarenina', 'author': 'tolstoy',
'published': '2005-03-01', 'characters': ['b', {'moo': 'moo'}]},
'published': '2005-03-01', 'nested': ['b', {'moo': 'moo'}]},
{u'b\xfck': 'warandpeace', 'author': 'tolstoy',
'characters': {'a':'b'}}
'nested': {'a':'b'}}
]
}
postparams = '%s=1' % json.dumps(cls.data)
Expand Down Expand Up @@ -659,7 +660,9 @@ def test_upsert_basic(self):
'method': 'upsert',
'records': [{
'author': 'adams',
'characters': {'main': 'Arthur Dent', 'other': 'Marvin'},
'nested': {'a': 2, 'b': {'c': 'd'}},
'characters': ['Arthur Dent', 'Marvin'],
'nested': {'foo': 'bar'},
u'b\xfck': hhguide}]
}

Expand All @@ -678,7 +681,8 @@ def test_upsert_basic(self):
records = results.fetchall()
assert records[2][u'b\xfck'] == hhguide
assert records[2].author == 'adams'
assert json.loads(records[2].characters.json) == {'main': 'Arthur Dent', 'other': 'Marvin'}
assert records[2].characters == ['Arthur Dent', 'Marvin']
assert json.loads(records[2].nested.json) == {'foo': 'bar'}
self.Session.remove()

c = self.Session.connection()
Expand Down Expand Up @@ -821,13 +825,14 @@ def setup_class(cls):
'resource_id': resource.id,
'fields': [{'id': u'b\xfck', 'type': 'text'},
{'id': 'author', 'type': 'text'},
{'id': 'characters', 'type': 'json'},
{'id': 'nested', 'type': 'json'},
{'id': 'characters', 'type': 'text[]'},
{'id': 'published'}],
'primary_key': u'b\xfck',
'records': [{u'b\xfck': 'annakarenina', 'author': 'tolstoy',
'published': '2005-03-01', 'characters': ['b', {'moo': 'moo'}]},
'published': '2005-03-01', 'nested': ['b', {'moo': 'moo'}]},
{u'b\xfck': 'warandpeace', 'author': 'tolstoy',
'characters': {'a':'b'}}
'nested': {'a':'b'}}
]
}
postparams = '%s=1' % json.dumps(cls.data)
Expand Down Expand Up @@ -855,7 +860,8 @@ def test_insert_basic(self):
'method': 'insert',
'records': [{
'author': 'adams',
'characters': {'main': 'Arthur Dent', 'other': 'Marvin'},
'characters': ['Arthur Dent', 'Marvin'],
'nested': {'foo': 'bar', 'baz': 3},
u'b\xfck': hhguide}]
}

Expand Down Expand Up @@ -906,16 +912,19 @@ def setup_class(cls):
'resource_id': resource.id,
'fields': [{'id': u'b\xfck', 'type': 'text'},
{'id': 'author', 'type': 'text'},
{'id': 'characters', 'type': 'json'},
{'id': 'nested', 'type': 'json'},
{'id': 'characters', 'type': 'text[]'},
{'id': 'published'}],
'primary_key': u'b\xfck',
'records': [{u'b\xfck': 'annakarenina', 'author': 'tolstoy',
'published': '2005-03-01', 'characters': ['b', {'moo': 'moo'}]},
'published': '2005-03-01', 'nested': ['b', {'moo': 'moo'}]},
{u'b\xfck': 'warandpeace', 'author': 'tolstoy',
'characters': {'a':'b'}},
'nested': {'a':'b'}},
{'author': 'adams',
'characters': {'main': 'Arthur Dent', 'other': 'Marvin'},
u'b\xfck': hhguide}]
'characters': ['Arthur Dent', 'Marvin'],
'nested': {'foo': 'bar'},
u'b\xfck': hhguide}
]
}
postparams = '%s=1' % json.dumps(cls.data)
auth = {'Authorization': str(cls.sysadmin_user.apikey)}
Expand Down Expand Up @@ -947,7 +956,8 @@ def test_update_basic(self):
'method': 'update',
'records': [{
'author': 'adams',
'characters': {'main': 'Arthur Dent', 'other': 'Marvin'},
'characters': ['Arthur Dent', 'Marvin'],
'nested': {'baz': 3},
u'b\xfck': hhguide}]
}

Expand Down

0 comments on commit 0f223be

Please sign in to comment.