예제 #1
0
    def test_list_project(self):
        """Test listing projects"""
        projectLeader = sample_user(email='*****@*****.**')
        sample_project(projectLeader=projectLeader)
        sample_project(name='test 2', projectLeader=projectLeader)

        res = self.client.get(PROJECT_URL)

        projects = models.Project.objects.all().order_by('id')
        serializer = serializers.ProjectSerializer(projects, many=True)
        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(res.data, serializer.data)
예제 #2
0
    def test_view_project_fail_inactive_user(self):
        """Test is_active in project membership required"""
        user = sample_user(email='*****@*****.**')
        project = sample_project(name='my super test', projectLeader=user)
        models.ProjectMembership.objects.create(user=self.user,
                                                project=project,
                                                is_active=False)
        url = detail_project_url(project.id)
        res = self.client.get(url)

        self.assertEqual(res.status_code, status.HTTP_403_FORBIDDEN)
예제 #3
0
    def test_retrieve_project_as_admin(self):
        """Test retrieving a project"""
        projectLeader = sample_user(email='*****@*****.**')
        project = sample_project(projectLeader=projectLeader)

        url = detail_project_url(project.id)
        res = self.client.get(url)

        serializer = serializers.ProjectDetailSerializer(project)

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(res.data, serializer.data)
예제 #4
0
    def test_retrieve_project_as_member(self):
        """Test retrieving a project as a member of the project"""
        project = sample_project()
        models.ProjectMembership.objects.create(user=self.user,
                                                project=project,
                                                is_active=True)

        url = detail_project_url(project.id)
        res = self.client.get(url)

        serializer = serializers.ProjectDetailSerializer(project)
        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(res.data, serializer.data)
예제 #5
0
    def test_assign_place_to_project(self):
        """Test assign place to a project"""
        project = sample_project(projectLeader=self.user)
        place = sample_place()

        payload = {'place_id': place.id}
        url = assign_place_project_url(project.id)

        res = self.client.patch(url, payload)

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        project.refresh_from_db()
        self.assertIn(place, project.places.all())
예제 #6
0
    def test_assign_user_to_project(self):
        """Test assign user to a project"""
        project = sample_project(projectLeader=self.user)
        user = sample_user(email="*****@*****.**")

        payload = {'user_id': user.id}
        url = assign_user_project_url(project.id)

        res = self.client.patch(url, payload)

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        project.refresh_from_db()
        self.assertIn(user, project.members.all())
예제 #7
0
    def test_list_project_as_member(self):
        """Test listing projects"""
        projectLeader = sample_user(email='*****@*****.**')
        project1 = sample_project(projectLeader=projectLeader)
        project2 = sample_project(name='test 2', projectLeader=projectLeader)
        project3 = sample_project(name='test 3', projectLeader=projectLeader)

        models.ProjectMembership.objects.create(user=self.user,
                                                project=project1,
                                                is_active=True)
        models.ProjectMembership.objects.create(user=self.user,
                                                project=project2,
                                                is_active=True)

        res = self.client.get(PROJECT_URL)

        projects = models.Project.objects.filter(
            members=self.user).order_by('id')
        serializer = serializers.ProjectSerializer(projects, many=True)
        serializer3 = serializers.ProjectSerializer(project3, many=False)
        self.assertEqual(res.status_code, status.HTTP_200_OK)
        self.assertEqual(res.data, serializer.data)
        self.assertNotIn(serializer3.data, res.data)
예제 #8
0
    def test_update_project(self):
        """Test updating project"""
        project = sample_project()
        projectLeader = sample_user(email='*****@*****.**',
                                    name='other leader')
        payload = {
            'name': 'new project name',
            'projectLeader': projectLeader.id,
        }

        url = detail_project_url(project.id)
        res = self.client.patch(url, payload)

        self.assertEqual(res.status_code, status.HTTP_200_OK)
        project.refresh_from_db()

        self.assertEqual(project.name, payload['name'])
        self.assertEqual(project.projectLeader.id, payload['projectLeader'])