Exemplo n.º 1
0
    def test_export_range(
        self,
        mocked_upload,
        import_test_data,
        start_date_str,
        end_date_str,
        num_expected_files,
        total_expected_lines,
    ):
        exporter = Exporter()
        start_date = datetime.strptime(start_date_str, "%Y%m%d").date()
        end_date = datetime.strptime(end_date_str, "%Y%m%d").date()
        exporter.export_range(start_date, end_date)

        num_days = (end_date - start_date).days + 1
        batch_names = {(start_date + timedelta(days=x)).strftime("%Y%m%d")
                       for x in range(num_days)}
        batch_names = list(batch_names.intersection(BATCHES_IN_TEST_FILE))

        total_lines = 0

        for batch_name in batch_names:
            filename = f"{batch_name}_NPR_BACKUP.csv"
            path = os.path.join(settings.TMP_DATA_DIR, filename)
            mocked_upload.assert_any_call(path, filename)

            assert exists(path)
            with open(path) as f:
                lines = f.readlines()
                total_lines += len(lines) - 1  # don't count the header

                # cleanup
                os.remove(path)

        assert total_lines == total_expected_lines
Exemplo n.º 2
0
from datetime import datetime, timedelta

import settings
from exporter import Exporter
from importer import Importer

if __name__ == "__main__":
    """
    Import the last 7 days of data from the RDW database
    and export the data in CSV files to the objectstore.
    """
    end_date = datetime.now().date()
    start_date = end_date - timedelta(days=settings.NUM_DAYS_TO_IMPORT)

    importer = Importer()
    importer.import_range(start_date, end_date)

    exporter = Exporter()
    exporter.export_range(start_date, end_date)