old_contents: import string
  import random
  from contextlib import contextmanager
  
  from django.test import TestCase
  
  from rapidsms.models import Connection, Contact, Backend
  
  from groups.models import Group
  
  
  UNICODE_CHARS = [unichr(x) for x in xrange(1, 0xD7FF)]
  
  
  class CreateDataTest(TestCase):
      """ Base test case that provides helper functions to create data """
  
      def random_string(self, length=255, extra_chars=''):
          chars = string.letters + extra_chars
          return ''.join([random.choice(chars) for i in range(length)])
  
      def random_number_string(self, length=4):
          numbers = [str(x) for x in random.sample(range(10), 4)]
          return ''.join(numbers)
  
      def random_unicode_string(self, max_length=255):
          output = u''
          for x in xrange(random.randint(1, max_length / 2)):
              c = UNICODE_CHARS[random.randint(0, len(UNICODE_CHARS) - 1)]
              output += c + u' '
          return output
  
      def create_backend(self, data={}):
          defaults = {
              'name': self.random_string(12),
          }
          defaults.update(data)
          return Backend.objects.create(**defaults)
  
      def create_contact(self, data={}):
          defaults = {
              'name': self.random_string(12),
          }
          defaults.update(data)
          return Contact.objects.create(**defaults)
  
      def create_connection(self, data={}):
          defaults = {
              'identity': self.random_string(10),
          }
          defaults.update(data)
          if 'backend' not in defaults:
              defaults['backend'] = self.create_backend()
          return Connection.objects.create(**defaults)
  
      def create_group(self, data={}):
          defaults = {
              'name': self.random_string(12),
          }
          defaults.update(data)
          return Group.objects.create(**defaults)
  
  
  @contextmanager
  def patch_settings(**kwargs):
      from django.conf import settings
      old_settings = []
      for key, new_value in kwargs.items():
          old_value = getattr(settings, key, SettingDoesNotExist)
          old_settings.append((key, old_value))
          setattr(settings, key, new_value)
      yield
      for key, old_value in old_settings:
          if old_value is SettingDoesNotExist:
              delattr(settings, key)
          else:
              setattr(settings, key, old_value)
  
new_contents: import string
  import random
  from contextlib import contextmanager
  
  from django.test import TestCase
  
  from rapidsms.models import Connection, Contact, Backend
  
  from groups.models import Group
  
  
  UNICODE_CHARS = [unichr(x) for x in xrange(1, 0xD7FF)]
  
  
  class CreateDataTest(TestCase):
      """ Base test case that provides helper functions to create data """
  
      def random_string(self, length=255, extra_chars=''):
          chars = string.letters + extra_chars
          return ''.join([random.choice(chars) for i in range(length)])
  
      def random_number_string(self, length=4):
          numbers = [str(x) for x in random.sample(range(10), 4)]
          return ''.join(numbers)
  
      def random_unicode_string(self, max_length=255):
          output = u''
          for x in xrange(random.randint(1, max_length / 2)):
              c = UNICODE_CHARS[random.randint(0, len(UNICODE_CHARS) - 1)]
              output += c + u' '
          return output
  
      def create_backend(self, data={}):
          defaults = {
              'name': self.random_string(12),
          }
          defaults.update(data)
          return Backend.objects.create(**defaults)
  
      def create_contact(self, data={}):
          defaults = {
              'name': self.random_string(12),
          }
          defaults.update(data)
          return Contact.objects.create(**defaults)
  
      def create_connection(self, data={}):
          defaults = {
              'identity': self.random_string(10),
          }
          defaults.update(data)
          if 'backend' not in defaults:
              defaults['backend'] = self.create_backend()
          return Connection.objects.create(**defaults)
  
      def create_group(self, data={}):
          defaults = {
              'name': self.random_string(12),
          }
          defaults.update(data)
          return Group.objects.create(**defaults)
  
  
  class SettingDoesNotExist:
      pass
  
  
  @contextmanager
  def patch_settings(**kwargs):
      from django.conf import settings
      old_settings = []
      for key, new_value in kwargs.items():
          old_value = getattr(settings, key, SettingDoesNotExist)
          old_settings.append((key, old_value))
          setattr(settings, key, new_value)
      yield
      for key, old_value in old_settings:
          if old_value is SettingDoesNotExist:
              delattr(settings, key)
          else:
              setattr(settings, key, old_value)
  
subject: create dummy exception a la aremind tests to allow test to pass