def test_original_response_is_stored(self): """Compare the dictionary loaded from the zip file json is the same as that submitted""" expected_json_data = { "survey_id": "134", "tx_id": "27923934-62de-475c-bc01-433c09fd38b8", "collection": { "instrument_id": "0005", "period": "201704" }, "metadata": { "user_id": "123456789", "ru_ref": "12345678901A" }, "submitted_at": "2017-04-12T13:01:26Z", "data": {"something": "some data", "something else": "some other data"} } seq_nr = 12345 transformer = MWSSTransformer(expected_json_data, seq_nr=seq_nr) transformer.create_zip(img_seq=itertools.count()) z = zipfile.ZipFile(transformer.image_transformer.zip.in_memory_zip) zfile = z.open('EDC_QJson/134_12345.json', 'r') actual_json_data = json.loads(zfile.read().decode('utf-8')) z.close() self.assertEqual(actual_json_data, expected_json_data)
def test_image_sequence_number(self): """ Test image sequence number returns as expected """ response = { "survey_id": "134", "tx_id": "27923934-62de-475c-bc01-433c09fd38b8", "collection": { "instrument_id": "0005", "period": "201704" }, "metadata": { "user_id": "123456789", "ru_ref": "12345678901A" }, "submitted_at": "2017-04-12T13:01:26Z", "data": {"something": "some data", "something else": "some other data"} } seq_nr = 12345 transformer = MWSSTransformer(response, seq_nr=seq_nr) transformer.create_zip(img_seq=itertools.count()) funct = next(i for i in transformer.image_transformer.zip.get_filenames() if os.path.splitext(i)[1] == ".csv") bits = os.path.splitext(funct)[0].split("_") self.assertEqual(seq_nr, int(bits[-1]))