示例#1
0
def test_parse_csv_example_success():
    """The on-page example is actually valid."""
    csv_file = io.BytesIO(bytes(EXAMPLE_CSV, encoding='utf-8'))
    fake_request = mock.Mock(**{'FILES.get': {'csv_file': csv_file}.get})
    john_doe, jane_doe = '*****@*****.**', '*****@*****.**'
    assert _parse_csv(fake_request, 'example.com') == {
        '*****@*****.**': {john_doe},
        '*****@*****.**': {john_doe, jane_doe},
        '*****@*****.**': {john_doe, jane_doe},
        '*****@*****.**': {john_doe, jane_doe},
    }
示例#2
0
def test_parse_then_write_csv_is_noop(mock_ggroup_vhost):
    """Not an explicit goal, but write-parse-write should be the same
    as one write de facto if our data structures are consistent."""
    addresses_1 = mock_ggroup_vhost.get_forwarding_addresses()
    csv_str_1 = _write_csv(addresses_1)
    f = io.BytesIO(bytes(csv_str_1, encoding='utf-8'))
    fake_request = mock.Mock(**{'FILES.get': {'csv_file': f}.get})
    addresses_2 = frozenset({
        MailForwardingAddress(
            address=from_addr,
            forward_to=to_addrs,
            crypt_password=None,
            last_updated=None,
        )
        for from_addr, to_addrs in _parse_csv(fake_request, 'vhost.com').items()
    })
    assert _write_csv(addresses_2)
示例#3
0
def test_parse_csv_failure(csv_text, fake_error):
    """CSV with wrong # of columns or invalid email addresses fails."""
    csv_file = io.BytesIO(bytes(csv_text, encoding='utf-8'))
    fake_request = mock.Mock(**{'FILES.get': {'csv_file': csv_file}.get})
    with pytest.raises(fake_error):
        _parse_csv(fake_request, 'vhost.com')