예제 #1
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)
예제 #2
0
def test_write_csv_has_correct_format(mock_ggroup_vhost):
    """Output CSV has two columns and valid email addresses."""
    f = io.StringIO(_write_csv(mock_ggroup_vhost.get_forwarding_addresses()))
    reader = csv.reader(f)
    for row in reader:
        assert len(row) == 2
        assert _parse_addr(row[0] + '@' + mock_ggroup_vhost.domain)
        assert _parse_csv_forward_addrs(row[1])
예제 #3
0
def test_import_noop_csv(client_ggroup, mock_ggroup_vhost, mock_messages, mock_txn):
    """Exporting then importing ideally doesn't even hit the
    database."""
    csv_text = _write_csv(mock_ggroup_vhost.get_forwarding_addresses())
    resp = client_ggroup.post(
        reverse('vhost_mail_csv_import', args=('vhost.com',)),
        {
            'csv_file': io.StringIO(csv_text),
        },
    )
    assert not mock_ggroup_vhost.remove_forwarding_address.called
    assert not mock_ggroup_vhost.add_forwarding_address.called
    assert resp.status_code == 302
    mock_messages.assert_called_once_with(
        mock.ANY,
        messages.SUCCESS,
        'Import successful!',
    )
예제 #4
0
def test_write_csv_has_expected_rows(mock_ggroup_vhost):
    """Output CSV has all email addresses from the vhost."""
    addresses = mock_ggroup_vhost.get_forwarding_addresses()
    csv_str = _write_csv(addresses)
    check_csv_has_addresses(csv_str, addresses)