'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_user(self.user.profile)
            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.status = TicketStatus(name='TestStatus')
        self.status.set_default_user()
        self.status.save()
        self.queue = TicketQueue(name='TestQueue', default_ticket_status=self.status)
        self.queue.set_default_user()
        self.queue.save()
        self.ticket = Ticket(name='TestTicket', status=self.status, queue=self.queue)
        self.ticket.set_default_user()
        self.ticket.save()
        self.agent = ServiceAgent(related_user=self.user.profile, available_from=datetime.time(9), available_to=datetime.time(17))
        self.agent.set_default_user()
        self.agent.save()
        self.service = Service(name='test')
        self.service.set_default_user()
        self.service.save()
        self.sla = ServiceLevelAgreement(name='test', service=self.service, client=self.contact, provider=self.contact)
        self.sla.set_default_user()
        self.sla.save()
        self.client = Client()
        self.prepared = True
