Ejemplo n.º 1
0
    def step6__delete_version(self, test_context):
        version_list = self.get_version_list(test_context)
        first_version = version_list[1]

        # delete a version without access rights -> must fail
        response = self.rest_delete_version(
            endpoint=test_context.endpoint,
            endpoint_id=test_context.endpoint_id,
            extension_id=first_version['pk'],
            http_info=HttpInfo(self.token_no_access))
        self.get_asserter().assertEquals(
            response.status_code, HTTP_404_NOT_FOUND,
            "User without access rights shouldn't be able to delete a version")

        # delete a version with access rights
        response = self.rest_delete_version(
            endpoint=test_context.endpoint,
            endpoint_id=test_context.endpoint_id,
            extension_id=first_version['pk'],
            http_info=HttpInfo(self.token_full_access))
        self.get_asserter().assertEquals(
            response.status_code, HTTP_204_NO_CONTENT,
            "User with access rights should be able to delete a version")

        # check that there is only one version now
        version_list = self.get_version_list(test_context)
        self.get_asserter().assertEquals(
            len(version_list), 1,
            "There should be exactly one version after step 5")
    def setUp(self):
        self.superuser, self.token = self.create_user_and_login(
            "superuser", is_superuser=True)
        self.http_info = HttpInfo(auth_token=self.token,
                                  user_agent=HTTP_USER_AGENT,
                                  remote_address=REMOTE_ADDRESS)

        self.project = self.create_project(self.token, "MyProject",
                                           "My test project",
                                           Project.INITIALIZED, **http_info)

        self.labbook, response = self.create_labbook_orm(
            self.token, self.project.pk, "My labbook", False, **http_info)

        self.note, response = self.create_note_orm(self.token, self.project.pk,
                                                   "My note",
                                                   "My note content",
                                                   **http_info)

        note_content_type_id = Note.get_content_type().id
        self.rest_add_labbook_element(self.token, self.labbook.pk,
                                      note_content_type_id, self.note.pk, 0, 0,
                                      100, 100, **http_info)

        self.version_pk = self.create_version("labbooks", self.labbook.pk)
Ejemplo n.º 3
0
 def __step3_get_latest_version(self, test_context, token):
     version_list = self.get_version_list(test_context)
     version = version_list[0]
     return self.rest_get_version(endpoint=test_context.endpoint,
                                  endpoint_id=test_context.endpoint_id,
                                  extension_id=version['pk'],
                                  http_info=HttpInfo(token))
Ejemplo n.º 4
0
    def step3__get_versions(self, test_context):
        # request version list without having access rights
        response = self.rest_get_version_list(test_context.endpoint,
                                              test_context.endpoint_id,
                                              HttpInfo(self.token_no_access))

        # check that the request fails
        self.get_asserter().assertEquals(
            response.status_code, HTTP_404_NOT_FOUND,
            "User without access rights shouldn't be able to list versions")

        # request specific version without having access rights
        response = self.__step3_get_latest_version(test_context,
                                                   self.token_no_access)
        self.get_asserter().assertEquals(
            response.status_code, HTTP_404_NOT_FOUND,
            "User without access rights shouldn't be able to see specific version"
        )

        # request specific version with reading rights
        response = self.__step3_get_latest_version(test_context,
                                                   self.token_readonly)
        self.get_asserter().assertEquals(
            response.status_code, HTTP_200_OK,
            "User with reading rights should be able to see specific version")
        version = json.loads(response.content.decode())
        self.get_asserter().assertGreaterEqual(
            version['number'], 1)  # just check that there is something there
Ejemplo n.º 5
0
 def get_version_list(self, test_context):
     response = self.rest_get_version_list(
         endpoint=test_context.endpoint,
         endpoint_id=test_context.endpoint_id,
         http_info=HttpInfo(self.token_author))
     self.get_asserter().assertEquals(response.status_code, HTTP_200_OK,
                                      "Couldn't get version list")
     return json.loads(response.content.decode())['results']
Ejemplo n.º 6
0
 def __step1_post_as_user(self, token, test_context):
     return self.rest_post_version(
         test_context.endpoint, test_context.endpoint_id,
         VersionData(
             content_type=test_context.content_type,
             object_id=test_context.endpoint_id,
             summary="Test summary.\nSecond line of test summary.",
         ).as_dict(), HttpInfo(token))
Ejemplo n.º 7
0
    def setUp(self):
        """ Set up a user, projects and shared elements"""

        self.user_group = Group.objects.get(name='User')

        self.testuser1 = User.objects.create_user(username='******',
                                                  email='*****@*****.**',
                                                  password='******')
        self.token1 = self.login_and_return_token('testuser1', 'top_secret')
        self.testuser1.groups.add(self.user_group)

        # second user to verify testuser1 can delete objects owned by a second user
        self.testuser2 = User.objects.create_user(username='******',
                                                  email='*****@*****.**',
                                                  password='******')
        self.token2 = self.login_and_return_token('testuser2',
                                                  'other_top_secret')
        self.testuser2.groups.add(self.user_group)

        # create some elements outside of a project
        self.standalone_task1 = self.rest_create_task(
            self.token1, None, "Standalone Test Task", "Test Description",
            Task.TASK_STATE_NEW, Task.TASK_PRIORITY_HIGH, datetime.now(),
            datetime.now() + timedelta(days=30), self.testuser1.pk,
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.http_info_sa_task1 = HttpInfo(auth_token=self.token1,
                                           user_agent=HTTP_USER_AGENT,
                                           remote_address=REMOTE_ADDR)
        self.sa_task1_pk = self.standalone_task1.data['pk']
        self.sa_task1_versiondata = VersionData(
            object_id=self.sa_task1_pk, summary="My version").as_dict()
        self.standalone_task1_version = self.rest_post_version(
            'tasks', self.sa_task1_pk, self.sa_task1_versiondata,
            self.http_info_sa_task1)

        self.standalone_labbook1 = self.rest_create_labbook(
            self.token1, None, "Standalone Test Labbok", False,
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.standalone_contact1 = self.rest_create_contact(
            self.token1, None, 'Dr.', 'John', 'Doe', '*****@*****.**',
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.standalone_file1 = self.rest_create_file(
            self.token1, None, 'MyStandaloneFile',
            'This is a standalone file!', 'MyStandaloneFileName', 1024,
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.standalone_note1 = self.rest_create_note(
            self.token1, None, 'This is a standalone note',
            'Still a standalone note', HTTP_USER_AGENT, REMOTE_ADDR)

        self.standalone_meeting1 = self.rest_create_meeting(
            self.token1, None, 'Standalone Appointment', 'Meet me alone!',
            timezone.now(), timezone.now(), HTTP_USER_AGENT, REMOTE_ADDR)

        self.standalone_kanban1 = self.rest_create_kanbanboard(
            self.token1, None, 'Standalone Kanban Board',
            KanbanBoard.KANBAN_BOARD_TYPE_PERSONAL, HTTP_USER_AGENT,
            REMOTE_ADDR)

        self.standalone_picture1 = self.rest_create_picture(
            self.token1, None, 'Standalone Picture', 'demo1.png',
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.dmp_form = DmpForm.objects.create(title='test dmpform title',
                                               description='test dmpform desc')

        self.dmp_status = Dmp.FINAL

        self.standalone_dmp1 = self.rest_create_dmp(
            self.token1, None, 'Test DMP Title', self.dmp_status,
            self.dmp_form.pk, HTTP_USER_AGENT, REMOTE_ADDR)

        self.standalone_drive1 = self.rest_create_drive(
            self.token1, None, "Standalone drive a - b", HTTP_USER_AGENT,
            REMOTE_ADDR)

        # create a project with elements assigned to it
        self.project1 = self.create_project(
            self.token1, "My Own Project (testuser1)",
            "Only testuser1 has access to this project", Project.STARTED,
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.project1_task1 = self.rest_create_task(
            self.token1, self.project1.pk, 'Project Test Task',
            'Test Description', Task.TASK_STATE_NEW, Task.TASK_PRIORITY_HIGH,
            datetime.now(),
            datetime.now() + timedelta(days=30), self.testuser1.pk,
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.http_info_project1_task1 = HttpInfo(auth_token=self.token1,
                                                 user_agent=HTTP_USER_AGENT,
                                                 remote_address=REMOTE_ADDR)
        self.project1_task1_pk = self.project1_task1.data['pk']
        self.project1_task1_versiondata = VersionData(
            object_id=self.project1_task1_pk,
            summary="My project 1 task 1 version").as_dict()
        self.project1_task1_version = self.rest_post_version(
            'tasks', self.project1_task1_pk, self.project1_task1_versiondata,
            self.http_info_project1_task1)

        self.project1_task2 = self.rest_create_task(
            self.token1, self.project1.pk, 'Project Test Task 2',
            'Test Description 2', Task.TASK_STATE_NEW, Task.TASK_PRIORITY_HIGH,
            datetime.now(),
            datetime.now() + timedelta(days=30), self.testuser1.pk,
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.project1_labbook1 = self.rest_create_labbook(
            self.token1, self.project1.pk, "Standalone Test Labbok", False,
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.project1_contact1 = self.rest_create_contact(
            self.token1, self.project1.pk, 'MSC', 'Jane', 'Mnuchin',
            '*****@*****.**', HTTP_USER_AGENT, REMOTE_ADDR)

        self.project1_file1 = self.rest_create_file(
            self.token1, self.project1.pk, 'MyFile', 'This is a file!',
            'MyFileName', 1024, HTTP_USER_AGENT, REMOTE_ADDR)

        self.project1_note1 = self.rest_create_note(
            self.token1, self.project1.pk, 'This is a project note',
            'Still a project note', HTTP_USER_AGENT, REMOTE_ADDR)

        self.project1_meeting1 = self.rest_create_meeting(
            self.token1, self.project1.pk,
            'Project Meeting', 'Meet all the project members!', timezone.now(),
            timezone.now(), HTTP_USER_AGENT, REMOTE_ADDR)

        self.project1_kanban1 = self.rest_create_kanbanboard(
            self.token1, self.project1.pk, 'Project Kanban Board',
            KanbanBoard.KANBAN_BOARD_TYPE_PERSONAL, HTTP_USER_AGENT,
            REMOTE_ADDR)

        self.project1_picture1 = self.rest_create_picture(
            self.token1, self.project1.pk, 'Project Picture', 'demo1.png',
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.project1_dmp1 = self.rest_create_dmp(
            self.token1, self.project1.pk, 'Test Project DMP Title',
            self.dmp_status, self.dmp_form.pk, HTTP_USER_AGENT, REMOTE_ADDR)

        self.project1_drive1 = self.rest_create_drive(self.token1, None,
                                                      "Project drive a - b",
                                                      HTTP_USER_AGENT,
                                                      REMOTE_ADDR)

        # ## the same objects are created for testuser2 to see if the deletion is user-independent
        # ## (testuser1 is used in the deletion test for all objects)

        # create some elements outside of a project:
        self.standalone_task2 = self.rest_create_task(
            self.token2, None, "Standalone Test Task", "Test Description",
            Task.TASK_STATE_NEW, Task.TASK_PRIORITY_HIGH, datetime.now(),
            datetime.now() + timedelta(days=30), self.testuser1.pk,
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.http_info_sa_task2 = HttpInfo(auth_token=self.token2,
                                           user_agent=HTTP_USER_AGENT,
                                           remote_address=REMOTE_ADDR)
        self.sa_task2_pk = self.standalone_task2.data['pk']
        self.sa_task2_versiondata = VersionData(
            object_id=self.sa_task2_pk,
            summary="My standalone version 2").as_dict()
        self.standalone_task2_version = self.rest_post_version(
            'tasks', self.sa_task2_pk, self.sa_task2_versiondata,
            self.http_info_sa_task2)

        self.standalone_labbook2 = self.rest_create_labbook(
            self.token2, None, "Standalone Test Labbok", False,
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.standalone_contact2 = self.rest_create_contact(
            self.token2, None, 'Dr.', 'John', 'Doe', '*****@*****.**',
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.standalone_file2 = self.rest_create_file(
            self.token2, None, 'MyStandaloneFile',
            'This is a standalone file!', 'MyStandaloneFileName', 1024,
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.standalone_note2 = self.rest_create_note(
            self.token2, None, 'This is a standalone note',
            'Still a standalone note', HTTP_USER_AGENT, REMOTE_ADDR)

        self.standalone_meeting2 = self.rest_create_meeting(
            self.token2, None, 'Standalone Appointment', 'Meet me alone!',
            timezone.now(), timezone.now(), HTTP_USER_AGENT, REMOTE_ADDR)

        self.standalone_kanban2 = self.rest_create_kanbanboard(
            self.token2, None, 'Standalone Kanban Board',
            KanbanBoard.KANBAN_BOARD_TYPE_PERSONAL, HTTP_USER_AGENT,
            REMOTE_ADDR)

        self.standalone_picture2 = self.rest_create_picture(
            self.token2, None, 'Standalone Picture', 'demo1.png',
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.standalone_dmp2 = self.rest_create_dmp(
            self.token2, None, 'Test DMP Title', self.dmp_status,
            self.dmp_form.pk, HTTP_USER_AGENT, REMOTE_ADDR)

        self.standalone_drive2 = self.rest_create_drive(
            self.token2, None, "Standalone drive a - b", HTTP_USER_AGENT,
            REMOTE_ADDR)

        # create a project with elements assigned to it
        self.project2 = self.create_project(
            self.token2, "My Own Project (testuser2)",
            "Only testuser2 has access to this project", Project.STARTED,
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.project2_task1 = self.rest_create_task(
            self.token2, self.project2.pk, 'Project Test Task',
            'Test Description', Task.TASK_STATE_NEW, Task.TASK_PRIORITY_HIGH,
            datetime.now(),
            datetime.now() + timedelta(days=30), self.testuser1.pk,
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.http_info_project2_task1 = HttpInfo(auth_token=self.token2,
                                                 user_agent=HTTP_USER_AGENT,
                                                 remote_address=REMOTE_ADDR)
        self.project2_task1_pk = self.project2_task1.data['pk']
        self.project2_task1_versiondata = VersionData(
            object_id=self.project2_task1_pk, summary="My version").as_dict()
        self.project2_task1_version = self.rest_post_version(
            'tasks', self.project2_task1_pk, self.project2_task1_versiondata,
            self.http_info_project2_task1)

        self.project2_task2 = self.rest_create_task(
            self.token2, self.project2.pk, 'Project Test Task 2',
            'Test Description 2', Task.TASK_STATE_NEW, Task.TASK_PRIORITY_HIGH,
            datetime.now(),
            datetime.now() + timedelta(days=30), self.testuser1.pk,
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.project2_labbook1 = self.rest_create_labbook(
            self.token2, self.project2.pk, "Standalone Test Labbok", False,
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.project2_contact1 = self.rest_create_contact(
            self.token2, self.project2.pk, 'MSC', 'Jane', 'Mnuchin',
            '*****@*****.**', HTTP_USER_AGENT, REMOTE_ADDR)

        self.project2_file1 = self.rest_create_file(
            self.token2, self.project2.pk, 'MyFile', 'This is a file!',
            'MyFileName', 1024, HTTP_USER_AGENT, REMOTE_ADDR)

        self.project2_note1 = self.rest_create_note(
            self.token2, self.project2.pk, 'This is a project note',
            'Still a project note', HTTP_USER_AGENT, REMOTE_ADDR)

        self.project2_meeting1 = self.rest_create_meeting(
            self.token2, self.project2.pk,
            'Project Appointment', 'Meet all the project members!',
            timezone.now(), timezone.now(), HTTP_USER_AGENT, REMOTE_ADDR)

        self.project2_kanban1 = self.rest_create_kanbanboard(
            self.token2, self.project2.pk, 'Project Kanban Board',
            KanbanBoard.KANBAN_BOARD_TYPE_PERSONAL, HTTP_USER_AGENT,
            REMOTE_ADDR)

        self.project2_picture1 = self.rest_create_picture(
            self.token2, self.project2.pk, 'Project Picture', 'demo1.png',
            HTTP_USER_AGENT, REMOTE_ADDR)

        self.project2_dmp1 = self.rest_create_dmp(
            self.token2, self.project2.pk, 'Test Project DMP Title',
            self.dmp_status, self.dmp_form.pk, HTTP_USER_AGENT, REMOTE_ADDR)

        self.project2_drive1 = self.rest_create_drive(self.token2,
                                                      self.project2.pk,
                                                      "Project drive a - b",
                                                      HTTP_USER_AGENT,
                                                      REMOTE_ADDR)

        self.fraction_field = MetadataField.objects.create(
            name='MyFraction',
            description="...",
            base_type=MetadataField.BASE_TYPE_FRACTION,
            type_settings={},
        )

        self.decimal_field = MetadataField.objects.create(
            name='MyDecimal',
            description="...",
            base_type=MetadataField.BASE_TYPE_DECIMAL_NUMBER,
            type_settings={},
        )
Ejemplo n.º 8
0
 def restore_version_as(self, test_context, version_pk, token):
     return self.rest_restore_version(test_context.endpoint,
                                      test_context.endpoint_id, version_pk,
                                      HttpInfo(token))