Skip to content

Commit

Permalink
fix test_exports
Browse files Browse the repository at this point in the history
  • Loading branch information
jdugh committed Aug 11, 2021
1 parent 8d021fe commit 3021938
Showing 1 changed file with 93 additions and 93 deletions.
186 changes: 93 additions & 93 deletions tests/test_exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

import xlrd
from backports import csv
# from path import TempDir
from path import TempDir

from formpack import FormPack
from formpack.constants import UNTRANSLATED
Expand Down Expand Up @@ -1366,52 +1366,52 @@ def test_export_with_split_fields(self):

self.assertEqual(export, expected)

# def test_xlsx(self):
# title, schemas, submissions = build_fixture('grouped_repeatable')
# fp = FormPack(schemas, title)
# options = {'versions': 'rgv1'}
def test_xlsx(self):
title, schemas, submissions = build_fixture('grouped_repeatable')
fp = FormPack(schemas, title)
options = {'versions': 'rgv1'}

# with TempDir() as d:
# xls = d / 'foo.xlsx'
# fp.export(**options).to_xlsx(xls, submissions)
# assert xls.isfile()
with TempDir() as d:
xls = d / 'foo.xlsx'
fp.export(**options).to_xlsx(xls, submissions)
assert xls.isfile()

def test_xlsx_long_sheet_names_and_invalid_chars(self):
title, schemas, submissions = build_fixture('long_names')
fp = FormPack(schemas, title)
options = {'versions': 'long_survey_name__the_quick__brown_fox_jumps'
'_over_the_lazy_dog_v1'}

with TempDir() as d:
xls = d / 'foo.xlsx'
fp.export(**options).to_xlsx(xls, submissions)
assert xls.isfile()
book = xlrd.open_workbook(xls)
assert book.sheet_names() == [
'long survey name_ the quick,...',
'long_group_name__Victor_jagt...',
'long_group_name__Victor_... (1)'
]

# def test_xlsx_long_sheet_names_and_invalid_chars(self):
# title, schemas, submissions = build_fixture('long_names')
# fp = FormPack(schemas, title)
# options = {'versions': 'long_survey_name__the_quick__brown_fox_jumps'
# '_over_the_lazy_dog_v1'}

# with TempDir() as d:
# xls = d / 'foo.xlsx'
# fp.export(**options).to_xlsx(xls, submissions)
# assert xls.isfile()
# book = xlrd.open_workbook(xls)
# assert book.sheet_names() == [
# 'long survey name_ the quick,...',
# 'long_group_name__Victor_jagt...',
# 'long_group_name__Victor_... (1)'
# ]


# def test_xlsx_with_tag_headers(self):
# title, schemas, submissions = build_fixture('hxl_grouped_repeatable')
# fp = FormPack(schemas, title)
# options = {'versions': 'hxl_rgv1', 'tag_cols_for_header': ['hxl']}
# with TempDir() as d:
# xls = d / 'foo.xlsx'
# fp.export(**options).to_xlsx(xls, submissions)
# assert xls.isfile()
# book = xlrd.open_workbook(xls)
# # Verify main sheet
# sheet = book.sheet_by_name('Household survey with HXL an...')
# row_values = [cell.value for cell in sheet.row(1)]
# assert row_values == [
# '#date+start', '#date+end', '#loc+name', '']
# # Verify repeating group
# sheet = book.sheet_by_name('houshold_member_repeat')
# row_values = [cell.value for cell in sheet.row(1)]
# assert row_values == ['#beneficiary', '', '']

def test_xlsx_with_tag_headers(self):
title, schemas, submissions = build_fixture('hxl_grouped_repeatable')
fp = FormPack(schemas, title)
options = {'versions': 'hxl_rgv1', 'tag_cols_for_header': ['hxl']}
with TempDir() as d:
xls = d / 'foo.xlsx'
fp.export(**options).to_xlsx(xls, submissions)
assert xls.isfile()
book = xlrd.open_workbook(xls)
# Verify main sheet
sheet = book.sheet_by_name('Household survey with HXL an...')
row_values = [cell.value for cell in sheet.row(1)]
assert row_values == [
'#date+start', '#date+end', '#loc+name', '']
# Verify repeating group
sheet = book.sheet_by_name('houshold_member_repeat')
row_values = [cell.value for cell in sheet.row(1)]
assert row_values == ['#beneficiary', '', '']

def test_force_index(self):
title, schemas, submissions = customer_satisfaction
Expand Down Expand Up @@ -1472,54 +1472,54 @@ def test_copy_fields(self):

self.assertDictEquals(exported, expected)

# def test_copy_fields_and_force_index_and_unicode(self):
# title, schemas, submissions = customer_satisfaction

# fp = FormPack(schemas, 'رضا العملاء')
# export = fp.export(copy_fields=('_uuid', '_submission_time', ValidationStatusCopyField),
# force_index=True)
# exported = export.to_dict(submissions)
# expected = OrderedDict({
# "رضا العملاء": {
# 'fields': ["restaurant_name", "customer_enjoyment",
# "_uuid", "_submission_time", "_validation_status", "_index"],
# 'data': [
# [
# "Felipes",
# "yes",
# "90dd7750f83011e590707c7a9125d07d",
# "2016-04-01 19:57:45.306805",
# "validation_status_approved",
# 1
# ],

# [
# "Dunkin Donuts",
# "no",
# "90dd7750f83011e590707c7a9125d08d",
# "2016-04-02 19:57:45.306805",
# "validation_status_approved",
# 2
# ],

# [
# "McDonalds",
# "no",
# "90dd7750f83011e590707c7a9125d09d",
# "2016-04-03 19:57:45.306805",
# "validation_status_approved",
# 3
# ]
# ]
# }
# })

# self.assertEqual(exported, expected)

# with TempDir() as d:
# xls = d / 'test.xlsx'
# fp.export().to_xlsx(xls, submissions)
# assert xls.isfile()
def test_copy_fields_and_force_index_and_unicode(self):
title, schemas, submissions = customer_satisfaction

fp = FormPack(schemas, 'رضا العملاء')
export = fp.export(copy_fields=('_uuid', '_submission_time', ValidationStatusCopyField),
force_index=True)
exported = export.to_dict(submissions)
expected = OrderedDict({
"رضا العملاء": {
'fields': ["restaurant_name", "customer_enjoyment",
"_uuid", "_submission_time", "_validation_status", "_index"],
'data': [
[
"Felipes",
"yes",
"90dd7750f83011e590707c7a9125d07d",
"2016-04-01 19:57:45.306805",
"validation_status_approved",
1
],

[
"Dunkin Donuts",
"no",
"90dd7750f83011e590707c7a9125d08d",
"2016-04-02 19:57:45.306805",
"validation_status_approved",
2
],

[
"McDonalds",
"no",
"90dd7750f83011e590707c7a9125d09d",
"2016-04-03 19:57:45.306805",
"validation_status_approved",
3
]
]
}
})

self.assertEqual(exported, expected)

with TempDir() as d:
xls = d / 'test.xlsx'
fp.export().to_xlsx(xls, submissions)
assert xls.isfile()

def test_copy_fields_multiple_versions(self):
title, schemas, submissions = restaurant_profile
Expand Down

0 comments on commit 3021938

Please sign in to comment.