Пример #1
0
 def test_batch_ids_are_all_unique(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     self.fb.map(df, None)
     batch_data = self.fb.map(df, None)
     unique_ids_size = batch_data['BatchID'].value_counts(dropna=True).size
     ids_size = batch_data['BatchID'].values.size
     self.assertEqual(ids_size, unique_ids_size)
Пример #2
0
 def test_all_contribution_ids_are_unique(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     contributions_data = self.fb.build_contributions(df)
     unique_ids_size = contributions_data['ContributionID'].value_counts(
         dropna=True).size
     ids_size = contributions_data['ContributionID'].values.size
     self.assertEqual(ids_size, unique_ids_size)
Пример #3
0
 def test_ids_are_unique(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     attribute_notes = self.anb.map(df, SourceCSVType.ATTRIBUTE_NOTES)
     unique_ids_size = attribute_notes['note_id'].value_counts(
         dropna=True).size
     ids_size = attribute_notes['note_id'].values.size
     self.assertEqual(ids_size, unique_ids_size)
Пример #4
0
 def test_data_is_not_null(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     attribute_notes = self.anb.map(df, SourceCSVType.ATTRIBUTE_NOTES)
     self.assertFalse(
         pd.isnull(attribute_notes['individual_id_1']).any()
         and pd.isnull(attribute_notes['attribute_group_name'].any())
         and pd.isnull(attribute_notes['attribute_name'])
         and pd.isnull(attribute_notes['comment']).any())
Пример #5
0
 def test_number_of_batches_equals_number_of_group_by_batch_name_date(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     self.fb.map(df, None)
     batch_data = self.fb.map(df, None)
     ids_size = batch_data['BatchID'].values.size
     # This seems weird but does work bizarrely
     group_by_size = batch_data.groupby(['BatchName',
                                         'BatchDate']).size().size
     self.assertEqual(ids_size, group_by_size)
Пример #6
0
 def test_batch_shared_data_columns_are_correct_types(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     self.fb.map(df, None)
     batch_date_is_date = self.fb.batch_data[
         'Batch_Date'].dtype == Timestamp
     batch_id_is_int = self.fb.batch_data[
         'Id'].dtype == np.int64 or self.fb.batch_data['Id'].dtype == int
     types_correct = batch_date_is_date and batch_id_is_int
     self.assertTrue(types_correct)
Пример #7
0
 def test_contributions_ids_are_ints(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     contributions_data = self.fb.build_contributions(df)
     contribution_id_is_int = contributions_data[
         'ContributionID'].dtype == int
     contribution_batch_id_is_int = contributions_data[
         'ContributionBatchID'].dtype == int
     contribution_individual_id_is_int = contributions_data[
         'IndividualID'].dtype == int
     self.assertTrue(contribution_id_is_int and contribution_batch_id_is_int
                     and contribution_individual_id_is_int)
Пример #8
0
 def test_number_of_shared_batch_data_equals_number_of_contributions_group_by_batch_name_date(
         self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     cloned_df = df.copy()
     cloned_df = self.fb.fill_missing_batch_data(cloned_df)
     self.fb.map(df, None)
     ids_size = self.fb.batch_data['Id'].values.size
     # This seems weird but does work bizarrely
     group_by_size = cloned_df.groupby(['Batch_Name',
                                        'Batch_Date']).size().size
     self.assertEqual(ids_size, group_by_size)
Пример #9
0
def run(source_file_path, target_file_type: TargetCSVType,
        source_type: SourceCSVType):
    mode = source_type.mode
    set_up(source_file_path, target_file_type, mode)
    data = CSVOperations.read_file_without_check(source_file_path)
    builder = BuilderFactory.get_builder(target_file_type, source_type)
    if builder is None:
        raise Exception('No matching builder was found')
    output_data = builder.map(data, source_type)

    target_file_path = get_target_file_path(target_file_type, source_file_path)
    if output_data is None:
        return
    if mode == Mode.APPEND:
        CSVOperations.delete_write(target_file_path, output_data)
    else:
        CSVOperations.write_file(
            get_target_file_path(target_file_type, source_file_path),
            output_data)
Пример #10
0
 def test_all_check_contributions_have_check_number(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     contributions_data = self.fb.build_contributions(df)
     check_contributions = contributions_data.loc[
         contributions_data['ContributionTypeName'] == 'Check']
     self.assertFalse(pd.isnull(check_contributions['CheckNumber']).any())
Пример #11
0
 def test_all_contributions_received_dates_are_dates(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     contributions_data = self.fb.build_contributions(df)
     self.assertTrue(contributions_data['ReceivedDate'].dtype == Timestamp)
Пример #12
0
 def test_all_contributions_have_funds(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     contributions_data = self.fb.build_contributions(df)
     self.assertFalse(pd.isnull(contributions_data['FundName']).any())
Пример #13
0
 def test_batch_columns_match(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     self.fb.map(df, None)
     batch_data = self.fb.map(df, None)
     npt.assert_array_equal(batch_data.columns.values,
                            TargetCSVType.BATCH.columns)
 def test_read_attribute_data_has_correct_columns(self):
     df = csvops.read_file_without_check(
         THIS_DIR + '/testdata/A2501E_ConnectionStepsAttributes.csv')
     npt.assert_array_equal(df.columns.values,
                            SourceCSVType.ATTRIBUTES.columns)
Пример #15
0
 def test_batch_amounts_are_all_decimal(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     self.fb.map(df, None)
     batch_data = self.fb.map(df, None)
     self.assertTrue(batch_data['BatchAmount'].dtype == decimal.Decimal)
Пример #16
0
 def test_batch_shared_data_contains_correct_number_of_batches(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     self.fb.map(df, None)
     unique_size = self.fb.batch_data['Id'].value_counts(dropna=True).size
     self.assertEqual(unique_size, 5)
Пример #17
0
 def test_batches_all_have_amounts(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     self.fb.map(df, None)
     batch_data = self.fb.map(df, None)
     self.assertFalse(pd.isnull(batch_data['BatchAmount']).any())
Пример #18
0
 def test_batches_ids_are_all_ints(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     self.fb.map(df, None)
     batch_data = self.fb.map(df, None)
     self.assertTrue(batch_data['BatchID'].dtype == int)
 def test_read_individual_household_has_correct_columns(self):
     df = csvops.read_file_without_check(
         THIS_DIR + '/testdata/X9400_no_attributes.csv')
     npt.assert_array_equal(df.columns.values,
                            SourceCSVType.INDIVIDUAL_HOUSEHOLD.columns)
Пример #20
0
 def test_all_contribution_batch_ids_have_batches(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     contributions_data = self.fb.build_contributions(df)
     npt.assert_array_equal(
         contributions_data['ContributionBatchID'].unique(),
         self.fb.batch_data['Id'])
Пример #21
0
 def test_contributions_columns_match(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     contributions_data = self.fb.build_contributions(df)
     npt.assert_array_equal(contributions_data.columns.values,
                            TargetCSVType.CONTRIBUTION.columns)
Пример #22
0
 def test_batch_shared_data_columns_are_all_populated(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     self.fb.map(df, None)
     self.assertFalse(self.fb.batch_data.isnull().values.any())
Пример #23
0
 def test_contributions_amount_equals_contribution_amount(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     contributions_data = self.fb.build_contributions(df)
     self.assertEqual(contributions_data['Amount'].sum(), 6084.99)
Пример #24
0
 def test_batch_dates_are_all_timestamps(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     self.fb.map(df, None)
     batch_data = self.fb.map(df, None)
     self.assertTrue(batch_data['BatchDate'].dtype == Timestamp)
Пример #25
0
 def test_number_of_contributions(self):
     df = csvops.read_file_without_check(THIS_DIR + TEST_DATA_FILENAME)
     contributions_data = self.fb.build_contributions(df)
     self.assertEquals(len(contributions_data.index), 36)