Example #1
0
 def test_model_task_status(self):
     "Test task status"
     obj = TaskStatus(name='test')
     obj.save()
     self.assertEquals('test', obj.name)
     self.assertNotEquals(obj.id, None)
     obj.delete()
Example #2
0
 def test_model_task(self):
     "Test task"
     project = Project(name='test')
     project.save()
     
     status = TaskStatus(name='test')
     status.save()
     
     obj = Task(name='test', project=project, status=status, priority=3)
     obj.save()
     self.assertEquals(project, obj.project)
     self.assertNotEquals(obj.id, None)
     obj.delete()
Example #3
0
class ProjectsViewsTest(TestCase):
    "Projects 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.project = Project(name='test', manager=self.contact, client=self.contact)
            self.project.set_default_user()
            self.project.save()
            
            self.status = TaskStatus(name='test')
            self.status.set_default_user()
            self.status.save()
            
            self.milestone = Milestone(name='test', project=self.project, status=self.status)
            self.milestone.set_default_user()
            self.milestone.save()  
            
            self.task = Task(name='test', project=self.project, status=self.status, priority=3)
            self.task.set_default_user()
            self.task.save()
            
            self.time_slot = TaskTimeSlot(task=self.task, details='test', time_from=datetime.now(), user=self.user)
            self.time_slot.set_default_user()
            self.time_slot.save()
            
            self.parent = Project(name='test')
            self.parent.set_default_user()
            self.parent.save() 
            
            self.parent_task = Task(name='test', project=self.project, status=self.status, priority=3)
            self.parent_task.set_default_user()
            self.parent_task.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 /projects/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('projects'))
        self.assertEquals(response.status_code, 200) 


    # Projects
   
    def test_project_add(self):
        "Test index page with login at /projects/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('project_add'))
        self.assertEquals(response.status_code, 200) 
        
        
    def test_project_add_typed(self):
        "Test index page with login at /projects/add/<project_id>/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('projects_project_add_typed', args=[self.parent.id]))
        self.assertEquals(response.status_code, 200)   
   
    
    def test_project_view_login(self):
        "Test index page with login at /projects/view/<project_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('projects_project_view', args=[self.project.id]))
        self.assertEquals(response.status_code, 200)

        
    def test_project_edit_login(self):
        "Test index page with login at /projects/edit//<project_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('projects_project_edit', args=[self.project.id]))
        self.assertEquals(response.status_code, 200)

        
    def test_project_delete_login(self):
        "Test index page with login at /projects/delete//<project_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('projects_project_delete', args=[self.project.id]))
        self.assertEquals(response.status_code, 200)


        
    # Milestones
    
    def test_milestone_add(self):
        "Test index page with login at /projects/milestone/add"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_milestone_add'))
        self.assertEquals(response.status_code, 200)    
        
        
    def test_milestone_add_typed(self):
        "Test index page with login at /projects/milestone/add/<project_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_milestone_add_typed', args=[self.parent.id]))
        self.assertEquals(response.status_code, 200)
    
    
    def test_milestone_view_login(self):
        "Test index page with login at /projects/milestone/view/<milestone_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_milestone_view', args=[self.milestone.id]))
        self.assertEquals(response.status_code, 200)

        
    def test_milestone_edit_login(self):
        "Test index page with login at /projects/milestone/edit/<milestone_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('projects_milestone_edit', args=[self.milestone.id]))
        self.assertEquals(response.status_code, 200)

        
    def test_milestone_delete_login(self):
        "Test index page with login at /projects/milestone/delete/<milestone_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_milestone_delete', args=[self.milestone.id]))
        self.assertEquals(response.status_code, 200)

        
    # Tasks
 
    def test_task_add(self):
        "Test index page with login at /projects/task/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_task_add'))
        self.assertEquals(response.status_code, 200)
        
        
    def test_task_add_typed(self):
        "Test index page with login at /projects/task/add/<project_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_task_add_typed', args=[self.project.id]))
        self.assertEquals(response.status_code, 200)
        
        
    def test_task_add_to_milestone(self):
        "Test index page with login at /projects/task/add/<milestone_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_task_add_to_milestone', args=[self.milestone.id]))
        self.assertEquals(response.status_code, 200)
        
        
    def test_task_add_subtask(self):
        "Test index page with login at /projects/task/add/<task_id>/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_task_add_subtask', args=[self.parent_task.id]))
        self.assertEquals(response.status_code, 200)
                
        
    def test_task_set_status(self):
        "Test index page with login at /projects/task/add/<task_id>/status/<status_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_task_set_status', args=[self.task.id, self.status.id]))
        self.assertEquals(response.status_code, 200)
 
    
    def test_task_view_login(self):
        "Test index page with login at /projects/task/view/<task_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_task_view', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

        
    def test_task_edit_login(self):
        "Test index page with login at /projects/task/edit/<task_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_task_edit', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

        
    def test_task_delete_login(self):
        "Test index page with login at /projects/task/delete/<task_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_task_delete', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

        
    # Task Time Slots
 
    def test_time_slot_add(self):
        "Test index page with login at /projects/task/view/time/<task_id>add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_task_time_slot_add', args=[self.task.id]))
        self.assertEquals(response.status_code, 200) 
 
    
    def test_time_slot_view_login(self):
        "Test index page with login at /projects/task/view/time/<time_slot_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_task_view', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)
  
        
    def test_time_slot_edit_login(self):
        "Test index page with login at /projects/task/edit/time/<time_slot_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_task_edit', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

        
    def test_time_slot_delete_login(self):
        "Test index page with login at /projects/task/delete/time/<time_slot_id>"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_task_delete', args=[self.task.id]))
        self.assertEquals(response.status_code, 200)

        
    # Task Statuses

    def test_task_status_add(self):
        "Test index page with login at /projects/task/status/add/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_task_status_add'))
        self.assertEquals(response.status_code, 200)


    def test_task_status_view_login(self):
        "Test index page with login at /projects/task/status/view/<status_id>/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_index_by_status', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)

        
    def test_task_status_edit_login(self):
        "Test index page with login at /projects/task/status/edit/<status_id>/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_task_status_edit', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)
 
        
    def test_task_status_delete_login(self):
        "Test index page with login at /projects/task/status/delete/<status_id>/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/')
        response = self.client.get(reverse('projects_task_status_delete', args=[self.status.id]))
        self.assertEquals(response.status_code, 200)

    # Settings
    
    def test_project_settings_view(self):
        "Test index page with login at /projects/settings/view/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_settings_view'))
        self.assertEquals(response.status_code, 200)
        
        
    def test_project_settings_edit(self):
        "Test index page with login at /projects/settings/edit/"
        response = self.client.post('/accounts/login',
                                    {'username': self.username, 'password': self.password })
        self.assertRedirects(response, '/') 
        response = self.client.get(reverse('projects_settings_edit'))
        self.assertEquals(response.status_code, 200)
        
    
    ######################################
    # Testing views when user is not logged in
    ######################################
    
    def test_index(self):
        "Test index page at /projects/"
        response = self.client.get('/projects/')
        # Redirects as unauthenticated
        self.assertRedirects(response, reverse('user_login')) 
        
        
    # Projects
   
    def test_project_add_out(self):
        "Testing /projects/add/"
        response = self.client.get(reverse('project_add'))
        self.assertRedirects(response, reverse('user_login'))  
        
    def test_project_add_typed_out(self):
        "Testing /projects/add/<project_id>/"
        response = self.client.get(reverse('projects_project_add_typed', args=[self.parent.id]))
        self.assertRedirects(response, reverse('user_login'))    
   
    def test_project_view_out(self):
        "Testing /projects/view/<project_id>"
        response = self.client.get(reverse('projects_project_view', args=[self.project.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_project_edit_out(self):
        "Testing /projects/edit//<project_id>"
        response = self.client.get(reverse('projects_project_edit', args=[self.project.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_project_delete_out(self):
        "Testing /projects/delete//<project_id>"
        response = self.client.get(reverse('projects_project_delete', args=[self.project.id]))
        self.assertRedirects(response, reverse('user_login')) 

        
    # Milestones
    
    def test_milestone_add_out(self):
        "Testing /projects/milestone/add"
        response = self.client.get(reverse('projects_milestone_add'))
        self.assertRedirects(response, reverse('user_login'))   
        
    def test_milestone_add_typed_out(self):
        "Testing /projects/milestone/add/<project_id>"
        response = self.client.get(reverse('projects_milestone_add_typed', args=[self.parent.id]))
        self.assertRedirects(response, reverse('user_login')) 
    
    def test_milestone_view_out(self):
        "Testing /projects/milestone/view/<milestone_id>"
        response = self.client.get(reverse('projects_milestone_view', args=[self.milestone.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_milestone_edit_out(self):
        "Testing /projects/milestone/edit/<milestone_id>"
        response = self.client.get(reverse('projects_milestone_edit', args=[self.milestone.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_milestone_delete_out(self):
        "Testing /projects/milestone/delete/<milestone_id>"
        response = self.client.get(reverse('projects_milestone_delete', args=[self.milestone.id]))
        self.assertRedirects(response, reverse('user_login')) 

        
    # Tasks
 
    def test_task_add_out(self):
        "Testing /projects/task/add/"
        response = self.client.get(reverse('projects_task_add'))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_task_add_typed_out(self):
        "Testing /projects/task/add/<project_id>"
        response = self.client.get(reverse('projects_task_add_typed', args=[self.project.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_task_add_to_milestone_out(self):
        "Testing /projects/task/add/<milestone_id>" 
        response = self.client.get(reverse('projects_task_add_to_milestone', args=[self.milestone.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_task_add_subtask_out(self):
        "Testing /projects/task/add/<task_id>/"
        response = self.client.get(reverse('projects_task_add_subtask', args=[self.parent_task.id]))
        self.assertRedirects(response, reverse('user_login')) 
                
    def test_task_set_status_out(self):
        "Testing /projects/task/add/<task_id>/status/<status_id>"
        response = self.client.get(reverse('projects_task_set_status', args=[self.task.id, self.status.id]))
        self.assertRedirects(response, reverse('user_login')) 
 
    def test_task_view_out(self):
        "Testing /projects/task/view/<task_id>"
        response = self.client.get(reverse('projects_task_view', args=[self.task.id]))
        self.assertRedirects(response, reverse('user_login')) 

    def test_task_edit_out(self):
        "Testing /projects/task/edit/<task_id>"
        response = self.client.get(reverse('projects_task_edit', args=[self.task.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_task_delete_out(self):
        "Testing /projects/task/delete/<task_id>" 
        response = self.client.get(reverse('projects_task_delete', args=[self.task.id]))
        self.assertRedirects(response, reverse('user_login')) 

    
    # Task Time Slots
 
    def test_time_slot_add_out(self):
        "Testing /projects/task/view/time/<task_id>add/"
        response = self.client.get(reverse('projects_task_time_slot_add', args=[self.task.id]))
        self.assertRedirects(response, reverse('user_login')) 
    
    def test_time_slot_view_out(self):
        "Testing /projects/task/view/time/<time_slot_id>"
        response = self.client.get(reverse('projects_task_view', args=[self.task.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_time_slot_edit_out(self):
        "Testing /projects/task/edit/time/<time_slot_id>"
        response = self.client.get(reverse('projects_task_edit', args=[self.task.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_time_slot_delete_out(self):
        "Testing /projects/task/delete/time/<time_slot_id>" 
        response = self.client.get(reverse('projects_task_delete', args=[self.task.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    # Task Statuses

    def test_task_status_add_out(self):
        "Testing /projects/task/status/add/"
        response = self.client.get(reverse('projects_task_status_add'))
        self.assertRedirects(response, reverse('user_login')) 

    def test_task_status_view_out(self):
        "Testing /projects/task/status/view/<status_id>/"
        response = self.client.get(reverse('projects_index_by_status', args=[self.status.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_task_status_edit_out(self):
        "Testing /projects/task/status/edit/<status_id>/"
        response = self.client.get(reverse('projects_task_status_edit', args=[self.status.id]))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_task_status_delete_out(self):
        "Testing /projects/task/status/delete/<status_id>/"
        response = self.client.get(reverse('projects_task_status_delete', args=[self.status.id]))
        self.assertRedirects(response, reverse('user_login')) 

    # Settings
    
    def test_project_settings_view_out(self):
        "Testing /projects/settings/view/"
        response = self.client.get(reverse('projects_settings_view'))
        self.assertRedirects(response, reverse('user_login')) 
        
    def test_project_settings_edit_out(self):
        "Testing /projects/settings/edit/"
        response = self.client.get(reverse('projects_settings_edit'))
        self.assertRedirects(response, reverse('user_login')) 
Example #4
0
class ProjectsAPITest(TestCase):
    "Projects functional tests for api"
    username = "******"
    password = "******"
    prepared = False
    authentication_headers = {
        "CONTENT_TYPE": "application/json",
        "HTTP_AUTHORIZATION": "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk",
    }
    content_type = "application/json"

    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="api_test")
            except Group.DoesNotExist:
                Group.objects.all().delete()
                self.group = Group(name="api_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_default_user()
                perspective.save()

            ModuleSetting.set("default_perspective", perspective.id)

            self.contact_type = ContactType(name="api_test")
            self.contact_type.set_default_user()
            self.contact_type.save()

            self.contact = Contact(name="api_test", contact_type=self.contact_type)
            self.contact.set_default_user()
            self.contact.save()

            self.project = Project(name="api_test", manager=self.contact, client=self.contact)
            self.project.set_default_user()
            self.project.save()

            self.status = TaskStatus(name="api_test")
            self.status.set_default_user()
            self.status.save()

            self.milestone = Milestone(name="api_test", project=self.project, status=self.status)
            self.milestone.set_default_user()
            self.milestone.save()

            self.task = Task(name="api_test", project=self.project, status=self.status, priority=3)
            self.task.set_default_user()
            self.task.save()

            self.time_slot = TaskTimeSlot(
                task=self.task, details="api_test", time_from=datetime.now(), user=self.user.get_profile()
            )
            self.time_slot.set_default_user()
            self.time_slot.save()

            self.parent = Project(name="api_test")
            self.parent.set_default_user()
            self.parent.save()

            self.parent_task = Task(name="api_test", project=self.project, status=self.status, priority=3)
            self.parent_task.set_default_user()
            self.parent_task.save()

            self.client = Client()

            self.prepared = True

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

    # Get info about projects, milestones, status, tasks, tasktimes.

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

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

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

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

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

    def test_get_project(self):
        response = self.client.get(
            reverse("api_projects", kwargs={"object_ptr": self.project.id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEquals(data["id"], self.project.id)
        self.assertEquals(data["name"], self.project.name)
        self.assertEquals(data["details"], self.project.details)

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

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

    def test_get_milestone(self):
        response = self.client.get(
            reverse("api_projects_milestones", kwargs={"object_ptr": self.milestone.id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEquals(data["id"], self.milestone.id)
        self.assertEquals(data["name"], self.milestone.name)
        self.assertEquals(data["project"]["id"], self.milestone.project.id)
        self.assertEquals(data["status"]["id"], self.milestone.status.id)

    def test_get_task(self):
        response = self.client.get(
            reverse("api_projects_tasks", kwargs={"object_ptr": self.task.id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

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

    def test_get_timeslot(self):
        response = self.client.get(
            reverse("api_projects_tasktimes", kwargs={"object_ptr": self.time_slot.id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEquals(data["id"], self.time_slot.id)
        self.assertEquals(data["task"]["id"], self.time_slot.task.id)

    # Common test

    def test_common_project(self):

        # create new project
        new_project = {"name": "api test", "details": "<p>test details</p>"}
        response = self.client.post(
            reverse("api_projects"),
            data=json.dumps(new_project),
            content_type=self.content_type,
            **self.authentication_headers
        )
        # print response.request
        self.assertEquals(response.status_code, 200)

        # check data in response
        data = json.loads(response.content)
        self.assertEquals(data["name"], new_project["name"])
        self.assertEquals(data["details"], new_project["details"])
        project_id = data["id"]

        # get info about new project
        response = self.client.get(
            path=reverse("api_projects", kwargs={"object_ptr": project_id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

        # get statuses list
        response = self.client.get(path=reverse("api_projects_status"), **self.authentication_headers)
        self.assertEquals(response.status_code, 200)

        statuses = json.loads(response.content)
        fstatus = statuses[0]["id"]

        # create new task status
        new_status = {"name": "Open api test", "active": True, "hidden": False, "details": "<p>test details</p>"}
        response = self.client.post(
            reverse("api_projects_status"),
            data=json.dumps(new_status),
            content_type=self.content_type,
            **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEquals(data["name"], new_status["name"])
        self.assertEquals(data["active"], new_status["active"])
        self.assertEquals(data["hidden"], new_status["hidden"])
        self.assertEquals(data["details"], new_status["details"])
        sstatus = data["id"]

        # create new milestone
        new_milestone = {
            "name": "api test milestone",
            "status": fstatus,
            "project": project_id,
            "start_date": "2011-06-09 12:00:00",
            "details": "<p>test details</p>",
        }
        response = self.client.post(
            reverse("api_projects_milestones"),
            data=json.dumps(new_milestone),
            content_type=self.content_type,
            **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEquals(data["name"], new_milestone["name"])
        self.assertEquals(data["status"]["id"], new_milestone["status"])
        self.assertEquals(data["project"]["id"], new_milestone["project"])
        self.assertEquals(data["details"], new_milestone["details"])
        milestone_id = data["id"]

        #  create new task
        new_task = {
            "name": "api test task",
            "status": sstatus,
            "project": project_id,
            "milestone": milestone_id,
            "priority": 5,
            "start_date": "2011-06-02 12:00:00",
            "estimated_time": 5000,
            "details": "<p>test details</p>",
        }
        response = self.client.post(
            reverse("api_projects_tasks"),
            data=json.dumps(new_task),
            content_type=self.content_type,
            **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEquals(data["name"], new_task["name"])
        self.assertEquals(data["priority"], new_task["priority"])
        self.assertEquals(data["status"]["id"], new_task["status"])
        self.assertEquals(data["project"]["id"], new_task["project"])
        self.assertEquals(data["milestone"]["id"], new_task["milestone"])
        self.assertEquals(data["estimated_time"], new_task["estimated_time"])
        self.assertEquals(data["details"], new_task["details"])
        task_id = data["id"]

        # create new subtask
        new_sub_task = {
            "name": "api test task",
            "status": sstatus,
            "parent": task_id,
            "project": project_id,
            "priority": 5,
            "start_date": "2011-06-02 13:00:00",
            "estimated_time": 2500,
            "details": "<p>test details</p>",
        }

        response = self.client.post(
            reverse("api_projects_tasks"),
            data=json.dumps(new_sub_task),
            content_type=self.content_type,
            **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEquals(data["name"], new_sub_task["name"])
        self.assertEquals(data["priority"], new_sub_task["priority"])
        self.assertEquals(data["status"]["id"], new_sub_task["status"])
        self.assertEquals(data["parent"]["id"], new_sub_task["parent"])
        self.assertEquals(data["project"]["id"], new_sub_task["project"])
        self.assertEquals(data["estimated_time"], new_sub_task["estimated_time"])
        self.assertEquals(data["details"], new_sub_task["details"])
        sub_task_id = data["id"]

        # create task time
        new_tasktime = {"task": task_id, "minutes": 400, "details": "<p>test details</p>"}

        response = self.client.post(
            reverse("api_projects_tasktimes"),
            data=json.dumps(new_tasktime),
            content_type=self.content_type,
            **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

        data = json.loads(response.content)
        self.assertEquals(data["task"]["id"], new_tasktime["task"])
        self.assertEquals(data["details"], new_tasktime["details"])
        tasktime_id = data["id"]

        # start task time
        response = self.client.get(
            path=reverse("api_projects_tasktime_start", kwargs={"task_id": sub_task_id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

        data = json.loads(response.content)
        slot_id = data["id"]

        sleep(60)

        # stop task time
        response = self.client.post(
            reverse("api_projects_tasktime_stop", kwargs={"slot_id": slot_id}),
            data=json.dumps({"details": "<p>test details</p>"}),
            content_type=self.content_type,
            **self.authentication_headers
        )
        self.assertEquals(response.status_code, 200)

        # delete task time
        response = self.client.delete(
            reverse("api_projects_tasktimes", kwargs={"object_ptr": tasktime_id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 204)

        # delete task
        response = self.client.delete(
            reverse("api_projects_tasks", kwargs={"object_ptr": task_id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 204)

        # check subtask
        response = self.client.get(
            path=reverse("api_projects_tasks", kwargs={"object_ptr": sub_task_id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 404)

        # delete milestone
        response = self.client.delete(
            reverse("api_projects_milestones", kwargs={"object_ptr": milestone_id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 204)

        # delete status
        response = self.client.delete(
            reverse("api_projects_status", kwargs={"object_ptr": sstatus}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 204)

        # delete project
        response = self.client.delete(
            reverse("api_projects", kwargs={"object_ptr": project_id}), **self.authentication_headers
        )
        self.assertEquals(response.status_code, 204)