def test_validate_legacy_case_data_happy_path(self):
     "Show that when given valid data, 'is_valid' is True for each row"
     required_one_ofs = ["current_smoker", "symptoms_selected"]
     df = validate_legacy_case_data(
         pd.DataFrame(make_legacy_contacts_data()),
         CONTACT_DATA_DICT,
         required_one_ofs=required_one_ofs,
     )
     assert df["is_valid"].all()
    def test_validate_legacy_case_data_invalid_number(self):
        """Show that case data rows with invalid number value are invalid...

        and row["validation_problems"] has info about the offending column(s)
        """
        change_row = 0
        num_col = "days_symptoms_lasted"
        data = make_legacy_contacts_data()
        data[change_row][num_col] = "this is not a number"
        df = pd.DataFrame(data)
        df = validate_legacy_case_data(df, CONTACT_DATA_DICT)
        assert ~df.iloc[change_row]["is_valid"]
        assert num_col in df.iloc[change_row]["validation_problems"]
    def test_validate_legacy_case_data_invalid_date(self):
        """Show that case data rows with invalid date value are invalid...

        and row["validation_problems"] has info about the offending column(s)
        """
        change_row = 0
        date_col = "dob"
        data = make_legacy_contacts_data()
        data[change_row][date_col] = "this-is-not-a-date"
        df = pd.DataFrame(data)
        df = validate_legacy_case_data(df, CONTACT_DATA_DICT)
        assert ~df.iloc[change_row]["is_valid"]
        assert date_col in df.iloc[change_row]["validation_problems"]
    def test_validate_legacy_case_data_invalid_multi_select(self):
        """Show that case data rows with invalid number value are invalid...

        and row["validation_problems"] has info about the offending column(s)
        """
        change_row = 0
        multi_select_col = "symptoms_selected"
        val = "floating"
        data = make_legacy_contacts_data()
        data[change_row][multi_select_col] = val
        assert val not in CONTACT_DATA_DICT[multi_select_col]["allowed_values"]
        df = pd.DataFrame(data)
        df = validate_legacy_case_data(df, CONTACT_DATA_DICT)
        assert ~df.iloc[change_row]["is_valid"]
        assert multi_select_col in df.iloc[change_row]["validation_problems"]
    def test_validate_legacy_case_data_invalid_select(self):
        """Show that case data rows with invalid number value are invalid...

        and row["validation_problems"] has info about the offending column(s)
        """
        change_row = 0
        select_col = "current_smoker"
        val = "what did you say?"
        data = make_legacy_contacts_data()
        data[change_row][select_col] = val
        assert val not in CONTACT_DATA_DICT[select_col]["allowed_values"]
        df = pd.DataFrame(data)
        df = validate_legacy_case_data(df, CONTACT_DATA_DICT)
        assert ~df.iloc[change_row]["is_valid"]
        assert select_col in df.iloc[change_row]["validation_problems"]
    def test_validate_legacy_case_data_missing_required_value(self):
        """Show that case data rows with missing required fields are invalid...

        and row["validation_problems"] has info about the offending column(s)
        """
        change_row_1 = 0
        change_row_2 = 1
        required_col = "first_name"
        assert CONTACT_DATA_DICT[required_col]["required"] is True
        data = make_legacy_contacts_data()
        data[change_row_1][required_col] = None
        data[change_row_2][required_col] = ""
        df = pd.DataFrame(data)
        df = validate_legacy_case_data(df, CONTACT_DATA_DICT)
        assert ~df.iloc[[change_row_1, change_row_2]]["is_valid"].all()
        assert required_col in df.iloc[change_row_1]["validation_problems"]
        assert required_col in df.iloc[change_row_2]["validation_problems"]
 def test_validate_legacy_case_data_required_one_ofs_invalid(self):
     """Show that "required one of" validation logic works"""
     required_one_ofs = ["current_smoker", "symptoms_selected"]
     change_row_1 = 0
     change_row_2 = 1
     data = make_legacy_contacts_data()
     for col in required_one_ofs:
         data[change_row_1][col] = None
         data[change_row_2][col] = ""
     df = pd.DataFrame(data)
     df = validate_legacy_case_data(df,
                                    CONTACT_DATA_DICT,
                                    required_one_ofs=required_one_ofs)
     assert ~df.iloc[[change_row_1, change_row_2]]["is_valid"].all()
     for row_idx in [change_row_1, change_row_2]:
         assert ("one of the following columns"
                 in df.iloc[row_idx]["validation_problems"])
         for col in required_one_ofs:
             assert col in df.iloc[row_idx]["validation_problems"]