old_contents: import random
  import string
  from django import test
  from django.core import exceptions
  from django_flanker.forms import EmailField
  from django_flanker.validators import flanker_validator
  from flanker.addresslib import validate
  from mock import patch
  from pytest import raises
  from .forms import EmailForm, PersonForm
  
  
  def mock_exchanger_lookup(arg, metrics=False):
      mtimes = {'mx_lookup': 0, 'dns_lookup': 0, 'mx_conn': 0}
      mx_record = None
      if arg == 'gmail.com':
          mx_record = 'sample.gmail-smtp-in.l.google.com'
      return (mx_record, mtimes)
  
  
  def generate_bad_email():
      pool = string.lowercase + string.digits
      local = ''.join([random.choice(pool) for x in xrange(15)])
      host = ''.join([random.choice(pool) for x in xrange(32)])
      return '{0}@{1}.com'.format(local, host)
  
  
  @patch.object(validate, 'mail_exchanger_lookup', mock_exchanger_lookup)
  class FlankerTests(test.TestCase):
      def test_validator(self):
          assert flanker_validator('derek.payton@gmail.com') is None
          with raises(exceptions.ValidationError):
              flanker_validator('derek.payton@g-mail.com')
          with raises(exceptions.ValidationError):
              flanker_validator(generate_bad_email())
  
      def test_model_form_field(self):
          form = PersonForm()
          assert isinstance(form.fields['email'], EmailField)
  
      def test_form_valid(self):
          form = EmailForm({'email': 'derek.payton@gmail.com'})
          assert form.is_valid() is True
  
      def test_form_invalid(self):
          form = EmailForm({'email': generate_bad_email()})
          assert form.is_valid() is False
  
      def test_form_invalid_suggest(self):
          bad_email = 'derek.payton@gmial.com'
          suggestion = validate.suggest_alternate(bad_email)
          form = EmailForm({'email': bad_email})
          assert form.is_valid() is False
          assert suggestion in form.errors['email'].as_text()
  
new_contents: from django import test
  from django.core import exceptions
  from django_flanker.forms import EmailField
  from django_flanker.validators import flanker_validator
  from flanker.addresslib import validate
  from mock import patch
  from pytest import raises
  from .forms import EmailForm, PersonForm
  
  
  def mock_exchanger_lookup(arg, metrics=False):
      mtimes = {'mx_lookup': 0, 'dns_lookup': 0, 'mx_conn': 0}
      mx_record = None
      if arg == 'gmail.com':
          mx_record = 'sample.gmail-smtp-in.l.google.com'
      return (mx_record, mtimes)
  
  
  @patch.object(validate, 'mail_exchanger_lookup', mock_exchanger_lookup)
  class FlankerTests(test.TestCase):
      def test_validator(self):
          assert flanker_validator('derek.payton@gmail.com') is None
          with raises(exceptions.ValidationError):
              flanker_validator('user@bad-email.com')
  
      def test_model_form_field(self):
          form = PersonForm()
          assert isinstance(form.fields['email'], EmailField)
  
      def test_form_valid(self):
          form = EmailForm({'email': 'derek.payton@gmail.com'})
          assert form.is_valid() is True
  
      def test_form_invalid(self):
          form = EmailForm({'email': 'user@bad-email.com'})
          assert form.is_valid() is False
  
      def test_form_invalid_suggest(self):
          bad_email = 'derek.payton@gmial.com'
          suggestion = validate.suggest_alternate(bad_email)
          form = EmailForm({'email': bad_email})
          assert form.is_valid() is False
          assert suggestion in form.errors['email'].as_text()
  
subject: Remove generate_bad_email from tests, as mock_exchanger_lookup handles "invalid" domains.