|
10 | 10 |
|
11 | 11 | import xlrd |
12 | 12 | from backports import csv |
13 | | -# from path import TempDir |
| 13 | +from path import TempDir |
14 | 14 |
|
15 | 15 | from formpack import FormPack |
16 | 16 | from formpack.constants import UNTRANSLATED |
@@ -1366,52 +1366,52 @@ def test_export_with_split_fields(self): |
1366 | 1366 |
|
1367 | 1367 | self.assertEqual(export, expected) |
1368 | 1368 |
|
1369 | | - # def test_xlsx(self): |
1370 | | - # title, schemas, submissions = build_fixture('grouped_repeatable') |
1371 | | - # fp = FormPack(schemas, title) |
1372 | | - # options = {'versions': 'rgv1'} |
| 1369 | + def test_xlsx(self): |
| 1370 | + title, schemas, submissions = build_fixture('grouped_repeatable') |
| 1371 | + fp = FormPack(schemas, title) |
| 1372 | + options = {'versions': 'rgv1'} |
1373 | 1373 |
|
1374 | | - # with TempDir() as d: |
1375 | | - # xls = d / 'foo.xlsx' |
1376 | | - # fp.export(**options).to_xlsx(xls, submissions) |
1377 | | - # assert xls.isfile() |
| 1374 | + with TempDir() as d: |
| 1375 | + xls = d / 'foo.xlsx' |
| 1376 | + fp.export(**options).to_xlsx(xls, submissions) |
| 1377 | + assert xls.isfile() |
| 1378 | + |
| 1379 | + def test_xlsx_long_sheet_names_and_invalid_chars(self): |
| 1380 | + title, schemas, submissions = build_fixture('long_names') |
| 1381 | + fp = FormPack(schemas, title) |
| 1382 | + options = {'versions': 'long_survey_name__the_quick__brown_fox_jumps' |
| 1383 | + '_over_the_lazy_dog_v1'} |
| 1384 | + |
| 1385 | + with TempDir() as d: |
| 1386 | + xls = d / 'foo.xlsx' |
| 1387 | + fp.export(**options).to_xlsx(xls, submissions) |
| 1388 | + assert xls.isfile() |
| 1389 | + book = xlrd.open_workbook(xls) |
| 1390 | + assert book.sheet_names() == [ |
| 1391 | + 'long survey name_ the quick,...', |
| 1392 | + 'long_group_name__Victor_jagt...', |
| 1393 | + 'long_group_name__Victor_... (1)' |
| 1394 | + ] |
1378 | 1395 |
|
1379 | | - # def test_xlsx_long_sheet_names_and_invalid_chars(self): |
1380 | | - # title, schemas, submissions = build_fixture('long_names') |
1381 | | - # fp = FormPack(schemas, title) |
1382 | | - # options = {'versions': 'long_survey_name__the_quick__brown_fox_jumps' |
1383 | | - # '_over_the_lazy_dog_v1'} |
1384 | | - |
1385 | | - # with TempDir() as d: |
1386 | | - # xls = d / 'foo.xlsx' |
1387 | | - # fp.export(**options).to_xlsx(xls, submissions) |
1388 | | - # assert xls.isfile() |
1389 | | - # book = xlrd.open_workbook(xls) |
1390 | | - # assert book.sheet_names() == [ |
1391 | | - # 'long survey name_ the quick,...', |
1392 | | - # 'long_group_name__Victor_jagt...', |
1393 | | - # 'long_group_name__Victor_... (1)' |
1394 | | - # ] |
1395 | | - |
1396 | | - |
1397 | | - # def test_xlsx_with_tag_headers(self): |
1398 | | - # title, schemas, submissions = build_fixture('hxl_grouped_repeatable') |
1399 | | - # fp = FormPack(schemas, title) |
1400 | | - # options = {'versions': 'hxl_rgv1', 'tag_cols_for_header': ['hxl']} |
1401 | | - # with TempDir() as d: |
1402 | | - # xls = d / 'foo.xlsx' |
1403 | | - # fp.export(**options).to_xlsx(xls, submissions) |
1404 | | - # assert xls.isfile() |
1405 | | - # book = xlrd.open_workbook(xls) |
1406 | | - # # Verify main sheet |
1407 | | - # sheet = book.sheet_by_name('Household survey with HXL an...') |
1408 | | - # row_values = [cell.value for cell in sheet.row(1)] |
1409 | | - # assert row_values == [ |
1410 | | - # '#date+start', '#date+end', '#loc+name', ''] |
1411 | | - # # Verify repeating group |
1412 | | - # sheet = book.sheet_by_name('houshold_member_repeat') |
1413 | | - # row_values = [cell.value for cell in sheet.row(1)] |
1414 | | - # assert row_values == ['#beneficiary', '', ''] |
| 1396 | + |
| 1397 | + def test_xlsx_with_tag_headers(self): |
| 1398 | + title, schemas, submissions = build_fixture('hxl_grouped_repeatable') |
| 1399 | + fp = FormPack(schemas, title) |
| 1400 | + options = {'versions': 'hxl_rgv1', 'tag_cols_for_header': ['hxl']} |
| 1401 | + with TempDir() as d: |
| 1402 | + xls = d / 'foo.xlsx' |
| 1403 | + fp.export(**options).to_xlsx(xls, submissions) |
| 1404 | + assert xls.isfile() |
| 1405 | + book = xlrd.open_workbook(xls) |
| 1406 | + # Verify main sheet |
| 1407 | + sheet = book.sheet_by_name('Household survey with HXL an...') |
| 1408 | + row_values = [cell.value for cell in sheet.row(1)] |
| 1409 | + assert row_values == [ |
| 1410 | + '#date+start', '#date+end', '#loc+name', ''] |
| 1411 | + # Verify repeating group |
| 1412 | + sheet = book.sheet_by_name('houshold_member_repeat') |
| 1413 | + row_values = [cell.value for cell in sheet.row(1)] |
| 1414 | + assert row_values == ['#beneficiary', '', ''] |
1415 | 1415 |
|
1416 | 1416 | def test_force_index(self): |
1417 | 1417 | title, schemas, submissions = customer_satisfaction |
@@ -1472,54 +1472,54 @@ def test_copy_fields(self): |
1472 | 1472 |
|
1473 | 1473 | self.assertDictEquals(exported, expected) |
1474 | 1474 |
|
1475 | | - # def test_copy_fields_and_force_index_and_unicode(self): |
1476 | | - # title, schemas, submissions = customer_satisfaction |
1477 | | - |
1478 | | - # fp = FormPack(schemas, 'رضا العملاء') |
1479 | | - # export = fp.export(copy_fields=('_uuid', '_submission_time', ValidationStatusCopyField), |
1480 | | - # force_index=True) |
1481 | | - # exported = export.to_dict(submissions) |
1482 | | - # expected = OrderedDict({ |
1483 | | - # "رضا العملاء": { |
1484 | | - # 'fields': ["restaurant_name", "customer_enjoyment", |
1485 | | - # "_uuid", "_submission_time", "_validation_status", "_index"], |
1486 | | - # 'data': [ |
1487 | | - # [ |
1488 | | - # "Felipes", |
1489 | | - # "yes", |
1490 | | - # "90dd7750f83011e590707c7a9125d07d", |
1491 | | - # "2016-04-01 19:57:45.306805", |
1492 | | - # "validation_status_approved", |
1493 | | - # 1 |
1494 | | - # ], |
1495 | | - |
1496 | | - # [ |
1497 | | - # "Dunkin Donuts", |
1498 | | - # "no", |
1499 | | - # "90dd7750f83011e590707c7a9125d08d", |
1500 | | - # "2016-04-02 19:57:45.306805", |
1501 | | - # "validation_status_approved", |
1502 | | - # 2 |
1503 | | - # ], |
1504 | | - |
1505 | | - # [ |
1506 | | - # "McDonalds", |
1507 | | - # "no", |
1508 | | - # "90dd7750f83011e590707c7a9125d09d", |
1509 | | - # "2016-04-03 19:57:45.306805", |
1510 | | - # "validation_status_approved", |
1511 | | - # 3 |
1512 | | - # ] |
1513 | | - # ] |
1514 | | - # } |
1515 | | - # }) |
1516 | | - |
1517 | | - # self.assertEqual(exported, expected) |
1518 | | - |
1519 | | - # with TempDir() as d: |
1520 | | - # xls = d / 'test.xlsx' |
1521 | | - # fp.export().to_xlsx(xls, submissions) |
1522 | | - # assert xls.isfile() |
| 1475 | + def test_copy_fields_and_force_index_and_unicode(self): |
| 1476 | + title, schemas, submissions = customer_satisfaction |
| 1477 | + |
| 1478 | + fp = FormPack(schemas, 'رضا العملاء') |
| 1479 | + export = fp.export(copy_fields=('_uuid', '_submission_time', ValidationStatusCopyField), |
| 1480 | + force_index=True) |
| 1481 | + exported = export.to_dict(submissions) |
| 1482 | + expected = OrderedDict({ |
| 1483 | + "رضا العملاء": { |
| 1484 | + 'fields': ["restaurant_name", "customer_enjoyment", |
| 1485 | + "_uuid", "_submission_time", "_validation_status", "_index"], |
| 1486 | + 'data': [ |
| 1487 | + [ |
| 1488 | + "Felipes", |
| 1489 | + "yes", |
| 1490 | + "90dd7750f83011e590707c7a9125d07d", |
| 1491 | + "2016-04-01 19:57:45.306805", |
| 1492 | + "validation_status_approved", |
| 1493 | + 1 |
| 1494 | + ], |
| 1495 | + |
| 1496 | + [ |
| 1497 | + "Dunkin Donuts", |
| 1498 | + "no", |
| 1499 | + "90dd7750f83011e590707c7a9125d08d", |
| 1500 | + "2016-04-02 19:57:45.306805", |
| 1501 | + "validation_status_approved", |
| 1502 | + 2 |
| 1503 | + ], |
| 1504 | + |
| 1505 | + [ |
| 1506 | + "McDonalds", |
| 1507 | + "no", |
| 1508 | + "90dd7750f83011e590707c7a9125d09d", |
| 1509 | + "2016-04-03 19:57:45.306805", |
| 1510 | + "validation_status_approved", |
| 1511 | + 3 |
| 1512 | + ] |
| 1513 | + ] |
| 1514 | + } |
| 1515 | + }) |
| 1516 | + |
| 1517 | + self.assertEqual(exported, expected) |
| 1518 | + |
| 1519 | + with TempDir() as d: |
| 1520 | + xls = d / 'test.xlsx' |
| 1521 | + fp.export().to_xlsx(xls, submissions) |
| 1522 | + assert xls.isfile() |
1523 | 1523 |
|
1524 | 1524 | def test_copy_fields_multiple_versions(self): |
1525 | 1525 | title, schemas, submissions = restaurant_profile |
|
0 commit comments