'Initial Setup'

def setUp(self):

    if (not self.prepared):
        Object.objects.all().delete()
        User.objects.all().delete()
        try:
            self.group = Group.objects.get(name='test')
        except Group.DoesNotExist:
            Group.objects.all().delete()
            self.group = Group(name='test')
            self.group.save()
        try:
            self.user = DjangoUser.objects.get(username=self.username)
            self.user.set_password(self.password)
            try:
                self.profile = self.user.profile
            except Exception:
                User.objects.all().delete()
                self.user = DjangoUser(username=self.username, password='')
                self.user.set_password(self.password)
                self.user.save()
        except DjangoUser.DoesNotExist:
            User.objects.all().delete()
            self.user = DjangoUser(username=self.username, password='')
            self.user.set_password(self.password)
            self.user.save()
        try:
            perspective = Perspective.objects.get(name='default')
        except Perspective.DoesNotExist:
            Perspective.objects.all().delete()
            perspective = Perspective(name='default')
            perspective.set_default_user()
            perspective.save()
        ModuleSetting.set('default_perspective', perspective.id)
        self.contact_type = ContactType(name='test')
        self.contact_type.set_default_user()
        self.contact_type.save()
        self.contact = Contact(name='test', contact_type=self.contact_type)
        self.contact.set_default_user()
        self.contact.save()
        self.category = Category(name='test')
        self.category.set_default_user()
        self.category.save()
        self.equity = Equity(issue_price=10, sell_price=10, issuer=self.contact, owner=self.contact)
        self.equity.set_default_user()
        self.equity.save()
        self.asset = Asset(name='test', owner=self.contact)
        self.asset.set_default_user()
        self.asset.save()
        self.tax = Tax(name='test', rate=10)
        self.tax.set_default_user()
        self.tax.save()
        self.currency = Currency(code='GBP', name='Pounds', symbol='L', is_default=True)
        self.currency.set_default_user()
        self.currency.save()
        self.account = Account(name='test', owner=self.contact, balance_currency=self.currency)
        self.account.set_default_user()
        self.account.save()
        self.liability = Liability(name='test', source=self.contact, target=self.contact, account=self.account, value=10, value_currency=self.currency)
        self.liability.set_default_user()
        self.liability.save()
        self.transaction = Transaction(name='test', account=self.account, source=self.contact, target=self.contact, value=10, value_currency=self.currency)
        self.transaction.set_default_user()
        self.transaction.save()
        self.client = Client()
        self.prepared = True
