def test_published_project_with_incomplete_default_locale_raises_error(
            self, mock_project, mock_user):
        # Arrange
        stub_project = Project()
        stub_project.status = ProjectStatus.PUBLISHED.value

        mock_project.return_value = stub_project

        locales = []
        info = ProjectInfoDTO()
        info.locale = "en"
        info.name = "Test"
        locales.append(info)

        dto = ProjectDTO()
        dto.project_id = 1
        dto.default_locale = "en"
        dto.project_info_locales = locales
        dto.project_status = ProjectStatus.PUBLISHED.name

        stub_admin_user = User()
        stub_admin_user.username = "******"
        stub_admin_user.role = UserRole.ADMIN.value

        mock_user.return_value = stub_admin_user
        # Act / Assert
        with self.assertRaises(ProjectAdminServiceError):
            ProjectAdminService.update_project(dto, mock_user.id)
    def test_updating_a_project_with_different_roles(self, mock_project,
                                                     mock_project2, mock_user):
        stub_project = Project()
        stub_project.status = ProjectStatus.DRAFT.value

        mock_project.return_value = stub_project

        locales = []
        info = ProjectInfoDTO()
        info.locale = "en"
        info.name = "Test"
        locales.append(info)

        dto = ProjectDTO()
        dto.project_id = 1
        dto.default_locale = "en"
        dto.project_status = ProjectStatus.DRAFT.name
        dto.project_priority = ProjectPriority.LOW.name
        dto.mapper_level = MappingLevel.BEGINNER.name
        dto.mapping_types = ["ROADS"]
        dto.mapping_editors = ["ID"]
        dto.validation_editors = ["ID"]
        dto.project_info_locales = locales

        stub_user = User()
        stub_user.username = "******"
        stub_user.role = UserRole.MAPPER.value

        mock_user.return_value = stub_user

        with self.assertRaises(ValueError) as e:
            ProjectAdminService.update_project(dto, mock_user.id)
        the_exception = e.exception
        self.assertTrue(isinstance(the_exception, ValueError))

        # stub_project.author_id = mock_user.id

        stub_user.username = "******"
        stub_user.role = UserRole.ADMIN.value
        mock_user.return_value = stub_user

        try:
            ProjectAdminService.update_project(dto, mock_user.id)
        except ProjectAdminServiceError:
            self.fail("update_project raised an exception with admin role")
    def test_updating_a_private_project_with_no_allowed_users_causes_an_error(
            self, mock_project, mock_user):
        # Arrange
        mock_project.return_value = Project()

        dto = ProjectDTO()
        dto.private = True
        dto.allowed_usernames = []

        stub_user = User()
        stub_user.username = "******"
        stub_user.role = UserRole.ADMIN.value

        mock_user.return_value = stub_user

        with self.assertRaises(ProjectAdminServiceError):
            ProjectAdminService.update_project(dto, mock_user.id)
    def test_valid_geo_json_attaches_task_to_project(self):
        # Arrange
        valid_feature_collection = json.loads(
            '{"features": [{"geometry": {"coordinates": [[[[-4.0237, 56.0904],'
            '[-3.9111, 56.1715], [-3.8122, 56.098], [-4.0237, 56.0904]]]], "type":'
            '"MultiPolygon"}, "properties": {"x": 2402, "y": 1736, "zoom": 12, "isSquare": true}, "type":'
            '"Feature"}], "type": "FeatureCollection"}')

        test_project = Project()

        # Act
        ProjectAdminService._attach_tasks_to_project(test_project,
                                                     valid_feature_collection)

        # Assert
        self.assertEqual(
            1,
            test_project.tasks.count(),
            "One task should have been attached to project",
        )
Exemple #5
0
    def test_updating_a_private_project_with_no_allowed_users(
            self, mock_project, mock_project2, mock_user):
        # Arrange
        mock_project.return_value = Project()

        dto = ProjectDTO()
        dto.private = True
        dto.allowed_usernames = []

        stub_user = User()
        stub_user.username = "******"
        stub_user.role = UserRole.ADMIN.value

        mock_user.return_value = stub_user

        try:
            ProjectAdminService.update_project(dto, mock_user.id)
        except ProjectAdminServiceError:
            self.fail(
                "update_project raised an exception when setting it as private"
            )