Skip to content

Commit 3021938

Browse files
committed
fix test_exports
1 parent 8d021fe commit 3021938

File tree

1 file changed

+93
-93
lines changed

1 file changed

+93
-93
lines changed

tests/test_exports.py

Lines changed: 93 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
import xlrd
1212
from backports import csv
13-
# from path import TempDir
13+
from path import TempDir
1414

1515
from formpack import FormPack
1616
from formpack.constants import UNTRANSLATED
@@ -1366,52 +1366,52 @@ def test_export_with_split_fields(self):
13661366

13671367
self.assertEqual(export, expected)
13681368

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'}
13731373

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+
]
13781395

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', '', '']
14151415

14161416
def test_force_index(self):
14171417
title, schemas, submissions = customer_satisfaction
@@ -1472,54 +1472,54 @@ def test_copy_fields(self):
14721472

14731473
self.assertDictEquals(exported, expected)
14741474

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()
15231523

15241524
def test_copy_fields_multiple_versions(self):
15251525
title, schemas, submissions = restaurant_profile

0 commit comments

Comments
 (0)