|
43 | 43 | from unidecode import unidecode |
44 | 44 | from werkzeug.utils import secure_filename |
45 | 45 | from nose.tools import assert_raises |
| 46 | +from flatten_json import flatten |
46 | 47 |
|
47 | 48 |
|
48 | 49 | class TestWeb(web.Helper): |
@@ -4267,29 +4268,30 @@ def test_export_task_csv(self): |
4267 | 4268 | assert len(exported_tasks) == len(project.tasks), err_msg |
4268 | 4269 | for t in project.tasks: |
4269 | 4270 | err_msg = "All the task column names should be included" |
4270 | | - for tk in t.dictize().keys(): |
4271 | | - expected_key = "task__%s" % tk |
| 4271 | + for tk in flatten(t.dictize()).keys(): |
| 4272 | + expected_key = "%s" % tk |
4272 | 4273 | assert expected_key in keys, err_msg |
4273 | 4274 | err_msg = "All the task.info column names should be included" |
4274 | 4275 | for tk in t.info.keys(): |
4275 | | - expected_key = "taskinfo__%s" % tk |
| 4276 | + expected_key = "info_%s" % tk |
4276 | 4277 | assert expected_key in keys, err_msg |
4277 | 4278 |
|
4278 | 4279 | for et in exported_tasks: |
4279 | | - task_id = et[keys.index('task__id')] |
| 4280 | + task_id = et[keys.index('id')] |
4280 | 4281 | task = db.session.query(Task).get(task_id) |
| 4282 | + task_dict_flat = flatten(task.dictize()) |
4281 | 4283 | task_dict = task.dictize() |
4282 | | - for k in task_dict: |
4283 | | - slug = 'task__%s' % k |
4284 | | - err_msg = "%s != %s" % (task_dict[k], et[keys.index(slug)]) |
4285 | | - if k != 'info': |
4286 | | - assert unicode(task_dict[k]) == et[keys.index(slug)], err_msg |
| 4284 | + for k in task_dict_flat.keys(): |
| 4285 | + slug = '%s' % k |
| 4286 | + err_msg = "%s != %s" % (task_dict_flat[k], et[keys.index(slug)]) |
| 4287 | + if task_dict_flat[k] is not None: |
| 4288 | + assert unicode(task_dict_flat[k]) == et[keys.index(slug)], err_msg |
4287 | 4289 | else: |
4288 | | - assert json.dumps(task_dict[k]) == et[keys.index(slug)], err_msg |
| 4290 | + assert u'' == et[keys.index(slug)], err_msg |
4289 | 4291 | for k in task_dict['info'].keys(): |
4290 | | - slug = 'taskinfo__%s' % k |
| 4292 | + slug = 'info_%s' % k |
4291 | 4293 | err_msg = "%s != %s" % (task_dict['info'][k], et[keys.index(slug)]) |
4292 | | - assert unicode(task_dict['info'][k]) == et[keys.index(slug)], err_msg |
| 4294 | + assert unicode(task_dict_flat[slug]) == et[keys.index(slug)], err_msg |
4293 | 4295 | # Tasks are exported as an attached file |
4294 | 4296 | content_disposition = 'attachment; filename=%d_project1_task_csv.zip' % project.id |
4295 | 4297 | assert res.headers.get('Content-Disposition') == content_disposition, res.headers |
@@ -4363,28 +4365,21 @@ def test_53_export_task_runs_csv(self): |
4363 | 4365 | assert len(exported_task_runs) == len(project.task_runs), err_msg |
4364 | 4366 |
|
4365 | 4367 | for t in project.tasks[0].task_runs: |
4366 | | - for tk in t.dictize().keys(): |
4367 | | - expected_key = "task_run__%s" % tk |
4368 | | - assert expected_key in keys, expected_key |
4369 | | - for tk in t.info.keys(): |
4370 | | - expected_key = "task_runinfo__%s" % tk |
| 4368 | + for tk in flatten(t.dictize()).keys(): |
| 4369 | + expected_key = "%s" % tk |
4371 | 4370 | assert expected_key in keys, expected_key |
4372 | 4371 |
|
4373 | 4372 | for et in exported_task_runs: |
4374 | | - task_run_id = et[keys.index('task_run__id')] |
| 4373 | + task_run_id = et[keys.index('id')] |
4375 | 4374 | task_run = db.session.query(TaskRun).get(task_run_id) |
4376 | | - task_run_dict = task_run.dictize() |
| 4375 | + task_run_dict = flatten(task_run.dictize()) |
4377 | 4376 | for k in task_run_dict: |
4378 | | - slug = 'task_run__%s' % k |
| 4377 | + slug = '%s' % k |
4379 | 4378 | err_msg = "%s != %s" % (task_run_dict[k], et[keys.index(slug)]) |
4380 | | - if k != 'info': |
| 4379 | + if task_run_dict[k] is not None: |
4381 | 4380 | assert unicode(task_run_dict[k]) == et[keys.index(slug)], err_msg |
4382 | 4381 | else: |
4383 | | - assert json.dumps(task_run_dict[k]) == et[keys.index(slug)], err_msg |
4384 | | - for k in task_run_dict['info'].keys(): |
4385 | | - slug = 'task_runinfo__%s' % k |
4386 | | - err_msg = "%s != %s" % (task_run_dict['info'][k], et[keys.index(slug)]) |
4387 | | - assert unicode(task_run_dict['info'][k]) == et[keys.index(slug)], err_msg |
| 4382 | + assert u'' == et[keys.index(slug)], err_msg |
4388 | 4383 | # Task runs are exported as an attached file |
4389 | 4384 | content_disposition = 'attachment; filename=%d_project1_task_run_csv.zip' % project.id |
4390 | 4385 | assert res.headers.get('Content-Disposition') == content_disposition, res.headers |
|
0 commit comments