예제 #1
0
파일: views.py 프로젝트: alejo8591/maker
def service_add(request, response_format='html'):
    "Service add"
    
    if not request.user.get_profile().is_admin('maker.services'):
        return user_denied(request, 
                           message="You don't have administrator access to the Service Support module")
    
    if request.POST:
        if not 'cancel' in request.POST:
            service = Service()
            form = ServiceForm(request.user.get_profile(), request.POST, instance=service)
            if form.is_valid():
                service = form.save()
                service.set_user_from_request(request)
                return HttpResponseRedirect(reverse('services_service_view', args=[service.id]))
        else:
            return HttpResponseRedirect(reverse('services'))
    else:
        form = ServiceForm(request.user.get_profile())
    
    context = _get_default_context(request)
    context.update({'form': form})
    
    return render_to_response('services/service_add', context,
                              context_instance=RequestContext(request), response_format=response_format)
예제 #2
0
파일: tests.py 프로젝트: alejo8591/maker
 def setUp(self):
     "Initial Setup"
     
     if not self.prepared:
         # Clean up first
         Object.objects.all().delete()
         User.objects.all().delete()
             
         # Create objects
         self.group, created = Group.objects.get_or_create(name='test')
         duser, created = DjangoUser.objects.get_or_create(username=self.username)
         duser.set_password(self.password)
         duser.save()
         self.user, created = User.objects.get_or_create(user=duser)
         self.user.save()
         perspective, created = Perspective.objects.get_or_create(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.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, 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
예제 #3
0
파일: tests.py 프로젝트: alejo8591/maker
class ServicesViewsTest(TestCase):
    "Services functional tests for views"

    username = "******"
    password = "******"
    prepared = False
    
    def setUp(self):
        "Initial Setup"
        
        if not self.prepared:
            # Clean up first
            Object.objects.all().delete()
            User.objects.all().delete()
                
            # Create objects
            self.group, created = Group.objects.get_or_create(name='test')
            duser, created = DjangoUser.objects.get_or_create(username=self.username)
            duser.set_password(self.password)
            duser.save()
            self.user, created = User.objects.get_or_create(user=duser)
            self.user.save()
            perspective, created = Perspective.objects.get_or_create(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.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, 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
    

    ######################################
    # Testing views when user is logged in
    ###################################### 

    def test_index_login(self):
        "Test index page with login at /services/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services'))
        self.assertEquals(response.status_code, 200)

    def test_index_owned(self):
        "Test index page with login at /services/owned"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_index_owned'))
        self.assertEquals(response.status_code, 200)

    def test_index_assigned(self):
        "Test index page with login at /services/assigned"

        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_index_assigned'))
        self.assertEquals(response.status_code, 200)


        
    # Queues
    
    def test_queue_add(self):
        "Test page with login at /services/queue/add"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_queue_add'))
        self.assertEquals(response.status_code, 200)
        
    def test_queue_view(self):
        "Test page with login at /services/queue/view/<queue_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_queue_view', args=[self.queue.id]))
        self.assertEquals(response.status_code, 200)

    def test_queue_edit(self):
        "Test page with login at /services/queue/edit/<queue_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_queue_edit', args=[self.queue.id]))
        self.assertEquals(response.status_code, 200)
        
    def test_queue_delete(self):
        "Test page with login at /services/queue/delete/<queue_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_queue_delete', args=[self.queue.id]))
        self.assertEquals(response.status_code, 200)


        
    # Statuses
    
    def test_status_view(self):
        "Test index page with login at /services/status/view/<status_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_status_view', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)
        
    def test_status_edit(self):
        "Test index page with login at /services/status/edit/<status_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_status_edit', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)
        
    def test_status_delete(self):
        "Test index page with login at /services/status/delete/<status_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_status_delete', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)
        
    def test_status_add(self):
        "Test index page with login at /services/status/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_status_add'))
        self.assertEquals(response.status_code, 200)


        
    # Tickets
    
    def test_ticket_add(self):
        "Test page with login at /services/ticket/add"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_ticket_add'))
        self.assertEquals(response.status_code, 200)
        
    def test_ticket_add_by_queue(self):
        "Test page with login at /services/ticket/add/queue/(?P<queue_id>\d+)"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_ticket_add_by_queue', args=[self.queue.id]))
        self.assertEquals(response.status_code, 200)
        
    def test_ticket_view(self):
        "Test page with login at /services/ticket/view/<ticket_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_ticket_view', args=[self.ticket.id]))
        self.assertEquals(response.status_code, 200)

    def test_ticket_edit(self):
        "Test page with login at /services/ticket/edit/<ticket_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_ticket_edit', args=[self.ticket.id]))
        self.assertEquals(response.status_code, 200)

    def test_ticket_delete(self):
        "Test page with login at /services/ticket/delete/<ticket_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_ticket_delete', args=[self.ticket.id]))
        self.assertEquals(response.status_code, 200)

    def test_ticket_set_status(self):
        "Test page with login at /services/ticket/set/(?P<ticket_id>\d+)/status/(?P<status_id>\d+)"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_ticket_set_status', args=[self.ticket.id, self.status.id]))
        self.assertEquals(response.status_code, 200)


        
    # Settings
    
    def test_settings_view(self):
        "Test page with login at /services/settings/view"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_settings_view'))
        self.assertEquals(response.status_code, 200)
        
    def test_settings_edit(self):
        "Test page with login at /services/settings/edit"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_settings_view'))
        self.assertEquals(response.status_code, 200)


        
    # Catalogue
    
    def test_service_catalogue(self):
        "Test page with login at /services/catalogue"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_service_catalogue'))
        self.assertEquals(response.status_code, 200)


        
    # Services
    
    def test_service_view(self):
        "Test page with login at /services/service/view/<service_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_service_view', args=[self.service.id]))
        self.assertEquals(response.status_code, 200)

    def test_service_edit(self):
        "Test page with login at /services/service/edit/<service_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_service_edit', args=[self.service.id]))
        self.assertEquals(response.status_code, 200)
        
    def test_service_delete(self):
        "Test page with login at /services/service/delete/<service_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_service_delete', args=[self.service.id]))
        self.assertEquals(response.status_code, 200)
        
    def test_service_add(self):
        "Test page with login at /services/service/add"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_service_add'))
        self.assertEquals(response.status_code, 200)


        
    # SLAs
    
    def test_sla_index(self):
        "Test page with login at /services/sla"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_sla_index'))
        self.assertEquals(response.status_code, 200)

    def test_sla_view(self):
        "Test page with login at /services/sla/view/<sla_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_sla_view', args=[self.sla.id]))
        self.assertEquals(response.status_code, 200)

    def test_sla_edit(self):
        "Test page with login at /services/sla/edit/<sla_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_sla_edit', args=[self.sla.id]))
        self.assertEquals(response.status_code, 200)

    def test_sla_delete(self):
        "Test page with login at /services/sla/delete/<sla_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_sla_delete', args=[self.sla.id]))
        self.assertEquals(response.status_code, 200)

    def test_sla_add(self):
        "Test page with login at /services/sla/add"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_sla_index'))
        self.assertEquals(response.status_code, 200)



    # Agents
    
    def test_agent_index(self):
        "Test page with login at /services/agent"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_agent_index'))
        self.assertEquals(response.status_code, 200)

    def test_agent_view(self):
        "Test page with login at /services/agent/view/<agent_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_agent_view', args=[self.agent.id]))
        self.assertEquals(response.status_code, 200)

    def test_agent_edit(self):
        "Test page with login at /services/agent/edit/<agent_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_agent_edit', args=[self.agent.id]))
        self.assertEquals(response.status_code, 200)

    def test_agent_delete(self):
        "Test page with login at /services/agent/delete/<agent_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_agent_delete', args=[self.agent.id]))
        self.assertEquals(response.status_code, 200)

    def test_agent_add(self):
        "Test page with login at /services/agent/add"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('services_agent_add'))
        self.assertEquals(response.status_code, 200)
        
        
    ######################################
    # Testing views when user is not logged in
    ###################################### 
    
    def test_index(self):
        "Test index page at /services/"
        response = self.client.get(reverse('services'))
        # Redirects as unauthenticated
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_index_owned_out(self):
        "Testing /services/owned"
        response = self.client.get(reverse('services_index_owned'))
        self.assertRedirects(response, reverse('user_login')) 

    def test_index_assigned_out(self):
        "Testing /services/assigned"
        response = self.client.get(reverse('services_index_assigned'))
        self.assertRedirects(response, reverse('user_login')) 

        
    # Queues
    
    def test_queue_add_out(self):
        "Testing /services/queue/add"
        response = self.client.get(reverse('services_queue_add'))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_queue_view_out(self):
        "Testing /services/queue/view/<queue_id>"
        response = self.client.get(reverse('services_queue_view', args=[self.queue.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_queue_edit_out(self):
        "Testing /services/queue/edit/<queue_id>"
        response = self.client.get(reverse('services_queue_edit', args=[self.queue.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_queue_delete_out(self):
        "Testing /services/queue/delete/<queue_id>"
        response = self.client.get(reverse('services_queue_delete', args=[self.queue.id]))
        self.assertRedirects(response, reverse('user_login')) 

        
    # Statuses
    
    def test_status_view_out(self):
        "Testing /services/status/view/<status_id>"
        response = self.client.get(reverse('services_status_view', args=[self.status.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_status_edit_out(self):
        "Testing /services/status/edit/<status_id>"
        response = self.client.get(reverse('services_status_edit', args=[self.status.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_status_delete_out(self):
        "Testing /services/status/delete/<status_id>"
        response = self.client.get(reverse('services_status_delete', args=[self.status.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_status_add_out(self):
        "Testing /services/status/add/"
        response = self.client.get(reverse('services_status_add'))
        self.assertRedirects(response, reverse('user_login')) 

        
    # Tickets
    
    def test_ticket_add_out(self):
        "Testing /services/ticket/add"
        response = self.client.get(reverse('services_ticket_add'))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_ticket_add_by_queue_out(self):
        "Testing /services/ticket/add/queue/(?P<queue_id>\d+)"
        response = self.client.get(reverse('services_ticket_add_by_queue', args=[self.queue.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_ticket_view_out(self):
        "Testing /services/ticket/view/<ticket_id>"
        response = self.client.get(reverse('services_ticket_view', args=[self.ticket.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_ticket_edit_out(self):
        "Testing /services/ticket/edit/<ticket_id>"
        response = self.client.get(reverse('services_ticket_edit', args=[self.ticket.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_ticket_delete_out(self):
        "Testing /services/ticket/delete/<ticket_id>"
        response = self.client.get(reverse('services_ticket_delete', args=[self.ticket.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_ticket_set_status_out(self):
        "Testing /services/ticket/set/(?P<ticket_id>\d+)/status/(?P<status_id>\d+)"
        response = self.client.get(reverse('services_ticket_set_status', args=[self.ticket.id, self.status.id]))
        self.assertRedirects(response, reverse('user_login')) 


    # Settings
    
    def test_settings_view_out(self):
        "Testing /services/settings/view"
        response = self.client.get(reverse('services_settings_view'))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_settings_edit_out(self):
        "Testing /services/settings/edit"
        response = self.client.get(reverse('services_settings_view'))
        self.assertRedirects(response, reverse('user_login')) 

        
    # Catalogue
    
    def test_service_catalogue_out(self):
        "Testing /services/catalogue"
        response = self.client.get(reverse('services_service_catalogue'))
        self.assertRedirects(response, reverse('user_login')) 

        
    # Services
    
    def test_service_view_out(self):
        "Testing /services/service/view/<service_id>"
        response = self.client.get(reverse('services_service_view', args=[self.service.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_service_edit_out(self):
        "Testing /services/service/edit/<service_id>"
        response = self.client.get(reverse('services_service_edit', args=[self.service.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_service_delete_out(self):
        "Testing /services/service/delete/<service_id>"
        response = self.client.get(reverse('services_service_delete', args=[self.service.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_service_add_out(self):
        "Testing /services/service/add"
        response = self.client.get(reverse('services_service_add'))
        self.assertRedirects(response, reverse('user_login')) 

        
    # SLAs
    
    def test_sla_index_out(self):
        "Testing /services/sla"
        response = self.client.get(reverse('services_sla_index'))
        self.assertRedirects(response, reverse('user_login')) 

    def test_sla_view_out(self):
        "Testing /services/sla/view/<sla_id>"
        response = self.client.get(reverse('services_sla_view', args=[self.sla.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_sla_edit_out(self):
        "Testing /services/sla/edit/<sla_id>"
        response = self.client.get(reverse('services_sla_edit', args=[self.sla.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_sla_delete_out(self):
        "Testing /services/sla/delete/<sla_id>"
        response = self.client.get(reverse('services_sla_delete', args=[self.sla.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_sla_add_out(self):
        "Testing /services/sla/add"
        response = self.client.get(reverse('services_sla_index'))
        self.assertRedirects(response, reverse('user_login')) 


    # Agents
    
    def test_agent_index_out(self):
        "Testing /services/agent"
        response = self.client.get(reverse('services_agent_index'))
        self.assertRedirects(response, reverse('user_login')) 

    def test_agent_view_out(self):
        "Testing /services/agent/view/<agent_id>"
        response = self.client.get(reverse('services_agent_view', args=[self.agent.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_agent_edit_out(self):
        "Testing /services/agent/edit/<agent_id>"
        response = self.client.get(reverse('services_agent_edit', args=[self.agent.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_agent_delete_out(self):
        "Test page with login at /services/agent/delete/<agent_id>"
        response = self.client.get(reverse('services_agent_delete', args=[self.agent.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_agent_add_out(self):
        "Test page with login at /services/agent/add"
        response = self.client.get(reverse('services_agent_add'))
        self.assertRedirects(response, reverse('user_login')) 
예제 #4
0
파일: tests.py 프로젝트: alejo8591/maker
    def setUp(self):
        "Initial Setup"

        if not self.prepared:
            # Clean up first
            Object.objects.all().delete()
            User.objects.all().delete()

            # Create objects
            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.get_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.get_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.get_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
예제 #5
0
파일: tests.py 프로젝트: alejo8591/maker
class ServicesViewsTest(TestCase):
    "Services functional tests for api"

    username = "******"
    password = "******"
    prepared = False
    authentication_headers = {
        "CONTENT_TYPE": "application/json",
        "HTTP_AUTHORIZATION": "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk",
    }
    content_type = "application/json"
    prepared = False

    def setUp(self):
        "Initial Setup"

        if not self.prepared:
            # Clean up first
            Object.objects.all().delete()
            User.objects.all().delete()

            # Create objects
            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.get_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.get_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.get_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

    def test_unauthenticated_access(self):
        "Test index page at /api/services/services"
        response = self.client.get("/api/services/services")
        # Redirects as unauthenticated
        self.assertEquals(response.status_code, 401)

    def test_get_ticket_statuses_list(self):
        """ Test index page api/services/status """
        response = self.client.get(path=reverse("api_services_status"), **self.authentication_headers)
        self.assertEquals(response.status_code, 200)

    def test_get_status(self):
        response = self.client.get(
            path=reverse("api_services_status", kwargs={"object_ptr": self.status.id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

    def test_update_status(self):
        updates = {"name": "Api update", "details": "<p>api details</p>"}
        response = self.client.put(
            path=reverse("api_services_status", kwargs={"object_ptr": self.status.id}),
            content_type=self.content_type,
            data=json.dumps(updates),
            **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

    def test_get_services_list(self):
        """ Test index page api/services """
        response = self.client.get(path=reverse("api_services"), **self.authentication_headers)
        self.assertEquals(response.status_code, 200)

    def test_get_service(self):
        response = self.client.get(
            path=reverse("api_services", kwargs={"object_ptr": self.service.id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

    def test_update_service(self):
        updates = {"name": "Api update", "details": "<p>api details</p>"}
        response = self.client.put(
            path=reverse("api_services", kwargs={"object_ptr": self.service.id}),
            content_type=self.content_type,
            data=json.dumps(updates),
            **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

    def test_get_sla_list(self):
        """ Test index page api/services/sla """
        response = self.client.get(path=reverse("api_services_sla"), **self.authentication_headers)
        self.assertEquals(response.status_code, 200)

    def test_get_sla(self):
        response = self.client.get(
            path=reverse("api_services_sla", kwargs={"object_ptr": self.sla.id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

    def test_update_sla(self):
        updates = {"name": "Api update", "service": self.service.id, "provider": self.contact.id}
        response = self.client.put(
            path=reverse("api_services_sla", kwargs={"object_ptr": self.sla.id}),
            content_type=self.content_type,
            data=json.dumps(updates),
            **self.authentication_headers
        )
        print "content:"
        print response.content
        self.assertEquals(response.status_code, 200)

    def test_get_agents_list(self):
        """ Test index page api/services/agents """
        response = self.client.get(path=reverse("api_services_agents"), **self.authentication_headers)
        self.assertEquals(response.status_code, 200)

    def test_get_agent(self):
        response = self.client.get(
            path=reverse("api_services_agents", kwargs={"object_ptr": self.agent.id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

    def test_update_sla(self):
        updates = {"activate": True, "related_user": User.objects.all()[0].id}
        response = self.client.put(
            path=reverse("api_services_agents", kwargs={"object_ptr": self.agent.id}),
            content_type=self.content_type,
            data=json.dumps(updates),
            **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

    def test_get_queues_list(self):
        """ Test index page api/services/queues """
        response = self.client.get(path=reverse("api_services_queues"), **self.authentication_headers)
        self.assertEquals(response.status_code, 200)

    def test_get_queue(self):
        response = self.client.get(
            path=reverse("api_services_queues", kwargs={"object_ptr": self.queue.id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

    def test_update_queue(self):
        updates = {
            "name": "Api test",
            "default_ticket_priority": 5,
            "ticket_code": "api",
            "waiting_time": 300,
            "default_ticket_status": self.status.id,
        }
        response = self.client.put(
            path=reverse("api_services_queues", kwargs={"object_ptr": self.queue.id}),
            content_type=self.content_type,
            data=json.dumps(updates),
            **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

    def test_get_records(self):
        """ Test index page api/services/ticket/records/{ticket number} """
        response = self.client.get(
            path=reverse("api_services_ticket_records", kwargs={"ticket_id": self.ticket.id}),
            **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

    def test_create_record(self):
        new_record = {"body": "api test message", "notify": False}
        response = self.client.post(
            path=reverse("api_services_ticket_records", kwargs={"ticket_id": self.ticket.id}),
            data=json.dumps(new_record),
            content_type=self.content_type,
            **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEquals(new_record["body"], data["body"])

    def test_get_tasks_list(self):
        """ Test index page api/services/tasks """
        response = self.client.get(path=reverse("api_services_tickets"), **self.authentication_headers)
        self.assertEquals(response.status_code, 200)

    def test_get_ticket(self):
        response = self.client.get(
            path=reverse("api_services_tickets", kwargs={"object_ptr": self.ticket.id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

    def test_update_ticket(self):
        updates = {"name": "Api updates", "status": self.status.id, "priority": 3, "urgency": 5}
        response = self.client.put(
            path=reverse("api_services_tickets", kwargs={"object_ptr": self.ticket.id}),
            content_type=self.content_type,
            data=json.dumps(updates),
            **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

    def test_create_ticket(self):
        new_ticket = {"name": "Api creates", "status": self.status.id, "priority": 3, "urgency": 5}
        response = self.client.post(
            path=reverse("api_services_tickets") + "?" + urllib.urlencode({"queue_id": self.queue.id}),
            content_type=self.content_type,
            data=json.dumps(new_ticket),
            **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEquals(new_ticket["name"], data["name"])
        self.assertEquals(new_ticket["urgency"], data["urgency"])
        self.assertEquals(new_ticket["priority"], data["priority"])
        self.assertEquals(new_ticket["status"], data["status"]["id"])