comparison test/rest_common.py @ 6256:29c6dc8ed004

Test handling of unset transitive link field. Test changeset p5b66c480f71f by adding a new link to issue to the user class. Without the changeset, modifying testGetTransitive to include: cgi.MiniFieldStorage('@fields', 'status,assignedto.issue') results in: {'error': {'status': 404, 'msg': IndexError('no such user None',)}} (Note this is the wrong error message, it's not user that is None, it's None value for the issue link in the user object.) With the changeset and modfying expected output to include the new field, I get a passing test with output like: { 'id': '2', 'link': base_path + 'issue/2', 'assignedto.issue': None, 'status': { 'id': '10', 'link': base_path + 'status/10' } }, Changing the schema also requires changes to the etag testing code since it uses the user object and the representation has changed.
author John Rouillard <rouilj@ieee.org>
date Thu, 20 Aug 2020 23:28:24 -0400
parents 1cb2375015f0
children be8d5a8e090a
comparison
equal deleted inserted replaced
6255:8f8bb7465cd6 6256:29c6dc8ed004
213 self.db.issue.addprop(tx_Source=hyperdb.String()) 213 self.db.issue.addprop(tx_Source=hyperdb.String())
214 self.db.issue.addprop(anint=hyperdb.Integer()) 214 self.db.issue.addprop(anint=hyperdb.Integer())
215 self.db.issue.addprop(afloat=hyperdb.Number()) 215 self.db.issue.addprop(afloat=hyperdb.Number())
216 self.db.issue.addprop(abool=hyperdb.Boolean()) 216 self.db.issue.addprop(abool=hyperdb.Boolean())
217 self.db.issue.addprop(requireme=hyperdb.String(required=True)) 217 self.db.issue.addprop(requireme=hyperdb.String(required=True))
218 self.db.user.addprop(issue=hyperdb.Link('issue'))
218 self.db.msg.addprop(tx_Source=hyperdb.String()) 219 self.db.msg.addprop(tx_Source=hyperdb.String())
219 220
220 self.db.post_init() 221 self.db.post_init()
221 222
222 thisdir = os.path.dirname(__file__) 223 thisdir = os.path.dirname(__file__)
357 expected={'data': 358 expected={'data':
358 {'@total_size': 2, 359 {'@total_size': 2,
359 'collection': [ 360 'collection': [
360 { 'id': '2', 361 { 'id': '2',
361 'link': base_path + 'issue/2', 362 'link': base_path + 'issue/2',
363 'assignedto.issue': None,
362 'status': 364 'status':
363 { 'id': '10', 365 { 'id': '10',
364 'link': base_path + 'status/10' 366 'link': base_path + 'status/10'
365 } 367 }
366 }, 368 },
367 { 'id': '1', 369 { 'id': '1',
368 'link': base_path + 'issue/1', 370 'link': base_path + 'issue/1',
371 'assignedto.issue': None,
369 'status': 372 'status':
370 { 'id': '9', 373 { 'id': '9',
371 'link': base_path + 'status/9' 374 'link': base_path + 'status/9'
372 } 375 }
373 }, 376 },
374 ]} 377 ]}
375 } 378 }
376 form = cgi.FieldStorage() 379 form = cgi.FieldStorage()
377 form.list = [ 380 form.list = [
378 cgi.MiniFieldStorage('status.name', 'o'), 381 cgi.MiniFieldStorage('status.name', 'o'),
379 cgi.MiniFieldStorage('@fields', 'status'), 382 cgi.MiniFieldStorage('@fields', 'status,assignedto.issue'),
380 cgi.MiniFieldStorage('@sort', 'status.name'), 383 cgi.MiniFieldStorage('@sort', 'status.name'),
381 ] 384 ]
382 results = self.server.get_collection('issue', form) 385 results = self.server.get_collection('issue', form)
383 self.assertDictEqual(expected, results) 386 self.assertDictEqual(expected, results)
384 387
1137 node = self.db.user.getnode(newuser) 1140 node = self.db.user.getnode(newuser)
1138 etag = calculate_etag(node, self.db.config['WEB_SECRET_KEY']) 1141 etag = calculate_etag(node, self.db.config['WEB_SECRET_KEY'])
1139 items = node.items(protected=True) # include every item 1142 items = node.items(protected=True) # include every item
1140 print(repr(sorted(items))) 1143 print(repr(sorted(items)))
1141 print(etag) 1144 print(etag)
1142 self.assertEqual(etag, '"0433784660a141e8262835171e70fd2f"') 1145 self.assertEqual(etag, '"07c3a7f214d394cf46220e294a5a53c8"')
1143 1146
1144 # modify key and verify we have a different etag 1147 # modify key and verify we have a different etag
1145 etag = calculate_etag(node, self.db.config['WEB_SECRET_KEY'] + "a") 1148 etag = calculate_etag(node, self.db.config['WEB_SECRET_KEY'] + "a")
1146 items = node.items(protected=True) # include every item 1149 items = node.items(protected=True) # include every item
1147 print(repr(sorted(items))) 1150 print(repr(sorted(items)))
1148 print(etag) 1151 print(etag)
1149 self.assertNotEqual(etag, '"0433784660a141e8262835171e70fd2f"') 1152 self.assertNotEqual(etag, '"07c3a7f214d394cf46220e294a5a53c8"')
1150 1153
1151 # change data and verify we have a different etag 1154 # change data and verify we have a different etag
1152 node.username="Paul" 1155 node.username="Paul"
1153 etag = calculate_etag(node, self.db.config['WEB_SECRET_KEY']) 1156 etag = calculate_etag(node, self.db.config['WEB_SECRET_KEY'])
1154 items = node.items(protected=True) # include every item 1157 items = node.items(protected=True) # include every item
1155 print(repr(sorted(items))) 1158 print(repr(sorted(items)))
1156 print(etag) 1159 print(etag)
1157 self.assertEqual(etag, '"8abeacd284d58655c620d60389e29d4d"') 1160 self.assertEqual(etag, '"d655801d3a6d51e32891531b06ccecfa"')
1158 finally: 1161 finally:
1159 date.Date = originalDate 1162 date.Date = originalDate
1160 1163
1161 def testEtagProcessing(self): 1164 def testEtagProcessing(self):
1162 ''' 1165 '''

Roundup Issue Tracker: http://roundup-tracker.org/