Esempio n. 1
0
 def test_model(self):
     "Test Services models"
     status = TicketStatus(name='TestStatus')
     status.save()
     self.assertNotEquals(status.id, None)
     
     queue = TicketQueue(name='TestQueue', default_ticket_status=status)
     queue.save()
     self.assertNotEquals(status.id, None)
     
     ticket = Ticket(name='TestTicket', status=status, queue=queue)
     ticket.save()
     self.assertNotEquals(ticket.id, None)
     
     ticket.delete()
     queue.delete()
     status.delete()
Esempio n. 2
0
 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
Esempio n. 3
0
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')) 
Esempio n. 4
0
 def create_instance(self, request, *args, **kwargs):
     ticket = Ticket(creator=request.user.get_profile())
     if not request.agent:
         if request.queue:
             ticket.queue = request.queue
             if request.queue.default_ticket_status:
                 ticket.status = request.queue.default_ticket_status
             else:
                 try:
                     conf = ModuleSetting.get_for_module('maker.services', 'default_ticket_status')[0]
                     ticket.status = TicketStatus.objects.get(pk=long(conf.value))
                 except:
                     if 'statuses' in request.context:
                         try:
                             ticket.status = request.context['statuses'][0]
                         except:
                             pass
             ticket.priority = request.queue.default_ticket_priority
             ticket.service = request.queue.default_service
         else:
             try:
                 conf = ModuleSetting.get_for_module('maker.services', 'default_ticket_status')[0]
                 ticket.status = TicketStatus.objects.get(pk=long(conf.value))
             except:
                 if 'statuses' in request.context:
                     try:
                         ticket.status = request.context['statuses'][0]
                     except:
                         pass
             try:
                 conf = ModuleSetting.get_for_module('maker.services', 'default_ticket_queue')[0]
                 ticket.queue = TicketQueue.objects.get(pk=long(conf.value))
             except:
                 if 'queues' in request.context:
                     try:
                         ticket.queue = request.context['queues'][0]
                     except:
                         pass
         try:
             ticket.caller = request.user.get_profile().get_contact()
         except:
             pass
     return ticket
Esempio n. 5
0
def settings_view(request, response_format='html'):
    "Settings"
    
    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")
    
    
    # default ticket status
    try:
        conf = ModuleSetting.get_for_module('maker.services', 'default_ticket_status')[0]
        default_ticket_status = TicketStatus.objects.get(pk=long(conf.value))
    except Exception:
        default_ticket_status = None

    # default queue
    try:
        conf = ModuleSetting.get_for_module('maker.services', 'default_ticket_queue')[0]
        default_ticket_queue = TicketQueue.objects.get(pk=long(conf.value))
    except Exception:
        default_ticket_queue = None
        
    # notify ticket caller by email
    try:
        conf = ModuleSetting.get_for_module('maker.services', 'send_email_to_caller')[0]
        send_email_to_caller = conf.value
    except Exception:
        send_email_to_caller = settings.HARDTREE_SEND_EMAIL_TO_CALLER
        
    # notification template
    send_email_example = ''
    try:
        conf = ModuleSetting.get_for_module('maker.services', 'send_email_template')[0]
        send_email_template = conf.value
    except Exception:
        send_email_template = None
        
    queues = TicketQueue.objects.filter(trash=False, parent__isnull=True)
    statuses = TicketStatus.objects.filter(trash=False)

    if send_email_to_caller:
        # Render example e-mail
        try:
            ticket = Object.filter_by_request(request, Ticket.objects.filter(status__hidden=False, caller__isnull=False))[0]
        except IndexError:
            ticket = Ticket(reference='REF123', name='New request')
        if not ticket.caller:
            try:
                caller = Object.filter_by_request(request, Contact.objects)[0]
            except IndexError:
                caller = Contact(name='John Smith')
            ticket.caller = caller
        try:
            ticket.status
        except:
            ticket.status = None
        if not ticket.status:
            try:
                ticket.status = statuses[0]
            except IndexError:
                ticket.status = TicketStatus(name='Open')
        if send_email_template:
            try:
                send_email_example = render_string_template(send_email_template, {'ticket': ticket})
            except:
                send_email_example = render_to_string('services/emails/notify_caller', {'ticket': ticket}, response_format='html')
        else:
            send_email_example = render_to_string('services/emails/notify_caller', {'ticket': ticket}, response_format='html')
            
    
    
    context = _get_default_context(request)
    context.update({'settings_queues': queues,
                    'settings_statuses': statuses,
                    'default_ticket_status': default_ticket_status,
                    'default_ticket_queue': default_ticket_queue,
                    'send_email_to_caller': send_email_to_caller,
                    'send_email_example': send_email_example})
    
    return render_to_response('services/settings_view', context,
                              context_instance=RequestContext(request), response_format=response_format)
Esempio n. 6
0
def ticket_add(request, queue_id=None, response_format='html'):
    "Ticket add"
    
    context = _get_default_context(request)
    agent = context['agent']
    profile = request.user.get_profile()
    
    queue = None
    if queue_id:
        queue = get_object_or_404(TicketQueue, pk=queue_id)
        if not profile.has_permission(queue, mode='x'):
            queue = None

    if request.POST:
        if not 'cancel' in request.POST:
            ticket = Ticket(creator=profile)
            if not agent:
                if queue:
                    ticket.queue = queue
                    if queue.default_ticket_status:
                        ticket.status = queue.default_ticket_status
                    else:
                        try:
                            conf = ModuleSetting.get_for_module('maker.services', 'default_ticket_status')[0]
                            ticket.status = TicketStatus.objects.get(pk=long(conf.value))
                        except:
                            if 'statuses' in context:
                                try:
                                    ticket.status = context['statuses'][0]
                                except:
                                    pass
                    ticket.priority = queue.default_ticket_priority
                    ticket.service = queue.default_service
                else:
                    try:
                        conf = ModuleSetting.get_for_module('maker.services', 'default_ticket_status')[0]
                        ticket.status = TicketStatus.objects.get(pk=long(conf.value))
                    except:
                        if 'statuses' in context:
                            try:
                                ticket.status = context['statuses'][0]
                            except:
                                pass
                    try:
                        conf = ModuleSetting.get_for_module('maker.services', 'default_ticket_queue')[0]
                        ticket.queue = TicketQueue.objects.get(pk=long(conf.value))
                    except:
                        if 'queues' in context:
                            try:
                                ticket.queue = context['queues'][0]
                            except:
                                pass
                try:
                    ticket.caller = profile.get_contact()
                except:
                    pass
            form = TicketForm(profile, queue, agent, request.POST, instance=ticket)
            if form.is_valid():
                ticket = form.save()
                ticket.set_user_from_request(request)
                return HttpResponseRedirect(reverse('services_ticket_view', args=[ticket.id]))
        else:
            return HttpResponseRedirect(reverse('services'))
    else:
        form = TicketForm(request.user.get_profile(), queue, agent)
    
    context.update({'form': form, 'queue': queue})

    return render_to_response('services/ticket_add', context,
                              context_instance=RequestContext(request), response_format=response_format)
Esempio n. 7
0
    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
Esempio n. 8
0
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"])