def test_should_reject_email_with_bad_email_format(notify_frontend):
    notify_frontend.config['MAX_ROWS_IN_BULK_UPLOAD'] = 5
    bad_file = StringIO(
        open('tests/csv_test_files/bad_email_to_address.csv').read())
    transformed = transform_email(bad_file)
    assert len(transformed['errors']) == 1
    assert transformed['errors'][0] == 'Row (1) is invalid'
def test_should_reject_email_with_from_email_a_non_gov_uk_address(
        notify_frontend):
    bad_file = StringIO(
        open('tests/csv_test_files/bad_email_from_address.csv').read())
    transformed = transform_email(bad_file)
    assert len(transformed['errors']) == 1
    assert transformed['errors'][0] == 'Row (2) is invalid'
def test_should_reject_email_with_too_many_lines(notify_frontend):
    valid_file = StringIO(open('tests/csv_test_files/valid_email.csv').read())

    notify_frontend.config['MAX_ROWS_IN_BULK_UPLOAD'] = 1
    transformed = transform_email(valid_file)
    assert len(transformed['errors']) == 1
    assert transformed['errors'][0][
        'error'] == "Max number of rows (1) exceeded"
def test_should_parse_valid_email_csv(notify_frontend):
    valid_email_file = StringIO(
        open('tests/csv_test_files/valid_email.csv').read())

    transformed = transform_email(valid_email_file)
    assert len(transformed['notifications']) == 2
    assert transformed['notifications'][0]['to'] == '*****@*****.**'
    assert transformed['notifications'][1]['to'] == '*****@*****.**'
    assert transformed['notifications'][0]['from'] == '*****@*****.**'
    assert transformed['notifications'][1]['from'] == '*****@*****.**'
    assert transformed['notifications'][0]['subject'] == 'email test subject'
    assert transformed['notifications'][1]['subject'] == 'email test subject2'
    assert transformed['notifications'][0]['message'] == 'email test message'
    assert transformed['notifications'][1]['message'] == 'email test message2'
    assert transformed['notifications'][0][
        'description'] == 'email test description'
    assert transformed['notifications'][1][
        'description'] == 'email test description2'