def test_insert_data_quiz_process(setup_queue_event, test_data_quiz,
                                  create_table_mock):
    event = setup_queue_event(
        schema.Data(metadata=schema.Metadata(timestamp=0),
                    data=test_data_quiz))

    processHandler(event, None)

    create_table_mock.assert_table_data_column(
        'google_forms_data', 'type',
        pd.Series([
            'SCALE', 'MULTIPLE_CHOICE', 'TEXT', 'CHECKBOX', 'MULTIPLE_CHOICE',
            'LIST', 'DATE', 'TIME'
        ]))

    create_table_mock.assert_table_data_column(
        'google_forms_data', 'form_name',
        pd.Series([
            'test_quiz', 'test_quiz', 'test_quiz', 'test_quiz', 'test_quiz',
            'test_quiz', 'test_quiz', 'test_quiz'
        ]))

    create_table_mock.assert_table_data_column(
        'google_forms_data', 'uploaded_by_user',
        pd.Series([
            'test_person', 'test_person', 'test_person', 'test_person',
            'test_person', 'test_person', 'test_person', 'test_person'
        ]))

    create_table_mock.assert_table_data_column(
        'google_forms_data', 'is_quiz',
        pd.Series([True, True, True, True, True, True, True, True]))
def test_insert_data_multiple_respondents(setup_queue_event,
                                          test_data_form_multiple_respondents,
                                          create_table_mock):
    event = setup_queue_event(
        schema.Data(metadata=schema.Metadata(timestamp=0),
                    data=test_data_form_multiple_respondents))

    processHandler(event, None)

    create_table_mock.assert_table_data_column(
        'google_forms_data', 'type',
        pd.Series([
            'TEXT',
            'PARAGRAPH_TEXT',
            'TEXT',
            'PARAGRAPH_TEXT',
        ]))

    create_table_mock.assert_table_data_column(
        'google_forms_data', 'responder',
        pd.Series([
            'test_user1',
            'test_user1',
            'test_user2',
            'test_user2',
        ]))
    create_table_mock.assert_table_data_column(
        'google_forms_data', 'is_quiz', pd.Series([False, False, False,
                                                   False]))
def test_insert_data_invalid_type(setup_queue_event, test_data_quiz_invalid,
                                  create_table_mock):
    invalid_file_quiz_event = setup_queue_event(
        schema.Data(metadata=schema.Metadata(timestamp=0),
                    data=test_data_quiz_invalid))

    with pytest.raises(KeyError):
        processHandler(invalid_file_quiz_event, None)
def test_process_no_responses_no_data_added(setup_queue_event, test_data_empty,
                                            create_table_mock):
    event = setup_queue_event(
        schema.Data(metadata=schema.Metadata(timestamp=0),
                    data=test_data_empty))

    processHandler(event, None)

    create_table_mock.assert_table_not_created('google_forms_data')
def test_insert_data_form(setup_queue_event, test_data_form,
                          create_table_mock):
    event = setup_queue_event(
        schema.Data(metadata=schema.Metadata(timestamp=0),
                    data=test_data_form))

    processHandler(event, None)

    create_table_mock.assert_table_data_column(
        'google_forms_data', 'type',
        pd.Series([
            'PARAGRAPH_TEXT', 'TEXT', 'MULTIPLE_CHOICE', 'CHECKBOX',
            'CHECKBOX', 'LIST', 'SCALE', 'GRID', 'GRID', 'CHECKBOX_GRID',
            'CHECKBOX_GRID', 'DATE', 'TIME', 'FILE_UPLOAD'
        ]))