def test_pck_transformer_round_numeric_values_qpses(): """ For QPSES, a number of values require rounding before being sent downstream. These should round up on a .5 answer. """ scenarios = ["160", "165", "169"] for survey_id in scenarios: survey = {'survey_id': survey_id} response = { "collection": { "instrument_id": "0020" }, "data": { "60": 50.5, "561": 50.3, "562": 74.49, "661": 80.1, "662": 34.8, "146": "A lot of changes.", } } pck_transformer = PCKTransformer(survey, response) pck_transformer.round_numeric_values() assert pck_transformer.data == { '60': '51', '146': 'A lot of changes.', '561': '50', '562': '74', '661': '80', '662': '35' }
def test_pck_transformer_round_numeric_values_qpses(): """ For QPSES, a number of values require rounding before being sent downstream. These should round up on a .5 answer. """ scenarios = ["160", "165", "169"] for survey_id in scenarios: survey = {'survey_id': survey_id} response = { "collection": { "instrument_id": "0020" }, "data": { "60": 50.5, "561": 50.3, "562": 74.49, "661": 80.1, "662": 34.8, "146": "A lot of changes.", } } pck_transformer = PCKTransformer(survey, response) pck_transformer.round_numeric_values() assert pck_transformer.data['60'] == '51' assert pck_transformer.data['561'] == '50' assert pck_transformer.data['562'] == '74' assert pck_transformer.data['661'] == '80' assert pck_transformer.data['662'] == '35'
def test_pck_transformer_round_numeric_values_qss(self): """ For QSS (Stocks), a number of values require rounding before being sent downstream. These should be rounded to the nearest thousand. For example: - 12100 -> 12000 - 12500 -> 13000 - 12501 -> 13000 """ scenarios = ["0001", "0002"] for form_type in scenarios: survey = {'survey_id': "017"} response = { "collection": { "instrument_id": form_type }, "data": { "15": "Yes", "65": "311500", "66": "313103", "139": "7300", "140": "7680", "144": "2000", "145": "2205", "146": "A lot of changes.", "149": "1800", "150": "12205", } } pck_transformer = PCKTransformer(survey, response) pck_transformer.round_numeric_values() assert pck_transformer.data == { '15': "Yes", '65': '312', '66': '313', '139': '7', '140': '8', '144': '2', '145': '2', '146': 'A lot of changes.', '149': '2', '150': '12' }
def test_pck_transformer_calculates_total_playback_qcas(self): """ For QCAS, downstream needs the calculated values for both acquisitions and proceeds from disposals to be sent in the PCK. """ survey = {'survey_id': '019'} response = { "collection": { "instrument_id": "0020" }, "data": { "11": "03/07/2018", "12": "01/10/2018", "146": "A lot of changes.", # Disposals "689": "499", "696": "500", "704": "12345.67", "708": "12345500", "710": "-499", "712": "-12345.67", # Construction "681": "1000", # Acquisitions "688": "1500", "695": "1500", "703": "1500", "707": "1500", "709": "1500", "711": "1500", # Mineral "697": "-1500", "146a": "Yes", "146b": "Start or end of a long term project", "146c": "Site changes, for example, openings, closures, refurbishments or upgrades", "146d": "End of accounting period or financial year", "146e": "Normal movement for time of year", "146f": "Change of business structure, merger, or takeover", "146g": "One off or unusual investment", "146h": "Introduction / removal of new legislation / incentive", "146i": "Availability of credit", "146j": "Overspend during the previous quarter", "146k": "Other", "d12": "Yes", "d681": "Yes" } } pck_transformer = PCKTransformer(survey, response) pck_transformer.round_numeric_values() assert pck_transformer.data['689'] == '0' assert pck_transformer.data['696'] == '1' assert pck_transformer.data['704'] == '12' assert pck_transformer.data['708'] == '12346' assert pck_transformer.data['710'] == '-0' assert pck_transformer.data['712'] == '-12' pck_transformer.calculate_total_playback() # Total value of acquisitions questions for only machinery and equipments section assert pck_transformer.data['714'] == '12' # Total value of disposals questions for only machinery and equipments section assert pck_transformer.data['715'] == '12347' # Total value of all acquisitions questions assert pck_transformer.data['692'] == '11' # Total value of all disposals questions (same as '715' since constructions section and minerals sections does not have disposals question) assert pck_transformer.data['693'] == '12347'