def test_dak_json_export(self): "Test json report of DAK data" semester = Semester.create(2019, False) # 2019, vt jsonpickle.set_encoder_options('json', indent=4) jsonreport = JsonReport(self.dak, semester) stream = jsonreport.get_json(unpicklable=False, warn=True) data = json.loads(stream) self.assertEqual(data[u'foerenings_namn'], u"Test Scoutkår") self.assertEqual(data[u'forenings_id'], u"1111") self.assertEqual(data[u'kort'][u'namn_paa_kort'], "Testavdelning") self.assertEqual(data[u'kort'][u'sammankomster'][0]['deltagare'][0]['uid'], "1235") self.assertEqual(data[u'kort'][u'sammankomster'][0]['deltagare'][1]['uid'], "1236") self.assertEqual(data[u'kort'][u'sammankomster'][0]['ledare'][0]['uid'], "1234") self.assertEqual(data[u'kort'][u'naervarokort_nummer'], "1") self.save_and_check(stream, 'dak_json_export.json', 'dak_json_export.json') stream = jsonreport.get_report_string() data = jsonpickle.decode(stream) self.assertEqual(data.foerenings_namn, u"Test Scoutkår") self.assertEqual(data.forenings_id, u"1111") self.assertEqual(data.kort.namn_paa_kort, "Testavdelning") self.assertEqual(data.kort.sammankomster[0].deltagare[0].uid, "1235") self.assertEqual(data.kort.sammankomster[0].deltagare[1].uid, "1236") self.assertEqual(data.kort.sammankomster[0].ledare[0].uid, "1234") self.assertEqual(data.kort.naervarokort_nummer, "1") self.save_and_check(stream, 'dak_json_pickable_export.json', 'dak_json_pickable_export.json', force=True)
def test_dak_excel_export(self): "Test excel report of DAK data" current_semester = Semester.create(2019, False) # 2019, vt excel_report = ExcelReport(self.dak, current_semester) result_bytes = excel_report.getFilledInExcelSpreadsheet() generated_path = os.path.join(os.path.dirname(__file__), TestJsonReport.outputDir, 'dak_excel_export.xlsx') with open(generated_path, "wb") as filep: filep.write(result_bytes) workbook = load_workbook(generated_path) worksheets = workbook.worksheets[0] self.assertEqual(self.dak.kort.naervarokort_nummer, worksheets['E1'].value) self.assertEqual(current_semester.year, worksheets['I1'].value) self.assertEqual(self.dak.kort.namn_paa_kort, worksheets['D2'].value) self.assertEqual("Scouting", worksheets['D3'].value) self.assertEqual(self.dak.kort.lokal, worksheets['D4'].value) if current_semester.ht: self.assertEqual(worksheets['C6'].value, None) self.assertEqual(worksheets['C7'].value, 'X') else: self.assertEqual(worksheets['C6'].value, 'X') self.assertEqual(worksheets['C7'].value, None) row = 13 for deltagaren in self.dak.kort.deltagare: self.assertEqual(deltagaren.foernamn + " " + deltagaren.efternamn, worksheets['B' + str(row)].value) self.assertEqual('K' if deltagaren.is_female() else 'M', worksheets['H' + str(row)].value) self.assertEqual(deltagaren.personnummer[0:8], worksheets['J' + str(row)].value) self.assertEqual(1, worksheets['K' + str(row)].value) self.assertEqual(1, worksheets['L' + str(row)].value) row += 1 self.assertEqual(1, worksheets['M13'].value) self.assertEqual(None, worksheets['M14'].value) self.assertEqual(1, worksheets['M15'].value) os.remove(generated_path)