def test_aggregate_fourweekly_changes(self): """ question_id 190w4 used for fourweekly changes question; aggregates to 190. """ return_value = MWSSTransformer.transform({"190w4": ""}) self.assertIs(False, return_value["190"]) return_value = MWSSTransformer.transform({"190w4": "No"}) self.assertIs(False, return_value["190"]) return_value = MWSSTransformer.transform({"190w4": "Yes"}) self.assertIs(True, return_value["190"])
def test_aggregate_fiveweekly_changes(self): """ question_id 190w5 used for fiveweekly changes question; aggregates to 190. """ return_value = MWSSTransformer.transform({"190w5": ""}) self.assertFalse(return_value["190"]) return_value = MWSSTransformer.transform({"190w5": "No"}) self.assertFalse(return_value["190"]) return_value = MWSSTransformer.transform({"190w5": "Yes"}) self.assertTrue(return_value["190"])
def test_aggregate_fourweekly_changes(self): """ question_id 190w4 used for fourweekly changes question; aggregates to 190. """ return_value = MWSSTransformer.transform({"190w4": ""}) self.assertIs(False, return_value["190"]) return_value = MWSSTransformer.transform({"190w4": "No"}) self.assertIs(False, return_value["190"]) return_value = MWSSTransformer.transform({"190w4": "Yes"}) self.assertIs(True, return_value["190"])
def test_aggregate_fiveweekly_changes(self): """ question_id 190w5 used for fiveweekly changes question; aggregates to 190. """ return_value = MWSSTransformer.transform({"190w5": ""}) self.assertFalse(return_value["190"]) return_value = MWSSTransformer.transform({"190w5": "No"}) self.assertFalse(return_value["190"]) return_value = MWSSTransformer.transform({"190w5": "Yes"}) self.assertTrue(return_value["190"])
def test_digits_to_onetwo(self): """ Test question value in question range return as boolean """ digits_ingested_as_bools = [100, 120, 200, 220] for question_range in digits_ingested_as_bools: question_id = str(question_range) with self.subTest(question_range=question_range, question_id=question_id): return_value = MWSSTransformer.transform({question_id: "64"}) self.assertIs(True, return_value[question_id]) self.assertEqual(1, CSFormatter._pck_value(return_value[question_id])) return_value = MWSSTransformer.transform({question_id: ""}) self.assertEqual(2, CSFormatter._pck_value(return_value[question_id]))
def test_digits_to_onetwo(self): """ Test question value in question range return as boolean """ digits_ingested_as_bools = [100, 120, 200, 220] for question_range in digits_ingested_as_bools: question_id = str(question_range) with self.subTest(question_range=question_range, question_id=question_id): return_value = MWSSTransformer.transform({question_id: "64"}) self.assertIs(True, return_value[question_id]) self.assertEqual(1, CSFormatter._pck_value(return_value[question_id])) return_value = MWSSTransformer.transform({question_id: ""}) self.assertEqual(2, CSFormatter._pck_value(return_value[question_id]))
def test_dates_to_onetwo(self): """ Test dates in question range are returned as boolean """ dates_ingested_as_bools = [110, 210] for question_range in dates_ingested_as_bools: question_id = str(question_range) with self.subTest(question_range=question_range, question_id=question_id): return_value = MWSSTransformer.transform({question_id: "23/4/2017"}) self.assertEqual([datetime.date(2017, 4, 23)], return_value[question_id]) self.assertEqual(1, CSFormatter._pck_value(return_value[question_id])) return_value = MWSSTransformer.transform({question_id: ""}) self.assertEqual([], return_value[question_id]) self.assertEqual(2, CSFormatter._pck_value(return_value[question_id]))
def test_dates_to_onetwo(self): """ Test dates in question range are returned as boolean """ dates_ingested_as_bools = [110, 210] for question_range in dates_ingested_as_bools: question_id = str(question_range) with self.subTest(question_range=question_range, question_id=question_id): return_value = MWSSTransformer.transform({question_id: "23/4/2017"}) self.assertEqual([datetime.date(2017, 4, 23)], return_value[question_id]) self.assertEqual(1, CSFormatter._pck_value(return_value[question_id])) return_value = MWSSTransformer.transform({question_id: ""}) self.assertEqual([], return_value[question_id]) self.assertEqual(2, CSFormatter._pck_value(return_value[question_id]))
def test_pck_from_transformed_data(self): """ Test package from transformer returned data correctly """ f = open(self.replies_dir + "eq-mwss.json", "r") reply = json.loads(f.read()) f.close() reply["tx_id"] = "27923934-62de-475c-bc01-433c09fd38b8" reply["survey_id"] = "134" reply["collection"]["period"] = "200911" reply["metadata"]["ru_ref"] = "49900001225C" ids = Survey.identifiers(reply, batch_nr=3866, seq_nr=0) data = MWSSTransformer.transform( OrderedDict([ ("40", 2), ("140", 124), ("151", 217222) ]) ) id_dict = ids._asdict() return_value = CSFormatter._pck_lines(data, id_dict["inst_id"], id_dict["ru_ref"], id_dict["ru_check"], id_dict["period"]) self.assertEqual([ "FV ", "0005:49900001225C:200911", "0040 00000000002", "0130 00000000002", "0131 00000000002", "0132 00000000002", "0140 00000000124", "0151 00000217222", ], return_value)
def test_aggregate_fiveweekly_increase(self): """ Increase in fiveweekly pay (200w5); aggregated with monthly increase (200). """ return_value = MWSSTransformer.transform({"200w5": "25"}) self.assertIs(True, return_value["200"])
def test_aggregate_fiveweekly_increase(self): """ Increase in fiveweekly pay (200w5); aggregated with monthly increase (200). """ return_value = MWSSTransformer.transform({"200w5": "25"}) self.assertIs(True, return_value["200"])
def test_pck_from_transformed_data(self): """ Test package from transformer returned data correctly """ src = pkg_resources.resource_string(__name__, "replies/eq-mwss.json") reply = json.loads(src.decode("utf-8")) reply["tx_id"] = "27923934-62de-475c-bc01-433c09fd38b8" reply["survey_id"] = "134" reply["collection"]["period"] = "200911" reply["metadata"]["ru_ref"] = "49900001225C" ids = Survey.identifiers(reply, batch_nr=3866, seq_nr=0) data = MWSSTransformer.transform( OrderedDict([ ("40", 2), ("140", 124), ("151", 217222) ]) ) id_dict = ids._asdict() return_value = CSFormatter._pck_lines(data, id_dict["inst_id"], id_dict["ru_ref"], id_dict["ru_check"], id_dict["period"]) self.assertEqual([ "FV ", "0005:49900001225C:200911", "0040 00000000002", "0130 00000000002", "0131 00000000002", "0132 00000000002", "0140 00000000124", "0151 00000217222", ], return_value)
def test_aggregate_fourweekly_increase_employees(self): """ Employees with increase in fourweekly pay (220w4); aggregated with monthly increase (220). """ return_value = MWSSTransformer.transform({"220w4": "25"}) self.assertIs(True, return_value["220"])
def test_defaults_empty(self): """ Tests default values are empty """ return_value = MWSSTransformer.transform({}) self.assertIsInstance(return_value, OrderedDict) self.assertEqual([str(i) for i in (130, 131, 132)], list(return_value.keys()))
def test_aggregate_fourweekly_increase_employees(self): """ Employees with increase in fourweekly pay (220w4); aggregated with monthly increase (220). """ return_value = MWSSTransformer.transform({"220w4": "25"}) self.assertIs(True, return_value["220"])
def test_defaults_empty(self): """ Tests default values are empty """ return_value = MWSSTransformer.transform({}) self.assertIsInstance(return_value, OrderedDict) self.assertEqual([str(i) for i in (130, 131, 132)], list(return_value.keys()))
def test_defaults_with_data(self): """ Tests default values are populated """ return_value = MWSSTransformer.transform({"40": "33"}) self.assertIsInstance(return_value, OrderedDict) self.assertEqual(33, return_value["40"]) self.assertEqual(4, len(return_value))
def test_defaults_with_data(self): """ Tests default values are populated """ return_value = MWSSTransformer.transform({"40": "33"}) self.assertIsInstance(return_value, OrderedDict) self.assertEqual(33, return_value["40"]) self.assertEqual(4, len(return_value))
def test_imputed_zero_values_fiveweekly(self): """ Breakdown figures (173, 183) are imputed with zero when the respondent has confirmed the total (153) is zero. """ return_value = MWSSTransformer.transform({"d153": "Yes"}) self.assertEqual(0, return_value["153"]) self.assertEqual(0, return_value["173"]) self.assertEqual(0, return_value["183"])
def test_imputed_zero_values_monthly(self): """ Breakdown figures (171, 181) are imputed with zero when the respondent has confirmed the total (151) is zero. """ return_value = MWSSTransformer.transform({"d151": "Yes"}) self.assertEqual(0, return_value["151"]) self.assertEqual(0, return_value["171"]) self.assertEqual(0, return_value["181"])
def test_unsigned(self): """ Test unsigned integer value """ return_value = MWSSTransformer.transform({"40": "33"}) self.assertEqual(33, return_value["40"]) item = CSFormatter._pck_item("40", return_value["40"]) self.assertEqual(item, "0040 00000000033")
def test_aggregate_fiveweekly_increase_date(self): """ Date of increase in fiveweekly pay (210w5); aggregated with monthly (210). """ return_value = MWSSTransformer.transform({"210w5": "2017-01-11"}) self.assertEqual(1, len(return_value["210"])) self.assertEqual(11, return_value["210"][0].day) self.assertEqual(1, return_value["210"][0].month)
def test_imputed_zero_values_monthly(self): """ Breakdown figures (171, 181) are imputed with zero when the respondent has confirmed the total (151) is zero. """ return_value = MWSSTransformer.transform({"d151": "Yes"}) self.assertEqual(0, return_value["151"]) self.assertEqual(0, return_value["171"]) self.assertEqual(0, return_value["181"])
def test_imputed_zero_values_fiveweekly(self): """ Breakdown figures (173, 183) are imputed with zero when the respondent has confirmed the total (153) is zero. """ return_value = MWSSTransformer.transform({"d153": "Yes"}) self.assertEqual(0, return_value["153"]) self.assertEqual(0, return_value["173"]) self.assertEqual(0, return_value["183"])
def test_aggregate_fiveweekly_increase_date(self): """ Date of increase in fiveweekly pay (210w5); aggregated with monthly (210). """ return_value = MWSSTransformer.transform({"210w5": "2017-01-11"}) self.assertEqual(1, len(return_value["210"])) self.assertEqual(11, return_value["210"][0].day) self.assertEqual(1, return_value["210"][0].month)
def test_currency(self): """ Test currency value """ return_value = MWSSTransformer.transform({"50": "36852"}) self.assertEqual(36852, return_value["50"]) item = CSFormatter._pck_item("50", return_value["50"]) self.assertEqual(item, "0050 00000036852")
def test_unsigned(self): """ Test unsigned integer value """ return_value = MWSSTransformer.transform({"40": "33"}) self.assertEqual(33, return_value["40"]) item = CSFormatter._pck_item("40", return_value["40"]) self.assertEqual(item, "0040 00000000033")
def test_currency(self): """ Test currency value """ return_value = MWSSTransformer.transform({"50": "36852"}) self.assertEqual(36852, return_value["50"]) item = CSFormatter._pck_item("50", return_value["50"]) self.assertEqual(item, "0050 00000036852")
def test_imputed_zero_values_weekly_and_fortnightly(self): """ Breakdown figures (60, 70, 80) are imputed with zero when the respondent has confirmed the totals (50, 50f) are zero. """ return_value = MWSSTransformer.transform({"d50": "Yes", "d50f": "Yes"}) self.assertEqual(0, return_value["50"]) self.assertEqual(0, return_value["60"]) self.assertEqual(0, return_value["70"]) self.assertEqual(0, return_value["80"])
def test_aggregate_monthly_paid_employees(self): """ question_id 140m, 140w4, 140w5 are added to give a value for monthly paid employees (140). """ for question_id in ("140m", "140w4", "140w5"): with self.subTest(question_id=question_id): return_value = MWSSTransformer.transform({question_id: "25"}) self.assertEqual(25, return_value["140"]) self.assertEqual(4, len(return_value))
def test_aggregate_weekly_comments(self): """ question_id 300w, 300f, 300m, 300w4 & 300w5; all aggregated as 300. """ for question_id in ("300w", "300f", "300m", "300w4", "300w5"): with self.subTest(question_id=question_id): return_value = MWSSTransformer.transform({question_id: "This is a comment"}) self.assertEqual(True, return_value["300"]) self.assertEqual(4, len(return_value))
def test_aggregate_monthly_paid_employees(self): """ question_id 140m, 140w4, 140w5 are added to give a value for monthly paid employees (140). """ for question_id in ("140m", "140w4", "140w5"): with self.subTest(question_id=question_id): return_value = MWSSTransformer.transform({question_id: "25"}) self.assertEqual(25, return_value["140"]) self.assertEqual(4, len(return_value))
def test_imputed_zero_values_weekly_and_fortnightly(self): """ Breakdown figures (60, 70, 80) are imputed with zero when the respondent has confirmed the totals (50, 50f) are zero. """ return_value = MWSSTransformer.transform({"d50": "Yes", "d50f": "Yes"}) self.assertEqual(0, return_value["50"]) self.assertEqual(0, return_value["60"]) self.assertEqual(0, return_value["70"]) self.assertEqual(0, return_value["80"])
def test_aggregate_weekly_comments(self): """ question_id 300w, 300f, 300m, 300w4 & 300w5; all aggregated as 300. """ for question_id in ("300w", "300f", "300m", "300w4", "300w5"): with self.subTest(question_id=question_id): return_value = MWSSTransformer.transform({question_id: "This is a comment"}) self.assertEqual(True, return_value["300"]) self.assertEqual(4, len(return_value))
def test_unsigned_decimals(self): """ Test unsigned decimal value """ digits_ingested_as_bools = [100, 200] for question_range in digits_ingested_as_bools: question_id = str(question_range) with self.subTest(question_range=question_range, question_id=question_id): return_value = MWSSTransformer.transform({question_id: "64.0"}) self.assertIs(True, return_value[question_id]) self.assertEqual(1, CSFormatter._pck_value(return_value[question_id]))
def test_unsigned_decimals(self): """ Test unsigned decimal value """ digits_ingested_as_bools = [100, 200] for question_range in digits_ingested_as_bools: question_id = str(question_range) with self.subTest(question_range=question_range, question_id=question_id): return_value = MWSSTransformer.transform({question_id: "64.0"}) self.assertIs(True, return_value[question_id]) self.assertEqual(1, CSFormatter._pck_value(return_value[question_id]))
def test_pay_frequency_as_bool(self): """ Test pay frequency value in question range returns as boolean """ pay_frequencies = { 130: "Calendar monthly", 131: "Four weekly", 132: "Five weekly", } for question_id, return_value in pay_frequencies.items(): question_id = str(question_id) with self.subTest(question_id=question_id, return_value=return_value): return_value = MWSSTransformer.transform({question_id: return_value}) self.assertIs(True, return_value[question_id]) self.assertEqual(1, CSFormatter._pck_value(return_value[question_id])) return_value = MWSSTransformer.transform({question_id: ""}) self.assertIs(False, return_value[question_id]) self.assertEqual(2, CSFormatter._pck_value(return_value[question_id])) return_value = MWSSTransformer.transform({}) self.assertIs(False, return_value[question_id]) self.assertEqual(2, CSFormatter._pck_value(return_value[question_id]))
def test_pay_frequency_as_bool(self): """ Test pay frequency value in question range returns as boolean """ pay_frequencies = { 130: "Calendar monthly", 131: "Four weekly", 132: "Five weekly", } for question_id, return_value in pay_frequencies.items(): question_id = str(question_id) with self.subTest(question_id=question_id, return_value=return_value): return_value = MWSSTransformer.transform({question_id: return_value}) self.assertIs(True, return_value[question_id]) self.assertEqual(1, CSFormatter._pck_value(return_value[question_id])) return_value = MWSSTransformer.transform({question_id: ""}) self.assertIs(False, return_value[question_id]) self.assertEqual(2, CSFormatter._pck_value(return_value[question_id])) return_value = MWSSTransformer.transform({}) self.assertIs(False, return_value[question_id]) self.assertEqual(2, CSFormatter._pck_value(return_value[question_id]))