def test_scenario_builder_builds_arbitrary_table():
    with pg_connect() as con:
        scenario_builder = ScenarioBuilder(con)
        scenario_builder.reset()

        table_schema = {
            'test_col_1': 'TEXT',
            'tes_col_2': 'TEXT',
        }
        scenario_builder.build_arbitrary_table("test_table", table_schema)
        postgres_tables = scenario_builder.list_postgres_tables()

        assert "test_table" in postgres_tables
Esempio n. 2
0
def test_latest_submission_picks_most_recent_submission():
    with pg_connect() as con:
        scenario_builder = ScenarioBuilder(con)

        table_schema = {
            'provenance': 'TEXT',
            'nhs_number': 'TEXT',
            'submission_time': 'TEXT',
            'has_access_to_essential_supplies': 'TEXT',
            'is_able_to_carry_supplies': 'TEXT',
            'email_address': 'TEXT',
            'phone_number_calls': 'TEXT',
            'phone_number_texts': 'TEXT'
        }
        scenario_builder.build_arbitrary_table("all_submissions", table_schema)

        submission_data = [
            {
                'provenance': 'IVR',
                'nhs_number': '123',
                'submission_time': n_days_ago(n=5),
                'has_access_to_essential_supplies': 'YES',
                'is_able_to_carry_supplies': 'YES',
                'email_address': '*****@*****.**',
                'phone_number_calls': '12345',
                'phone_number_texts': '12345'
            },
            {
                'provenance': 'WEB',
                'nhs_number': '123',
                'submission_time': n_days_ago(n=1),
                'has_access_to_essential_supplies': 'NO',
                'is_able_to_carry_supplies': 'no',
                'email_address': 'test_mail@test_mail.com',
                'phone_number_calls': '0891505050',
                'phone_number_texts': '0891505050'
            },
            {
                'provenance': 'IVR',
                'nhs_number': '123',
                'submission_time': n_days_ago(n=3),
                'has_access_to_essential_supplies': 'YES',
                'is_able_to_carry_supplies': 'YES',
                'email_address': '*****@*****.**',
                'phone_number_calls': '12345',
                'phone_number_texts': '12345'
            }, {
                'provenance': 'IVR',
                'nhs_number': '123',
                'submission_time': n_days_ago(n=4),
                'has_access_to_essential_supplies': 'YES',
                'is_able_to_carry_supplies': 'YES',
                'email_address': '*****@*****.**',
                'phone_number_calls': '12345',
                'phone_number_texts': '12345'
            }
        ]
        expected_row = submission_data[1]

        scenario_builder.insert_multiple_into_arbitrary_table(
            "all_submissions", submission_data
        )

        with open('sql_to_build/latest_submission.sql', 'r') as f:
            query = f.read()

        results = presto_transaction(query)

        assert len(results) == 1
        assert all((item in list(expected_row.values()) for item in results[0]))