示例#1
0
 def setUp(self):
     self.extra_data = ExtraDataManager()
     self.extra_data.add_test_data('user name', self.user_name)
     if ShareFolderTests.auth is None:
         response = self.main_register_and_login.login_or_register(user_name=self.user_name, password=self.password,
                                                                   first_name=self.first_name,
                                                                   last_name=self.last_name)
         ShareFolderTests.auth = self.main_register_and_login.get_auth_from_login_data(response)
     self.assertIsInstance(ShareFolderTests.auth, str,
                           'Invalid auth: ' + str(ShareFolderTests.auth) + self.extra_data.get_all())
示例#2
0
 def setUp(self):
     self.extra_data = ExtraDataManager()
     self.extra_data.add_test_data('user name', self.user_name)
     main_register_and_login_mixin = MainRegisterAndLoginMixin()
     if GetPartitionTests.auth is None:
         response = main_register_and_login_mixin.login_or_register(user_name=self.user_name, password=self.password,
                                                                    first_name=self.first_name,
                                                                    last_name=self.last_name)
         GetPartitionTests.auth = main_register_and_login_mixin.get_auth_from_login_data(response)
     self.assertIsInstance(GetPartitionTests.auth, str,
                           'Invalid auth: ' + str(GetPartitionTests.auth) + self.extra_data.get_all())
示例#3
0
class UserDetailsTest(TestCase):
    auth = None

    user_name = 'rest_tests_user_details_' + str(int(time())) + '@autodesk.com'
    first_name = 'Rest'
    last_name = 'Test'
    password = '******'

    extra_data = None
    user_client = UserClient()

    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        main_register_and_login_mixin = MainRegisterAndLoginMixin()
        if UserDetailsTest.auth is None:
            response = main_register_and_login_mixin.login_or_register(
                user_name=self.user_name,
                password=self.password,
                first_name=self.first_name,
                last_name=self.last_name)
            UserDetailsTest.auth = main_register_and_login_mixin.get_auth_from_login_data(
                response)
        self.assertIsInstance(
            UserDetailsTest.auth, str, 'Invalid auth: ' +
            str(UserDetailsTest.auth) + self.extra_data.get_all())

    def test_get_user_details(self):
        response = self.user_client.get_user_details(auth=self.auth)
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())

        self.assertTrue(
            len(response.history) > 1,
            'Expected at least one redirect url in response history. response history: '
            + str(response.history) + self.extra_data.get_all())

    def test_user_status(self):
        response = self.user_client.get_user_status(auth=self.auth)
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data('get_user_status response',
                                      ClientUtils.get_response_body(response))

        status = ClientUtils.get_value_from_body(response, 'status')
        self.assertEqual(
            1, status, 'Expected status: 1 but got: ' + str(status) +
            self.extra_data.get_all())
示例#4
0
    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        main_register_and_login_mixin = MainRegisterAndLoginMixin()
        if BoxExternalFileSystemTests.auth is None:
            response = main_register_and_login_mixin.login_or_register(
                user_name=self.user_name,
                password=self.password,
                first_name=self.first_name,
                last_name=self.last_name)
            BoxExternalFileSystemTests.auth = main_register_and_login_mixin.get_auth_from_login_data(
                response)
        self.assertIsInstance(
            BoxExternalFileSystemTests.auth, str, 'Invalid auth: ' +
            str(BoxExternalFileSystemTests.auth) + self.extra_data.get_all())

        if BoxExternalFileSystemTests.host_id is None:
            connect_to_box_response = self.external_storage_client.webdav_connect_to_external_storage(
                auth=self.auth,
                folder_name=self.folder_name,
                service_url=self.service_url,
                user_name=self.box_user_name,
                password=self.box_password)
            status_code = ClientUtils.get_response_status_code(
                connect_to_box_response)
            self.assertEqual(
                httplib.OK, status_code, 'Got status code: ' +
                str(status_code) + self.extra_data.get_all())
            self.extra_data.add_test_data(
                'webdav_connect_to_external_storage_response',
                ClientUtils.get_response_body(connect_to_box_response))

            host_id = ClientUtils.get_value_from_body(
                connect_to_box_response, ExternalStorageClient.KEY_HOST_ID)
            self.assertEquals(
                61043, host_id, 'expected host_id: 61043 but got: ' +
                str(host_id) + self.extra_data.get_all())
            BoxExternalFileSystemTests.host_id = host_id
示例#5
0
    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        register_client = RegisterClient()
        if LoginTests.eidm_user_id is None:
            response = register_client.register_v1(
                user_name=self.user_name,
                password=self.valid_password,
                first_name=self.first_name,
                last_name=self.last_name)
            status_code = ClientUtils.get_response_status_code(response)
            self.assertEqual(
                httplib.OK, status_code, 'Got status code: ' +
                str(status_code) + self.extra_data.get_all())
            self.extra_data.add_test_data(
                'register response', ClientUtils.get_response_body(response))

            LoginTests.eidm_user_id = ClientUtils.get_value_from_body(
                response, RegisterClient.KEY_EIDM_USER_ID)
            self.assertIsNotNone(
                LoginTests.eidm_user_id,
                'Expected Eidm user id not None, Register failed in setup' +
                self.extra_data.get_all())
示例#6
0
class UserShareSuggestionsTest(TestCase):
    auth = None

    user_name = 'rest_tests_user_share_suggestions_' + str(int(
        time())) + '@autodesk.com'
    first_name = 'Rest'
    last_name = 'Test'
    password = '******'

    extra_data = None
    user_client = UserClient()
    files_management_client = FilesManagementClient()
    main_register_and_login_mixin = MainRegisterAndLoginMixin()

    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        if UserShareSuggestionsTest.auth is None:
            response = self.main_register_and_login_mixin.login_or_register(
                user_name=self.user_name,
                password=self.password,
                first_name=self.first_name,
                last_name=self.last_name)
            UserShareSuggestionsTest.auth = self.main_register_and_login_mixin.get_auth_from_login_data(
                response)
        self.assertIsInstance(
            UserShareSuggestionsTest.auth, str, 'Invalid auth: ' +
            str(UserShareSuggestionsTest.auth) + self.extra_data.get_all())

    def test_get_user_share_suggestions(self):
        file_name = 'test_file_get_user_share_suggestions' + str(int(
            time())) + '.dwg'
        user_name_to_share_with = 'rest_tests_share_with_user' + str(
            int(time())) + '@autodesk.com'
        first_name_share_with = 'Rest'
        last_name_share_with = 'Test'
        password_share_with = 'Moomoo123'

        self.extra_data.add_test_data('file name', file_name)
        self.extra_data.add_test_data('user name to share with',
                                      user_name_to_share_with)

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        login_data = self.main_register_and_login_mixin.login_or_register(
            user_name=user_name_to_share_with,
            password=password_share_with,
            first_name=first_name_share_with,
            last_name=last_name_share_with)
        self.assertIsNotNone(
            login_data, 'Failed to register user_name_to_share_with' +
            self.extra_data.get_all())

        share_response = self.files_management_client.share_file_v2(
            auth=self.auth,
            file_id=created_file_id,
            emails=[user_name_to_share_with])
        status_code = ClientUtils.get_response_status_code(share_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'share_file response',
            ClientUtils.get_response_body(share_response))

        user_share_suggestions_response = self.user_client.get_user_share_suggestions(
            auth=self.auth)
        status_code = ClientUtils.get_response_status_code(
            user_share_suggestions_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'get_user_share_suggestions response',
            ClientUtils.get_response_body(user_share_suggestions_response))

        response_contact_addresses = TestUtils.get_addresses_from_share_suggestions_response(
            user_share_suggestions_response)
        self.assertTrue(
            len(response_contact_addresses) == 1,
            'Expected 1 share suggestion only but got: ' +
            str(response_contact_addresses) + self.extra_data.get_all())
示例#7
0
class GetPartitionTests(TestCase):
    auth = None

    user_name = 'rest_tests_partition_' + str(int(time())) + '@autodesk.com'
    first_name = 'Rest'
    last_name = 'Test'
    password = '******'

    extra_data = None
    partition_client = PartitionClient()

    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        main_register_and_login_mixin = MainRegisterAndLoginMixin()
        if GetPartitionTests.auth is None:
            response = main_register_and_login_mixin.login_or_register(user_name=self.user_name, password=self.password,
                                                                       first_name=self.first_name,
                                                                       last_name=self.last_name)
            GetPartitionTests.auth = main_register_and_login_mixin.get_auth_from_login_data(response)
        self.assertIsInstance(GetPartitionTests.auth, str,
                              'Invalid auth: ' + str(GetPartitionTests.auth) + self.extra_data.get_all())

    def test_get_partition_v2_root_internal(self):
        expected_entries_names = ['Clean Canvas.dwg', 'Dog House Plan Sample.dwg', 'Drive Roller Assembly Sample.dwg',
                                  'Geospatial Sample.dwg', 'Villa Project Sample.dwg']

        response = self.partition_client.get_partition_v2(auth=self.auth)
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(httplib.OK, status_code, 'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data('get_partition response', ClientUtils.get_response_body(response))

        file_system_entries = ClientUtils.get_value_from_body(response, PartitionClient.KEY_FILE_SYSTEM_ENTRIES)
        self.assertIsNotNone(file_system_entries, 'Expected non empty partition' + self.extra_data.get_all())

        file_system_entries_names = TestUtils.get_entries_names_from_file_system_entries(file_system_entries)
        self.assertItemsEqual(expected_entries_names, file_system_entries_names,
                              'Expected entries names: ' + str(expected_entries_names) + ' but got: ' + str(
                                  file_system_entries_names) + self.extra_data.get_all())

    def test_get_partition_root_internal(self):
        expected_entries_names = ['Clean Canvas.dwg', 'Dog House Plan Sample.dwg', 'Drive Roller Assembly Sample.dwg',
                                  'Geospatial Sample.dwg', 'Villa Project Sample.dwg']

        response = self.partition_client.get_partition(auth=self.auth)
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(httplib.OK, status_code, 'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data('get_partition response', ClientUtils.get_response_body(response))

        file_system_entries = ClientUtils.get_value_from_body(response, PartitionClient.KEY_FILE_SYSTEM_ENTRIES)
        self.assertIsNotNone(file_system_entries, 'Expected non empty partition' + self.extra_data.get_all())

        file_system_entries_names = TestUtils.get_entries_names_from_file_system_entries(file_system_entries)
        self.assertItemsEqual(expected_entries_names, file_system_entries_names,
                              'Expected entries names: ' + str(expected_entries_names) + ' but got: ' + str(
                                  file_system_entries_names) + self.extra_data.get_all())

    def test_get_partition_v2_path_internal(self):
        expected_entries_names = ['Clean Canvas.dwg', 'Dog House Plan Sample.dwg', 'Drive Roller Assembly Sample.dwg',
                                  'Geospatial Sample.dwg', 'Villa Project Sample.dwg']

        response = self.partition_client.get_partition_path_v2(auth=self.auth, path='')
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(httplib.OK, status_code, 'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data('response', response)

        file_system_entries = ClientUtils.get_value_from_body(response, PartitionClient.KEY_FILE_SYSTEM_ENTRIES)
        self.assertIsNotNone(file_system_entries, 'Expected non empty partition' + self.extra_data.get_all())

        file_system_entries_names = TestUtils.get_entries_names_from_file_system_entries(file_system_entries)
        self.assertItemsEqual(expected_entries_names, file_system_entries_names,
                              'Expected entries names: ' + str(expected_entries_names) + ' but got: ' + str(
                                  file_system_entries_names) + self.extra_data.get_all())

    def test_get_partition_path_internal(self):
        expected_entries_names = ['Clean Canvas.dwg', 'Dog House Plan Sample.dwg', 'Drive Roller Assembly Sample.dwg',
                                  'Geospatial Sample.dwg', 'Villa Project Sample.dwg']

        response = self.partition_client.get_partition_path(auth=self.auth, path='')
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(httplib.OK, status_code, 'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data('response', response)

        file_system_entries = ClientUtils.get_value_from_body(response, PartitionClient.KEY_FILE_SYSTEM_ENTRIES)
        self.assertIsNotNone(file_system_entries, 'Expected non empty partition' + self.extra_data.get_all())

        file_system_entries_names = TestUtils.get_entries_names_from_file_system_entries(file_system_entries)
        self.assertItemsEqual(expected_entries_names, file_system_entries_names,
                              'Expected entries names: ' + str(expected_entries_names) + ' but got: ' + str(
                                  file_system_entries_names) + self.extra_data.get_all())
示例#8
0
class TimelineTests(TestCase):
    auth = None

    user_name = 'rest_tests_timeline_' + str(int(time())) + '@autodesk.com'
    password = '******'
    first_name = 'Rest'
    last_name = 'Test'

    extra_data = None
    files_management_client = FilesManagementClient()

    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        main_register_and_login_mixin = MainRegisterAndLoginMixin()
        if TimelineTests.auth is None:
            response = main_register_and_login_mixin.login_or_register(
                user_name=self.user_name,
                password=self.password,
                first_name=self.first_name,
                last_name=self.last_name)
            TimelineTests.auth = main_register_and_login_mixin.get_auth_from_login_data(
                response)
        self.assertIsInstance(
            TimelineTests.auth, str, 'Invalid auth: ' +
            str(TimelineTests.auth) + self.extra_data.get_all())

    def test_timeline_manual(self):
        file_name = 'test_file_timeline_manual_' + str(int(time())) + '.dwg'
        title = 'test_title_' + str(int(time()))

        self.extra_data.add_test_data('file name', file_name)
        self.extra_data.add_test_data('title', title)

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        manual_timeline_response = self.files_management_client.put_timeline_manual(
            auth=self.auth, file_id=created_file_id, title=title)
        status_code = ClientUtils.get_response_status_code(
            manual_timeline_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'put_timeline_manual response',
            ClientUtils.get_response_body(manual_timeline_response))

        response_title = ClientUtils.get_value_from_body(
            manual_timeline_response, FilesManagementClient.KEY_TITLE)
        self.assertEqual(
            title, response_title, 'Expected title: ' + str(title) +
            ' but got: ' + str(response_title) + self.extra_data.get_all())

        get_timeline_response = self.files_management_client.get_timeline(
            auth=self.auth, file_id=created_file_id)
        status_code = ClientUtils.get_response_status_code(
            get_timeline_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'get_timeline response',
            ClientUtils.get_response_body(get_timeline_response))

        response_entries = ClientUtils.get_value_from_body(
            get_timeline_response, FilesManagementClient.KEY_ENTRIES)
        self.assertIsNotNone(
            response_entries,
            'Expected non empty entries' + self.extra_data.get_all())
        self.assertTrue(
            len(response_entries) == 2,
            'Expected exactly 2 entries in response body but got: ' +
            str(response_entries) + self.extra_data.get_all())
        self.extra_data.add_test_data('response entries', response_entries)

        entry = response_entries[0]
        if entry['title'] != title:
            entry = response_entries[1]

        entry_primary_id = entry['primaryVersionId']
        self.assertEqual(
            created_file_id, entry_primary_id,
            'Expected file id: ' + str(created_file_id) + ' but got: ' +
            str(entry_primary_id) + self.extra_data.get_all())
        entry_title = entry['title']
        self.assertEqual(
            title, entry_title, 'Expected title: ' + str(title) +
            ' but got: ' + str(entry_title) + self.extra_data.get_all())

        users_drawing_prefs_in_response_body = ClientUtils.is_key_in_body(
            get_timeline_response, 'usersDrawingPreferences')
        self.assertTrue(
            users_drawing_prefs_in_response_body,
            'Expected usersDrawingPreferences in response body' +
            self.extra_data.get_all())
示例#9
0
 def setUp(self):
     self.extra_data = ExtraDataManager()
     self.extra_data.add_test_data('user name', self.user_name)
示例#10
0
class FilesTests(TestCase):
    auth = None

    user_name = 'rest_tests_manage_files_' + str(int(time())) + '@autodesk.com'
    password = '******'
    first_name = 'Rest'
    last_name = 'Test'

    extra_data = None
    files_management_client = FilesManagementClient()

    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        main_register_and_login_mixin = MainRegisterAndLoginMixin()
        if FilesTests.auth is None:
            response = main_register_and_login_mixin.login_or_register(
                user_name=self.user_name,
                password=self.password,
                first_name=self.first_name,
                last_name=self.last_name)
            FilesTests.auth = main_register_and_login_mixin.get_auth_from_login_data(
                response)
        self.assertIsInstance(
            FilesTests.auth, str, 'Invalid auth: ' + str(FilesTests.auth) +
            self.extra_data.get_all())

    def test_create_file(self):
        file_name = 'test_file_create_file_' + str(int(time())) + '.dwg'
        self.extra_data.add_test_data('file name', file_name)

        create_file_response = self.files_management_client.create_file(
            auth=self.auth, new_drawing_name=file_name)
        status_code = ClientUtils.get_response_status_code(
            create_file_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'create_file response',
            ClientUtils.get_response_body(create_file_response))

        response_file_id, response_file_name = ClientUtils.get_multiple_values_from_body(
            create_file_response, [
                FilesManagementClient.KEY_VERSION_ID,
                FilesManagementClient.KEY_NAME
            ])
        self.assertTrue(
            response_file_id > 0, 'Expected valid file id but got: ' +
            str(response_file_id) + self.extra_data.get_all())
        self.assertEqual(
            file_name, response_file_name,
            'Expected file name: ' + str(file_name) + 'but got: ' +
            str(response_file_name) + self.extra_data.get_all())

        self.extra_data.add_test_data('response file id', response_file_id)
        self.extra_data.add_test_data('response file name', response_file_name)

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        entry = TestUtils.get_entry_from_internal_file_system_entries(
            response_file_id, file_system_entries)
        self.assertIsNotNone(
            entry, 'Created file should exist in partition' +
            self.extra_data.get_all())

        partition_file_name = TestUtils.get_entry_data_by_keys(
            entry=entry, keys=PartitionClient.KEY_ENTRY_NAME)
        self.assertEqual(
            file_name, partition_file_name,
            'Expected file name: ' + str(file_name) + 'but got: ' +
            str(partition_file_name) + self.extra_data.get_all())

        partition_nitrous_id = TestUtils.get_entry_data_by_keys(
            entry=entry, keys=PartitionClient.KEY_NITROUS_ID)
        self.assertIsNotNone(
            partition_nitrous_id,
            'Expected nitrous ID not None' + self.extra_data.get_all())

    def test_create_file_v2(self):
        file_name = 'test_file_create_file_v2_' + str(int(time())) + '.dwg'
        self.extra_data.add_test_data('file name', file_name)

        create_file_response = self.files_management_client.create_file_v2(
            auth=self.auth, new_drawing_name=file_name)
        status_code = ClientUtils.get_response_status_code(
            create_file_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'create_file response',
            ClientUtils.get_response_body(create_file_response))

        response_file_id, response_file_name = ClientUtils.get_multiple_values_from_body(
            create_file_response, [
                FilesManagementClient.KEY_VERSION_ID,
                FilesManagementClient.KEY_NAME
            ])
        self.assertTrue(
            response_file_id > 0, 'Expected valid file id but got: ' +
            str(response_file_id) + self.extra_data.get_all())
        self.assertEqual(
            file_name, response_file_name,
            'Expected file name: ' + str(file_name) + 'but got: ' +
            str(response_file_name) + self.extra_data.get_all())

        self.extra_data.add_test_data('response file id', response_file_id)
        self.extra_data.add_test_data('response file name', response_file_name)

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        entry = TestUtils.get_entry_from_internal_file_system_entries(
            response_file_id, file_system_entries)
        self.assertIsNotNone(
            entry, 'Created file should exist in partition' +
            self.extra_data.get_all())

        partition_file_name = TestUtils.get_entry_data_by_keys(
            entry=entry, keys=PartitionClient.KEY_ENTRY_NAME)
        self.assertEqual(
            file_name, partition_file_name,
            'Expected file name: ' + str(file_name) + 'but got: ' +
            str(partition_file_name) + self.extra_data.get_all())

        partition_nitrous_id = TestUtils.get_entry_data_by_keys(
            entry=entry, keys=PartitionClient.KEY_NITROUS_ID)
        self.assertIsNotNone(
            partition_nitrous_id,
            'Expected nitrous ID not None' + self.extra_data.get_all())

    def test_rename_file_internal(self):
        file_name = 'test_file_rename_file_internal_' + str(int(
            time())) + '.dwg'
        file_new_name = 'test_file_rename_file_internal_renamed_' + str(
            int(time())) + '.dwg'
        expected_code_and_description = (0, 'SUCCESS')

        self.extra_data.add_test_data('file name', file_name)
        self.extra_data.add_test_data('file new name', file_new_name)

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        rename_file_response = self.files_management_client.rename_file_internal(
            auth=self.auth, file_id=created_file_id, name=file_new_name)
        status_code = ClientUtils.get_response_status_code(
            rename_file_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'rename_file_internal response',
            ClientUtils.get_response_body(rename_file_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            rename_file_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        entry = TestUtils.get_entry_from_internal_file_system_entries(
            created_file_id, file_system_entries)

        self.assertIsNotNone(
            entry, 'Renamed file should exist in partition' +
            self.extra_data.get_all())
        partition_file_name = TestUtils.get_entry_data_by_keys(
            entry=entry, keys=PartitionClient.KEY_ENTRY_NAME)
        self.assertEqual(
            file_new_name, partition_file_name,
            'Expected file name: ' + str(file_new_name) + ' but got: ' +
            str(partition_file_name) + self.extra_data.get_all())

    def test_rename_file_v2_internal(self):
        file_name = 'test_file_rename_file_v2_internal_' + str(int(
            time())) + '.dwg'
        file_new_name = 'test_file_rename_file_v2_internal_renamed_' + str(
            int(time())) + '.dwg'
        expected_code_and_description = (0, 'SUCCESS')

        self.extra_data.add_test_data('file name', file_name)
        self.extra_data.add_test_data('file new name', file_new_name)

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        rename_file_response = self.files_management_client.rename_file_v2_internal(
            auth=self.auth, file_id=created_file_id, name=file_new_name)
        status_code = ClientUtils.get_response_status_code(
            rename_file_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'rename_file_internal response',
            ClientUtils.get_response_body(rename_file_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            rename_file_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        entry = TestUtils.get_entry_from_internal_file_system_entries(
            created_file_id, file_system_entries)

        self.assertIsNotNone(
            entry, 'Renamed file should exist in partition' +
            self.extra_data.get_all())
        partition_file_name = TestUtils.get_entry_data_by_keys(
            entry=entry, keys=PartitionClient.KEY_ENTRY_NAME)
        self.assertEqual(
            file_new_name, partition_file_name,
            'Expected file name: ' + str(file_new_name) + ' but got: ' +
            str(partition_file_name) + self.extra_data.get_all())

    def test_copy_file_internal(self):
        file_name = 'test_file_copy_file_internal_' + str(int(time())) + '.dwg'
        file_new_name = 'test_file_copy_file_internal_copy' + str(int(
            time())) + '.dwg'
        expected_code_and_description = (0, 'SUCCESS')

        self.extra_data.add_test_data('file name', file_name)
        self.extra_data.add_test_data('file new name', file_new_name)

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        copy_file_response = self.files_management_client.copy_file_internal(
            auth=self.auth,
            file_id=created_file_id,
            to_folder_id=0,
            rename_to=file_new_name)
        status_code = ClientUtils.get_response_status_code(copy_file_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'copy_file_internal response',
            ClientUtils.get_response_body(copy_file_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            copy_file_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        copied_file_id = ClientUtils.get_value_from_body(
            copy_file_response, FilesManagementClient.KEY_PRIMARY_WS_ID)
        self.assertTrue(
            copied_file_id > 0, 'Expected valid copied file id but got: ' +
            str(copied_file_id) + self.extra_data.get_all())
        self.extra_data.add_test_data('copied file id', copied_file_id)

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        entry_src = TestUtils.get_entry_from_internal_file_system_entries(
            entry_id=created_file_id,
            internal_file_system_entries=file_system_entries)
        entry_copy = TestUtils.get_entry_from_internal_file_system_entries(
            entry_id=copied_file_id,
            internal_file_system_entries=file_system_entries)
        self.assertIsNotNone(
            entry_src, 'Source file should still exist in partition' +
            self.extra_data.get_all())
        self.assertIsNotNone(
            entry_copy, 'Copied file should exist in partition' +
            self.extra_data.get_all())

        entry_src_name = TestUtils.get_entry_data_by_keys(
            entry=entry_src, keys=PartitionClient.KEY_ENTRY_NAME)
        entry_copy_name = TestUtils.get_entry_data_by_keys(
            entry=entry_copy, keys=PartitionClient.KEY_ENTRY_NAME)
        self.assertEqual(
            file_name, entry_src_name,
            'Expected source file name: ' + str(file_name) + ' but got: ' +
            str(entry_src_name) + self.extra_data.get_all())
        self.assertEqual(
            file_new_name, entry_copy_name,
            'Expected copy file name: ' + str(file_new_name) + ' but got: ' +
            str(entry_copy_name) + self.extra_data.get_all())

    def test_copy_file_v2_internal(self):
        file_name = 'test_file_copy_file_v2_internal_' + str(int(
            time())) + '.dwg'
        file_new_name = 'test_file_copy_file_v2_internal_copy' + str(
            int(time())) + '.dwg'
        expected_code_and_description = (0, 'SUCCESS')

        self.extra_data.add_test_data('file name', file_name)
        self.extra_data.add_test_data('file new name', file_new_name)

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        copy_file_response = self.files_management_client.copy_file_v2_internal(
            auth=self.auth,
            file_id=created_file_id,
            to_folder_id=0,
            rename_to=file_new_name)
        status_code = ClientUtils.get_response_status_code(copy_file_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'copy_file_internal response',
            ClientUtils.get_response_body(copy_file_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            copy_file_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        copied_file_id = ClientUtils.get_value_from_body(
            copy_file_response, FilesManagementClient.KEY_PRIMARY_WS_ID)
        self.assertTrue(
            copied_file_id > 0, 'Expected valid copied file id but got: ' +
            str(copied_file_id) + self.extra_data.get_all())
        self.extra_data.add_test_data('copied file id', copied_file_id)

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        entry_src = TestUtils.get_entry_from_internal_file_system_entries(
            entry_id=created_file_id,
            internal_file_system_entries=file_system_entries)
        entry_copy = TestUtils.get_entry_from_internal_file_system_entries(
            entry_id=copied_file_id,
            internal_file_system_entries=file_system_entries)
        self.assertIsNotNone(
            entry_src, 'Source file should still exist in partition' +
            self.extra_data.get_all())
        self.assertIsNotNone(
            entry_copy, 'Copied file should exist in partition' +
            self.extra_data.get_all())

        entry_src_name = TestUtils.get_entry_data_by_keys(
            entry=entry_src, keys=PartitionClient.KEY_ENTRY_NAME)
        entry_copy_name = TestUtils.get_entry_data_by_keys(
            entry=entry_copy, keys=PartitionClient.KEY_ENTRY_NAME)
        self.assertEqual(
            file_name, entry_src_name,
            'Expected source file name: ' + str(file_name) + ' but got: ' +
            str(entry_src_name) + self.extra_data.get_all())
        self.assertEqual(
            file_new_name, entry_copy_name,
            'Expected copy file name: ' + str(file_new_name) + ' but got: ' +
            str(entry_copy_name) + self.extra_data.get_all())

    def test_move_file_internal(self):
        expected_code_and_description = (0, 'SUCCESS')
        file_name = 'test_file_move_file_internal_' + str(int(time())) + '.dwg'
        folder_name = 'test_folder_move_file_internal_' + str(int(time()))

        self.extra_data.add_test_data('file name', file_name)
        self.extra_data.add_test_data('folder name', folder_name)

        created_folder_id, msg = TestUtils.create_folder(
            auth=self.auth,
            folder_name=folder_name,
            extra_data=self.extra_data)
        self.assertIsNotNone(created_folder_id,
                             msg + self.extra_data.get_all())

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        move_file_response = self.files_management_client.move_file_internal(
            auth=self.auth,
            file_id=created_file_id,
            to_folder_id=created_folder_id)
        status_code = ClientUtils.get_response_status_code(move_file_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'move_file_internal response',
            ClientUtils.get_response_body(move_file_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            move_file_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth,
            partition_folder_id=created_folder_id,
            extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        entry = TestUtils.get_entry_from_internal_file_system_entries(
            created_file_id, file_system_entries)

        self.assertIsNotNone(
            entry, 'File should have moved to the new folder' +
            self.extra_data.get_all())
        partition_file_name = TestUtils.get_entry_data_by_keys(
            entry=entry, keys=PartitionClient.KEY_ENTRY_NAME)
        self.assertEqual(
            file_name, partition_file_name,
            'Expected file name: ' + str(file_name) + ' but got: ' +
            str(partition_file_name) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        entry = TestUtils.get_entry_from_internal_file_system_entries(
            created_file_id, file_system_entries)

        self.assertIsNone(
            entry, 'File should no longer appear in root folder' +
            self.extra_data.get_all())

    def test_delete_file_internal(self):
        file_name = 'test_file_delete_file_internal_' + str(int(
            time())) + '.dwg'
        expected_code_and_description = (0, 'SUCCESS')

        self.extra_data.add_test_data('file name', file_name)

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        delete_file_response = self.files_management_client.delete_file_internal(
            auth=self.auth, file_id=created_file_id)
        status_code = ClientUtils.get_response_status_code(
            delete_file_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'delete_file_internal response',
            ClientUtils.get_response_body(delete_file_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            delete_file_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        entry = TestUtils.get_entry_from_internal_file_system_entries(
            created_file_id, file_system_entries)

        self.assertIsNone(
            entry, 'Deleted file should not be in partition' +
            self.extra_data.get_all())

    def test_recent_files(self):
        response = self.files_management_client.recent_files(self.auth)
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data('response',
                                      ClientUtils.get_response_body(response))

        self.assertTrue(
            ClientUtils.is_key_in_body(response, 'limit'),
            'Expected key limit in response body' + self.extra_data.get_all())
        self.assertTrue(
            ClientUtils.is_key_in_body(response, 'lastFileDate'),
            'Expected key lastFileDate in response body' +
            self.extra_data.get_all())
        self.assertTrue(
            ClientUtils.is_key_in_body(response, 'page'),
            'Expected key page in response body' + self.extra_data.get_all())

        drawings = ClientUtils.get_value_from_body(
            response, FilesManagementClient.KEY_DRAWINGS)
        self.assertTrue(
            len(drawings) > 0,
            'Expected at least one drawing in response body' +
            self.extra_data.get_all())
示例#11
0
class UserPreferencesTests(TestCase):
    auth = None

    user_name = 'rest_tests_user_preferences_' + str(int(
        time())) + '@autodesk.com'
    first_name = 'Rest'
    last_name = 'Test'
    password = '******'

    extra_data = None
    user_preferences_client = UserClient()

    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        main_register_and_login_mixin = MainRegisterAndLoginMixin()
        if UserPreferencesTests.auth is None:
            response = main_register_and_login_mixin.login_or_register(
                user_name=self.user_name,
                password=self.password,
                first_name=self.first_name,
                last_name=self.last_name)
            UserPreferencesTests.auth = main_register_and_login_mixin.get_auth_from_login_data(
                response)
        self.assertIsInstance(
            UserPreferencesTests.auth, str, 'Invalid auth: ' +
            str(UserPreferencesTests.auth) + self.extra_data.get_all())

    def test_get_user_preferences(self):
        response = self.user_preferences_client.get_user_preferences(
            auth=self.auth)

        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data('get_user_preferences response',
                                      ClientUtils.get_response_body(response))

        version = ClientUtils.get_value_from_body(response,
                                                  UserClient.KEY_VERSION)
        self.assertIsInstance(
            version, int, 'Expected an integer version but got: ' +
            str(version) + self.extra_data.get_all())

    def test_post_user_preferences(self):
        expected_country = 'UK'

        response = self.user_preferences_client.post_user_preferences(
            auth=self.auth, country=expected_country)
        self.assertIsNotNone(
            response, 'Response is None. user_name: ' + str(self.user_name))
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.assertTrue(
            ClientUtils.is_response_body_empty(response),
            'Expected empty body in response but got ' +
            str(ClientUtils.get_response_body(response)) +
            self.extra_data.get_all())

        get_user_preferences_response = self.user_preferences_client.get_user_preferences(
            auth=self.auth)
        status_code = ClientUtils.get_response_status_code(
            get_user_preferences_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'get_user_preferences_response',
            ClientUtils.get_response_body(get_user_preferences_response))

        country = ClientUtils.get_value_from_body(
            get_user_preferences_response, UserClient.KEY_COUNTRY)
        self.assertEqual(
            expected_country, country,
            'Expected changed country: ' + str(expected_country) +
            ' but got: ' + str(country) + self.extra_data.get_all())
示例#12
0
class BoxExternalFileSystemTests(TestCase):
    auth = None
    host_id = None

    user_name = 'rest_tests_box_filesystem_' + str(int(
        time())) + '@autodesk.com'
    password = '******'
    first_name = 'Rest'
    last_name = 'Test'

    service_url = 'https://dav.box.com/dav'
    folder_name = 'box_folder'
    box_user_name = settings.BOX_USER_NAME
    box_password = settings.BOX_PASSWORD

    extra_data = None
    partition_client = PartitionClient()
    external_storage_client = ExternalStorageClient()
    files_management_client = FilesManagementClient()
    folders_management_client = FoldersManagementClient()

    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        main_register_and_login_mixin = MainRegisterAndLoginMixin()
        if BoxExternalFileSystemTests.auth is None:
            response = main_register_and_login_mixin.login_or_register(
                user_name=self.user_name,
                password=self.password,
                first_name=self.first_name,
                last_name=self.last_name)
            BoxExternalFileSystemTests.auth = main_register_and_login_mixin.get_auth_from_login_data(
                response)
        self.assertIsInstance(
            BoxExternalFileSystemTests.auth, str, 'Invalid auth: ' +
            str(BoxExternalFileSystemTests.auth) + self.extra_data.get_all())

        if BoxExternalFileSystemTests.host_id is None:
            connect_to_box_response = self.external_storage_client.webdav_connect_to_external_storage(
                auth=self.auth,
                folder_name=self.folder_name,
                service_url=self.service_url,
                user_name=self.box_user_name,
                password=self.box_password)
            status_code = ClientUtils.get_response_status_code(
                connect_to_box_response)
            self.assertEqual(
                httplib.OK, status_code, 'Got status code: ' +
                str(status_code) + self.extra_data.get_all())
            self.extra_data.add_test_data(
                'webdav_connect_to_external_storage_response',
                ClientUtils.get_response_body(connect_to_box_response))

            host_id = ClientUtils.get_value_from_body(
                connect_to_box_response, ExternalStorageClient.KEY_HOST_ID)
            self.assertEquals(
                61043, host_id, 'expected host_id: 61043 but got: ' +
                str(host_id) + self.extra_data.get_all())
            BoxExternalFileSystemTests.host_id = host_id

    def test_connect_to_box(self):
        active_hosts_response = self.external_storage_client.webdav_active_hosts(
            auth=self.auth)
        status_code = ClientUtils.get_response_status_code(
            active_hosts_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'webdav_active_hosts response',
            ClientUtils.get_response_body(active_hosts_response))

        active_hosts = ClientUtils.get_response_body(active_hosts_response)
        self.assertIsNotNone(
            active_hosts, 'active_hosts is None' + self.extra_data.get_all())

        found_host_in_active_hosts = False
        for host in active_hosts:
            if host['hostId'] == self.host_id:
                found_host_in_active_hosts = True
                break
        self.assertTrue(
            found_host_in_active_hosts,
            'Expected to find hostId 61043 in active hosts' +
            self.extra_data.get_all())

    def test_get_partition_external_v2(self):
        expected_entries_names = [
            'xref with block - Standard.zip', 'LiveView_Clean.dwg',
            'Permanent_Folder'
        ]

        response = self.partition_client.get_external_partition_v2(
            auth=self.auth, host_id=self.host_id)
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data('external_partition response',
                                      ClientUtils.get_response_body(response))

        file_system_entries = ClientUtils.get_value_from_body(
            response, PartitionClient.KEY_FILE_SYSTEM_ENTRIES)
        self.assertIsNotNone(
            file_system_entries,
            'Expected non empty partition' + self.extra_data.get_all())

        file_system_entries_names = TestUtils.get_entries_names_from_file_system_entries(
            file_system_entries)
        self.assertItemsEqual(
            expected_entries_names, file_system_entries_names,
            'Expected entries names: ' + str(expected_entries_names) +
            ' but got: ' + str(file_system_entries_names) +
            self.extra_data.get_all())

    def test_get_partition_external(self):
        expected_entries_names = [
            'xref with block - Standard.zip', 'LiveView_Clean.dwg',
            'Permanent_Folder'
        ]

        response = self.partition_client.get_external_partition(
            auth=self.auth, host_id=self.host_id)
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data('external_partition response',
                                      ClientUtils.get_response_body(response))

        file_system_entries = ClientUtils.get_value_from_body(
            response, PartitionClient.KEY_FILE_SYSTEM_ENTRIES)
        self.assertIsNotNone(
            file_system_entries,
            'Expected non empty partition' + self.extra_data.get_all())

        file_system_entries_names = TestUtils.get_entries_names_from_file_system_entries(
            file_system_entries)
        self.assertItemsEqual(
            expected_entries_names, file_system_entries_names,
            'Expected entries names: ' + str(expected_entries_names) +
            ' but got: ' + str(file_system_entries_names) +
            self.extra_data.get_all())

    def test_create_rename_and_delete_external_folder_v2(self):
        folder_name = 'test_folder_external_folder_flow_' + str(int(time()))
        folder_new_name = 'test_folder_external_folder_flow_renamed_' + str(
            int(time()))
        permanent_folder = 'Permanent_Folder/'
        expected_code_and_description = (0, 'SUCCESS')

        self.extra_data.add_test_data('folder name', folder_name)
        self.extra_data.add_test_data('folder new name', folder_new_name)

        create_folder_response = self.folders_management_client.create_external_folder_v2(
            auth=self.auth,
            host_id=self.host_id,
            new_folder_name=folder_name,
            folder_path=permanent_folder)

        status_code = ClientUtils.get_response_status_code(
            create_folder_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'create_external_folder response',
            ClientUtils.get_response_body(create_folder_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            create_folder_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_external_partition(
            auth=self.auth,
            host_id=self.host_id,
            path=permanent_folder,
            extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        file_system_entries_names = [
            str(entry[self.partition_client.KEY_ENTRY_NAME])
            for entry in file_system_entries
            if entry['type'] == 'EXTERNAL_FOLDER'
        ]

        if folder_name not in file_system_entries_names:
            self.fail('Folder should have been created in external host' +
                      self.extra_data.get_all())

        new_folder_relative_path = permanent_folder + folder_name
        self.extra_data.add_test_data('new folder relative path',
                                      new_folder_relative_path)

        rename_folder_response = self.folders_management_client.rename_external_folder_v2(
            auth=self.auth,
            host_id=self.host_id,
            path=new_folder_relative_path,
            name=folder_new_name)
        status_code = ClientUtils.get_response_status_code(
            rename_folder_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'rename_external_folder response',
            ClientUtils.get_response_body(rename_folder_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            rename_folder_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_external_partition(
            auth=self.auth,
            host_id=self.host_id,
            path=permanent_folder,
            extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        file_system_entries_names = [
            str(entry[self.partition_client.KEY_ENTRY_NAME])
            for entry in file_system_entries
            if entry['type'] == 'EXTERNAL_FOLDER'
        ]

        if folder_new_name not in file_system_entries_names:
            self.fail('Folder should have been renamed in external host' +
                      self.extra_data.get_all())

        renamed_folder_relative_path = permanent_folder + folder_new_name
        self.extra_data.add_test_data('renamed folder relative path',
                                      renamed_folder_relative_path)
        delete_folder_response = self.folders_management_client.delete_external_folder_v2(
            auth=self.auth,
            host_id=self.host_id,
            path=renamed_folder_relative_path)
        status_code = ClientUtils.get_response_status_code(
            delete_folder_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'delete_external_folder response',
            ClientUtils.get_response_body(delete_folder_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            delete_folder_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_external_partition(
            auth=self.auth,
            host_id=self.host_id,
            path=permanent_folder,
            extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        file_system_entries_names = [
            str(entry[self.partition_client.KEY_ENTRY_NAME])
            for entry in file_system_entries
            if entry['type'] == 'EXTERNAL_FOLDER'
        ]

        if folder_new_name in file_system_entries_names:
            self.fail(
                'Folder should have been deleted, and not found in partition result'
                + self.extra_data.get_all())

    def test_get_external_file_info_v2(self):
        file_name_in_box_folder = 'LiveView_Clean.dwg'

        external_file_info_response = self.files_management_client.get_external_file_info_v2(
            auth=self.auth, host_id=self.host_id, path=file_name_in_box_folder)
        status_code = ClientUtils.get_response_status_code(
            external_file_info_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'get_external_file_info response',
            ClientUtils.get_response_body(external_file_info_response))

        file_primary_version = ClientUtils.get_value_from_body(
            external_file_info_response,
            FilesManagementClient.KEY_PRIMARY_VERSION_ID)
        file_type = ClientUtils.get_value_from_body(
            external_file_info_response, FilesManagementClient.KEY_TYPE)
        file_size = ClientUtils.get_value_from_body(
            external_file_info_response, FilesManagementClient.KEY_SIZE)
        self.assertTrue(
            file_primary_version > 0,
            'Expected valid primary version id but got: ' +
            str(file_primary_version) + self.extra_data.get_all())
        self.assertEquals(
            'EXTERNAL_DRAWING', file_type,
            'Expected file type: EXTERNAL_DRAWING but got: ' + str(file_type) +
            self.extra_data.get_all())
        self.assertEquals(
            62, file_size, 'Expected file size: 62 but got: ' +
            str(file_size) + self.extra_data.get_all())

    def test_get_external_file_info(self):
        file_name_in_box_folder = 'LiveView_Clean.dwg'

        external_file_info_response = self.files_management_client.get_external_file_info(
            auth=self.auth, host_id=self.host_id, path=file_name_in_box_folder)
        status_code = ClientUtils.get_response_status_code(
            external_file_info_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'get_external_file_info response',
            ClientUtils.get_response_body(external_file_info_response))

        file_primary_version = ClientUtils.get_value_from_body(
            external_file_info_response,
            FilesManagementClient.KEY_PRIMARY_VERSION_ID)
        file_type = ClientUtils.get_value_from_body(
            external_file_info_response, FilesManagementClient.KEY_TYPE)
        file_size = ClientUtils.get_value_from_body(
            external_file_info_response, FilesManagementClient.KEY_SIZE)
        self.assertTrue(
            file_primary_version > 0,
            'Expected valid primary version id but got: ' +
            str(file_primary_version) + self.extra_data.get_all())
        self.assertEquals(
            'EXTERNAL_DRAWING', file_type,
            'Expected file type: EXTERNAL_DRAWING but got: ' + str(file_type) +
            self.extra_data.get_all())
        self.assertEquals(
            62, file_size, 'Expected file size: 62 but got: ' +
            str(file_size) + self.extra_data.get_all())

    def test_get_external_file_provider(self):
        file_name_in_box_folder = 'LiveView_Clean.dwg'

        external_file_info_response = self.files_management_client.get_external_file_provider_v2(
            auth=self.auth, host_id=self.host_id, path=file_name_in_box_folder)
        status_code = ClientUtils.get_response_status_code(
            external_file_info_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'get_external_file_provider response',
            ClientUtils.get_response_body(external_file_info_response))

        provider = ClientUtils.get_value_from_body(
            external_file_info_response, FilesManagementClient.KEY_PROVIDER)
        self.assertEquals(
            'BOX', provider, 'Expected provider: BOX but got: ' +
            str(provider) + self.extra_data.get_all())

    def test_move_file_to_external_folder_rename_and_delete_it_v2(self):
        folder_name = 'test_folder_external_file_flow_' + str(int(time()))
        file_name = 'test_file_external_file_flow_' + str(int(time())) + '.dwg'
        file_new_name = 'test_file_external_file_flow_renamed_' + str(
            int(time())) + '.dwg'
        permanent_folder = 'Permanent_Folder/'

        self.extra_data.add_test_data('folder name', folder_name)
        self.extra_data.add_test_data('file name', file_name)
        self.extra_data.add_test_data('file new name', file_new_name)

        success_code_and_description = (0, 'SUCCESS')
        cont_async_code_and_description = (
            23, 'FILESYSTEM OPERATION CONTINUES ASYNCRONOUSLY')

        polling_timeout_in_seconds = 30
        delay_between_polls = 1

        success, msg = TestUtils.create_external_folder(
            auth=self.auth,
            host_id=self.host_id,
            folder_path=permanent_folder,
            new_folder_name=folder_name,
            extra_data=self.extra_data)
        self.assertIsNotNone(success, msg + self.extra_data.get_all())

        folder_name = permanent_folder + folder_name
        self.extra_data.add_test_data('folder name', folder_name)

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        move_to_external_folder_response = self.files_management_client.move_internal_file_to_external(
            auth=self.auth,
            file_id=created_file_id,
            to_host_id=self.host_id,
            to_path=folder_name + '/')
        status_code = ClientUtils.get_response_status_code(
            move_to_external_folder_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'move_internal_file_to_external response',
            ClientUtils.get_response_body(move_to_external_folder_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            move_to_external_folder_response)
        self.assertEqual(
            cont_async_code_and_description, code_desc,
            'Expected ' + str(cont_async_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        polling_id = ClientUtils.get_value_from_body(
            move_to_external_folder_response,
            FilesManagementClient.KEY_POLLING_ID)
        self.assertTrue(
            polling_id > 0, 'Expected valid polling id, but got: ' +
            str(polling_id) + self.extra_data.get_all())
        self.extra_data.add_test_data('polling id', polling_id)

        successful_move, msg = TestUtils.poll_for_move_to_external(
            auth=self.auth,
            polling_id=polling_id,
            sleep_period=delay_between_polls,
            timeout_in_seconds=polling_timeout_in_seconds,
            extra_data=self.extra_data)
        self.assertIsNotNone(successful_move, msg + self.extra_data.get_all())

        sleep(5)

        file_system_entries, msg = TestUtils.get_external_partition(
            auth=self.auth,
            host_id=self.host_id,
            path=folder_name,
            extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        file_system_entries_names = [
            str(entry[self.partition_client.KEY_ENTRY_NAME])
            for entry in file_system_entries
            if entry['type'] == 'EXTERNAL_DRAWING'
        ]
        if file_name not in file_system_entries_names:
            self.fail('New file should have been moved to external host' +
                      self.extra_data.get_all())

        internal_file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(internal_file_system_entries,
                             msg + self.extra_data.get_all())

        file_system_entries_names = [
            str(entry[self.partition_client.KEY_ENTRY_NAME])
            for entry in internal_file_system_entries
            if entry['type'] == 'DRAWING'
        ]
        if file_new_name in file_system_entries_names:
            self.fail(
                'File should have moved to external folder, and not found in internal partition result'
                + self.extra_data.get_all())

        file_relative_path = folder_name + '/' + file_name
        self.extra_data.add_test_data('file relative path', file_relative_path)
        rename_file_response = self.files_management_client.rename_external_file_v2(
            auth=self.auth,
            host_id=self.host_id,
            name=file_new_name,
            path=file_relative_path)
        status_code = ClientUtils.get_response_status_code(
            rename_file_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'rename_external_file response',
            ClientUtils.get_response_body(rename_file_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            rename_file_response)
        self.assertEqual(
            success_code_and_description, code_desc,
            'Expected ' + str(success_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_external_partition(
            auth=self.auth,
            host_id=self.host_id,
            path=folder_name,
            extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        file_system_entries_names = [
            str(entry[self.partition_client.KEY_ENTRY_NAME])
            for entry in file_system_entries
            if entry['type'] == 'EXTERNAL_DRAWING'
        ]

        if file_new_name not in file_system_entries_names:
            self.fail('File should have been renamed in external host' +
                      self.extra_data.get_all())

        file_relative_path = folder_name + '/' + file_new_name
        self.extra_data.add_test_data('file relative path', file_relative_path)

        delete_file_response = self.files_management_client.delete_external_file_v2(
            auth=self.auth, host_id=self.host_id, path=file_relative_path)
        status_code = ClientUtils.get_response_status_code(
            delete_file_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'delete_external_file response',
            ClientUtils.get_response_body(delete_file_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            delete_file_response)
        self.assertEqual(
            success_code_and_description, code_desc,
            'Expected ' + str(success_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_external_partition(
            auth=self.auth,
            host_id=self.host_id,
            path=folder_name,
            extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        file_system_entries_names = [
            str(entry[self.partition_client.KEY_ENTRY_NAME])
            for entry in file_system_entries
            if entry['type'] == 'EXTERNAL_DRAWING'
        ]

        if file_new_name in file_system_entries_names:
            self.fail(
                'Folder should have been deleted, and not found in partition result'
                + self.extra_data.get_all())

        # Teardown - remove created folder - does not affect test results
        self.folders_management_client.delete_external_folder_v2(
            auth=self.auth, host_id=self.host_id, path=folder_name)
示例#13
0
class LoginTests(TestCase):
    eidm_user_id = None
    user_name = 'rest_tests_login_' + str(int(time())) + '@autodesk.com'
    first_name = 'Rest'
    last_name = 'Test'
    valid_password = '******'
    wrong_password = '******'
    empty_password = None

    extra_data = None
    login_client = LoginClient()

    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        register_client = RegisterClient()
        if LoginTests.eidm_user_id is None:
            response = register_client.register_v1(
                user_name=self.user_name,
                password=self.valid_password,
                first_name=self.first_name,
                last_name=self.last_name)
            status_code = ClientUtils.get_response_status_code(response)
            self.assertEqual(
                httplib.OK, status_code, 'Got status code: ' +
                str(status_code) + self.extra_data.get_all())
            self.extra_data.add_test_data(
                'register response', ClientUtils.get_response_body(response))

            LoginTests.eidm_user_id = ClientUtils.get_value_from_body(
                response, RegisterClient.KEY_EIDM_USER_ID)
            self.assertIsNotNone(
                LoginTests.eidm_user_id,
                'Expected Eidm user id not None, Register failed in setup' +
                self.extra_data.get_all())

    def test_login_v2_valid_credentials(self):
        response = self.login_client.login_v2(user_name=self.user_name,
                                              password=self.valid_password)

        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())

        response_user_name = ClientUtils.get_value_from_body(
            response,
            LoginClient.KEY_USER_INFO + '.' + LoginClient.KEY_USERNAME)
        self.assertEqual(
            self.user_name, response_user_name, 'Expected user_name: ' +
            str(self.user_name) + ' but got: ' + str(response_user_name))

        response_eidm_user_id = ClientUtils.get_value_from_body(
            response,
            LoginClient.KEY_USER_INFO + '.' + LoginClient.KEY_EIDM_USER_ID)
        self.assertEqual(
            LoginTests.eidm_user_id, response_eidm_user_id,
            'Expected eidm user id: ' + str(self.eidm_user_id) + ' but got: ' +
            str(response_eidm_user_id) + self.extra_data.get_all())

    def test_login_v2_incorrect_credentials(self):
        response = self.login_client.login_v2(user_name=self.user_name,
                                              password=self.wrong_password)
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(
            httplib.UNAUTHORIZED, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())

    def test_login_v2_no_password(self):
        response = self.login_client.login_v2(user_name=self.user_name,
                                              password=self.empty_password)
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(
            httplib.UNAUTHORIZED, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
示例#14
0
class DrawingFeedTests(TestCase):
    auth = None

    user_name = 'rest_tests_drawing_feed_' + str(int(time())) + '@autodesk.com'
    first_name = 'Rest'
    last_name = 'Test'
    password = '******'

    extra_data = None
    drawing_feed_client = DrawingFeedClient()

    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        main_register_and_login_mixin = MainRegisterAndLoginMixin()
        if DrawingFeedTests.auth is None:
            response = main_register_and_login_mixin.login_or_register(
                user_name=self.user_name,
                password=self.password,
                first_name=self.first_name,
                last_name=self.last_name)
            DrawingFeedTests.auth = main_register_and_login_mixin.get_auth_from_login_data(
                response)
        self.assertIsInstance(
            DrawingFeedTests.auth, str, 'Invalid auth: ' +
            str(DrawingFeedTests.auth) + self.extra_data.get_all())

    def test_new_post(self):
        file_name = 'test_file_new_post_' + str(int(time())) + '.dwg'
        comment_body = 'test_comment_body'
        self.extra_data.add_test_data('file name', file_name)

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        new_post_response = self.drawing_feed_client.new_post(
            auth=self.auth, file_id=created_file_id, post_body=comment_body)

        status_code = ClientUtils.get_response_status_code(new_post_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'new_post response',
            ClientUtils.get_response_body(new_post_response))

        post_status = ClientUtils.get_value_from_body(
            new_post_response, DrawingFeedClient.KEY_STATUS)
        self.assertEqual(
            'open', post_status, 'Expected post status: open but got: ' +
            str(post_status) + self.extra_data.get_all())
        post_body = ClientUtils.get_value_from_body(new_post_response,
                                                    DrawingFeedClient.KEY_BODY)
        self.assertEqual(
            comment_body, post_body,
            'Expected post body: ' + str(comment_body) + ' but got: ' +
            str(post_body) + self.extra_data.get_all())
        post_id = ClientUtils.get_value_from_body(new_post_response,
                                                  DrawingFeedClient.KEY_ID)
        self.assertIsInstance(
            post_id, unicode, 'Expected unicode post id but got: ' +
            str(post_id) + self.extra_data.get_all())
        self.extra_data.add_test_data('post id', post_id)

        get_feed_response = self.drawing_feed_client.get_drawing_feed(
            auth=self.auth, file_id=created_file_id)
        status_code = ClientUtils.get_response_status_code(get_feed_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'get_drawing_feed response',
            ClientUtils.get_response_body(get_feed_response))

        post = TestUtils.get_post_from_drawing_feed_response(
            get_feed_response, post_id)
        self.assertIsNotNone(
            post, 'Expected non-empty post' + self.extra_data.get_all())
        self.extra_data.add_test_data('post', post)

        post_status = post['status']
        self.assertEqual(
            'open', post_status, 'Expected post status: open but got: ' +
            str(post_status) + self.extra_data.get_all())
        post_body = post['body']
        self.assertEqual(
            comment_body, post_body,
            'Expected post body: ' + str(comment_body) + 'but got: ' +
            str(post_body) + self.extra_data.get_all())
        post_actor_name = post['actor']['name']
        user_full_name = self.first_name + ' ' + self.last_name
        self.assertEqual(
            user_full_name, post_actor_name,
            'Expected post actor: ' + str(user_full_name) + 'but got: ' +
            str(post_actor_name) + self.extra_data.get_all())

    def test_update_post(self):
        file_name = 'test_file_update_post_' + str(int(time())) + '.dwg'
        comment_body = 'test_comment_body'
        updated_post_status = 'closed'
        self.extra_data.add_test_data('file name', file_name)

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        new_post_response = self.drawing_feed_client.new_post(
            auth=self.auth, file_id=created_file_id, post_body=comment_body)
        status_code = ClientUtils.get_response_status_code(new_post_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'new_post response',
            ClientUtils.get_response_body(new_post_response))

        post_id = ClientUtils.get_value_from_body(new_post_response,
                                                  DrawingFeedClient.KEY_ID)
        self.assertIsInstance(
            post_id, unicode, 'Expected unicode post id but got: ' +
            str(post_id) + self.extra_data.get_all())
        self.extra_data.add_test_data('post id', post_id)

        update_post_response = self.drawing_feed_client.update_post(
            auth=self.auth,
            file_id=created_file_id,
            post_id=post_id,
            post_status=updated_post_status)
        status_code = ClientUtils.get_response_status_code(
            update_post_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'update_post response',
            ClientUtils.get_response_body(update_post_response))

        response_post_id = ClientUtils.get_value_from_body(
            update_post_response, DrawingFeedClient.KEY_ID)
        self.assertEqual(
            post_id, response_post_id, 'Expected post_id: ' + str(post_id) +
            ' but got: ' + str(response_post_id) + self.extra_data.get_all())

        self.assertTrue(
            ClientUtils.is_key_in_body(update_post_response, 'updated'),
            'Expected key "updated" to exist in response body' +
            self.extra_data.get_all())

        get_feed_response = self.drawing_feed_client.get_drawing_feed(
            auth=self.auth, file_id=created_file_id)
        status_code = ClientUtils.get_response_status_code(get_feed_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'get_drawing_feed response',
            ClientUtils.get_response_body(get_feed_response))

        post = TestUtils.get_post_from_drawing_feed_response(
            get_feed_response, post_id)
        self.assertIsNotNone(
            post, 'Expected non empty post' + self.extra_data.get_all())
        self.extra_data.add_test_data('post', post)

        post_status = post['status']
        self.assertEqual(
            updated_post_status, post_status,
            'Expected updated post status: ' + str(updated_post_status) +
            ' but got: ' + str(post_status) + self.extra_data.get_all())

    def test_new_post_old_api(self):
        file_name = 'test_file_new_post_' + str(int(time())) + '.dwg'
        comment_body = 'test_comment_body'
        self.extra_data.add_test_data('file name', file_name)

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        new_post_response = self.drawing_feed_client.new_post_old_api(
            auth=self.auth, file_id=created_file_id, post_body=comment_body)

        status_code = ClientUtils.get_response_status_code(new_post_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'new_post response',
            ClientUtils.get_response_body(new_post_response))

        post_status = ClientUtils.get_value_from_body(
            new_post_response, DrawingFeedClient.KEY_STATUS)
        self.assertEqual(
            'open', post_status, 'Expected post status: open but got: ' +
            str(post_status) + self.extra_data.get_all())
        post_body = ClientUtils.get_value_from_body(new_post_response,
                                                    DrawingFeedClient.KEY_BODY)
        self.assertEqual(
            comment_body, post_body,
            'Expected post body: ' + str(comment_body) + ' but got: ' +
            str(post_body) + self.extra_data.get_all())
        post_id = ClientUtils.get_value_from_body(new_post_response,
                                                  DrawingFeedClient.KEY_ID)
        self.assertIsInstance(
            post_id, unicode, 'Expected unicode post id but got: ' +
            str(post_id) + self.extra_data.get_all())
        self.extra_data.add_test_data('post id', post_id)

        get_feed_response = self.drawing_feed_client.get_drawing_feed_old_api(
            auth=self.auth, file_id=created_file_id)
        status_code = ClientUtils.get_response_status_code(get_feed_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'get_drawing_feed response',
            ClientUtils.get_response_body(get_feed_response))

        post = TestUtils.get_post_from_drawing_feed_response(
            get_feed_response, post_id)
        self.assertIsNotNone(
            post, 'Expected non-empty post' + self.extra_data.get_all())
        self.extra_data.add_test_data('post', post)

        post_status = post['status']
        self.assertEqual(
            'open', post_status, 'Expected post status: open but got: ' +
            str(post_status) + self.extra_data.get_all())
        post_body = post['body']
        self.assertEqual(
            comment_body, post_body,
            'Expected post body: ' + str(comment_body) + 'but got: ' +
            str(post_body) + self.extra_data.get_all())
        post_actor_name = post['actor']['name']
        user_full_name = self.first_name + ' ' + self.last_name
        self.assertEqual(
            user_full_name, post_actor_name,
            'Expected post actor: ' + str(user_full_name) + 'but got: ' +
            str(post_actor_name) + self.extra_data.get_all())

    def test_update_post_old_api(self):
        file_name = 'test_file_update_post_' + str(int(time())) + '.dwg'
        comment_body = 'test_comment_body'
        updated_post_status = 'closed'
        self.extra_data.add_test_data('file name', file_name)

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        new_post_response = self.drawing_feed_client.new_post_old_api(
            auth=self.auth, file_id=created_file_id, post_body=comment_body)
        status_code = ClientUtils.get_response_status_code(new_post_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'new_post response',
            ClientUtils.get_response_body(new_post_response))

        post_id = ClientUtils.get_value_from_body(new_post_response,
                                                  DrawingFeedClient.KEY_ID)
        self.assertIsInstance(
            post_id, unicode, 'Expected unicode post id but got: ' +
            str(post_id) + self.extra_data.get_all())
        self.extra_data.add_test_data('post id', post_id)

        update_post_response = self.drawing_feed_client.update_post_old_api(
            auth=self.auth,
            file_id=created_file_id,
            post_id=post_id,
            post_status=updated_post_status)
        status_code = ClientUtils.get_response_status_code(
            update_post_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'update_post response',
            ClientUtils.get_response_body(update_post_response))

        response_post_id = ClientUtils.get_value_from_body(
            update_post_response, DrawingFeedClient.KEY_ID)
        self.assertEqual(
            post_id, response_post_id, 'Expected post_id: ' + str(post_id) +
            ' but got: ' + str(response_post_id) + self.extra_data.get_all())

        self.assertTrue(
            ClientUtils.is_key_in_body(update_post_response, 'updated'),
            'Expected key "updated" to exist in response body' +
            self.extra_data.get_all())

        get_feed_response = self.drawing_feed_client.get_drawing_feed_old_api(
            auth=self.auth, file_id=created_file_id)
        status_code = ClientUtils.get_response_status_code(get_feed_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'get_drawing_feed response',
            ClientUtils.get_response_body(get_feed_response))

        post = TestUtils.get_post_from_drawing_feed_response(
            get_feed_response, post_id)
        self.assertIsNotNone(
            post, 'Expected non empty post' + self.extra_data.get_all())
        self.extra_data.add_test_data('post', post)

        post_status = post['status']
        self.assertEqual(
            updated_post_status, post_status,
            'Expected updated post status: ' + str(updated_post_status) +
            ' but got: ' + str(post_status) + self.extra_data.get_all())
示例#15
0
class DrawingPreferencesTests(TestCase):
    auth = None

    user_name = 'rest_tests_drawing_preferences_' + str(int(
        time())) + '@autodesk.com'
    password = '******'
    first_name = 'Rest'
    last_name = 'Test'

    extra_data = None
    files_management_client = FilesManagementClient()

    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        main_register_and_login_mixin = MainRegisterAndLoginMixin()
        if DrawingPreferencesTests.auth is None:
            response = main_register_and_login_mixin.login_or_register(
                user_name=self.user_name,
                password=self.password,
                first_name=self.first_name,
                last_name=self.last_name)
            DrawingPreferencesTests.auth = main_register_and_login_mixin.get_auth_from_login_data(
                response)
        self.assertIsInstance(
            DrawingPreferencesTests.auth, str, 'Invalid auth: ' +
            str(DrawingPreferencesTests.auth) + self.extra_data.get_all())

    def test_get_drawing_preferences(self):
        file_name = 'test_file_get_drawing_prefs_' + str(int(time())) + '.dwg'
        self.extra_data.add_test_data('file name', file_name)

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        get_drawing_prefs_response = self.files_management_client.get_drawing_preferences(
            auth=self.auth, file_id=created_file_id)
        status_code = ClientUtils.get_response_status_code(
            get_drawing_prefs_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data('get_drawing_preferences response',
                                      get_drawing_prefs_response)

        user_specific_drawing_prefs_in_response_body = ClientUtils.is_key_in_body(
            response=get_drawing_prefs_response,
            nested_keys='userSpecificDrawingPreferences')
        self.assertTrue(
            user_specific_drawing_prefs_in_response_body,
            'Exepected key userSpecificDrawingPreferences to exist in repsonse body'
            + self.extra_data.get_all())

        shared_drawing_prefs_in_response_body = ClientUtils.is_key_in_body(
            response=get_drawing_prefs_response,
            nested_keys='sharedDrawingPreferences')
        self.assertTrue(
            shared_drawing_prefs_in_response_body,
            'Exepected key sharedDrawingPreferences to exist in repsonse body'
            + self.extra_data.get_all())

    def test_post_drawing_preferences(self):
        file_name = 'test_file_post_drawing_prefs' + str(int(time())) + '.dwg'
        expected_orth_on = True
        expected_line_weight_on = False
        self.extra_data.add_test_data('file name', file_name)

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        user_specific_drawing_prefs = {}
        user_specific_drawing_prefs.__setitem__('orthoOn', expected_orth_on)
        user_specific_drawing_prefs.__setitem__('lineWeightOn',
                                                expected_line_weight_on)
        post_drawing_prefs_response = self.files_management_client.post_drawing_preferences(
            auth=self.auth,
            file_id=created_file_id,
            user_specific_drawing_preferences=user_specific_drawing_prefs)
        self.assertIsNotNone(post_drawing_prefs_response,
                             'Response is None' + self.extra_data.get_all())
        status_code = ClientUtils.get_response_status_code(
            post_drawing_prefs_response)
        self.assertEqual(
            httplib.NO_CONTENT, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.assertTrue(
            ClientUtils.is_response_body_empty(post_drawing_prefs_response),
            'Expected empty response body but got: ' +
            str(ClientUtils.get_response_body(post_drawing_prefs_response)) +
            self.extra_data.get_all())

        get_drawing_prefs_response = self.files_management_client.get_drawing_preferences(
            auth=self.auth, file_id=created_file_id)
        status_code = ClientUtils.get_response_status_code(
            get_drawing_prefs_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'get_drawing_preferences response',
            ClientUtils.get_response_body(get_drawing_prefs_response))

        orth_on = ClientUtils.get_value_from_body(
            response=get_drawing_prefs_response,
            json_path='userSpecificDrawingPreferences.orthoOn')
        self.assertEqual(
            expected_orth_on, orth_on,
            'Expected orth_on: ' + str(expected_orth_on) + 'but got: ' +
            str(orth_on) + self.extra_data.get_all())

        line_weight_on = ClientUtils.get_value_from_body(
            response=get_drawing_prefs_response,
            json_path='userSpecificDrawingPreferences.lineWeightOn')
        self.assertEqual(
            expected_line_weight_on, line_weight_on,
            'Expected line_weight_on: ' + str(expected_line_weight_on) +
            'but got: ' + str(line_weight_on) + self.extra_data.get_all())
示例#16
0
class ShareFilesTests(TestCase):
    auth = None

    user_name = 'rest_tests_share_files_' + str(int(time())) + '@autodesk.com'
    password = '******'
    first_name = 'Rest'
    last_name = 'Test'

    extra_data = None
    main_register_and_login_mixin = MainRegisterAndLoginMixin()
    files_management_client = FilesManagementClient()
    partition_client = PartitionClient()

    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        if ShareFilesTests.auth is None:
            response = self.main_register_and_login_mixin.login_or_register(
                user_name=self.user_name,
                password=self.password,
                first_name=self.first_name,
                last_name=self.last_name)
            ShareFilesTests.auth = self.main_register_and_login_mixin.get_auth_from_login_data(
                response)
        self.assertIsInstance(
            ShareFilesTests.auth, str, 'Invalid auth: ' +
            str(ShareFilesTests.auth) + self.extra_data.get_all())

    def test_share_file(self):
        file_name = 'test_file_share_file_' + str(int(time())) + '.dwg'
        expected_code_and_description = (0, 'SUCCESS')
        user_name_to_share_with = 'rest_tests_share_with_user_' + str(
            int(time())) + '@autodesk.com'

        self.extra_data.add_test_data('file name', file_name)
        self.extra_data.add_test_data('user name to share with',
                                      user_name_to_share_with)

        login_data = self.main_register_and_login_mixin.login_or_register(
            user_name=user_name_to_share_with,
            password=self.password,
            first_name=self.first_name,
            last_name=self.last_name)
        auth_user_to_share_with = self.main_register_and_login_mixin.get_auth_from_login_data(
            login_data)

        self.assertIsInstance(
            auth_user_to_share_with, str, 'Invalid auth: ' +
            str(auth_user_to_share_with) + self.extra_data.get_all())

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        share_response = self.files_management_client.share_file(
            auth=self.auth,
            file_id=created_file_id,
            emails=[user_name_to_share_with])
        status_code = ClientUtils.get_response_status_code(share_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'share_file response',
            ClientUtils.get_response_body(share_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            share_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=auth_user_to_share_with, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        shared_file = TestUtils.get_entry_from_internal_file_system_entries(
            created_file_id, file_system_entries)

        self.assertIsNotNone(
            shared_file, 'Shared file should exist in partition' +
            self.extra_data.get_all())

    def test_share_file_v2(self):
        file_name = 'test_file_share_file_v2_' + str(int(time())) + '.dwg'
        expected_code_and_description = (0, 'SUCCESS')
        user_name_to_share_with = 'rest_tests_share_with_user_' + str(
            int(time())) + '@autodesk.com'

        self.extra_data.add_test_data('file name', file_name)
        self.extra_data.add_test_data('user name to share with',
                                      user_name_to_share_with)

        login_data = self.main_register_and_login_mixin.login_or_register(
            user_name=user_name_to_share_with,
            password=self.password,
            first_name=self.first_name,
            last_name=self.last_name)
        auth_user_to_share_with = self.main_register_and_login_mixin.get_auth_from_login_data(
            login_data)

        self.assertIsInstance(
            auth_user_to_share_with, str, 'Invalid auth: ' +
            str(auth_user_to_share_with) + self.extra_data.get_all())

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        share_response = self.files_management_client.share_file_v2(
            auth=self.auth,
            file_id=created_file_id,
            emails=[user_name_to_share_with])
        status_code = ClientUtils.get_response_status_code(share_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'share_file response',
            ClientUtils.get_response_body(share_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            share_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=auth_user_to_share_with, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        shared_file = TestUtils.get_entry_from_internal_file_system_entries(
            created_file_id, file_system_entries)

        self.assertIsNotNone(
            shared_file, 'Shared file should exist in partition' +
            self.extra_data.get_all())

    def test_share_file_v2_without_sharing_permissions(self):
        file_name = 'test_file_share_file_v2_without_permissions_' + str(
            int(time())) + '.dwg'
        expected_code_and_description = (3, 'INSUFFICIENT PERMISSIONS')
        user_name_to_share_with = 'rest_tests_share_with_user_' + str(
            int(time())) + '@autodesk.com'
        user_name_can_not_share_with = 'rest_tests_share_with_user_should_fail_' + str(
            int(time())) + '@autodesk.com'

        self.extra_data.add_test_data('file name', file_name)
        self.extra_data.add_test_data('user name to share with',
                                      user_name_to_share_with)
        self.extra_data.add_test_data('user name can not share with',
                                      user_name_can_not_share_with)

        login_data = self.main_register_and_login_mixin.login_or_register(
            user_name=user_name_to_share_with,
            password=self.password,
            first_name=self.first_name,
            last_name=self.last_name)
        auth_user_to_share_with = self.main_register_and_login_mixin.get_auth_from_login_data(
            login_data)

        self.assertIsInstance(
            auth_user_to_share_with, str, 'Invalid auth: ' +
            str(auth_user_to_share_with) + self.extra_data.get_all())

        login_data = self.main_register_and_login_mixin.login_or_register(
            user_name=user_name_can_not_share_with,
            password=self.password,
            first_name=self.first_name,
            last_name=self.last_name)
        auth_user_can_not_share_with = self.main_register_and_login_mixin.get_auth_from_login_data(
            login_data)

        self.assertIsInstance(
            auth_user_can_not_share_with, str, 'Invalid auth: ' +
            str(auth_user_can_not_share_with) + self.extra_data.get_all())

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        share_response = self.files_management_client.share_file_v2(
            auth=self.auth,
            file_id=created_file_id,
            emails=[user_name_to_share_with],
            can_share=False)
        status_code = ClientUtils.get_response_status_code(share_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'share_file response',
            ClientUtils.get_response_body(share_response))

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=auth_user_to_share_with, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        shared_file = TestUtils.get_entry_from_internal_file_system_entries(
            created_file_id, file_system_entries)

        self.assertIsNotNone(
            shared_file, 'Shared file should exist in partition' +
            self.extra_data.get_all())

        share_response = self.files_management_client.share_file_v2(
            auth=auth_user_to_share_with,
            file_id=created_file_id,
            emails=[user_name_can_not_share_with])
        status_code = ClientUtils.get_response_status_code(share_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'share_file response',
            ClientUtils.get_response_body(share_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            share_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=auth_user_can_not_share_with, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        shared_file = TestUtils.get_entry_from_internal_file_system_entries(
            created_file_id, file_system_entries)

        self.assertIsNone(
            shared_file,
            'File not shared due to missing permissions should not exist in partition'
            + self.extra_data.get_all())

    def test_get_file_shares(self):
        file_name = 'test_file_get_file_shares_' + str(int(time())) + '.dwg'
        user_name_to_share_with = 'rest_tests_share_with_user_' + str(
            int(time())) + '@autodesk.com'

        self.extra_data.add_test_data('file name', file_name)
        self.extra_data.add_test_data('user name to share with',
                                      user_name_to_share_with)

        login_data = self.main_register_and_login_mixin.login_or_register(
            user_name=user_name_to_share_with,
            password=self.password,
            first_name=self.first_name,
            last_name=self.last_name)

        self.assertIsNotNone(
            login_data, 'Failed to register user_name_to_share_with' +
            self.extra_data.get_all())

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        share_response = self.files_management_client.share_file_v2(
            auth=self.auth,
            file_id=created_file_id,
            emails=[user_name_to_share_with])
        status_code = ClientUtils.get_response_status_code(share_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'share_file response',
            ClientUtils.get_response_body(share_response))

        get_shares_response = self.files_management_client.get_file_shares(
            auth=self.auth, file_id=created_file_id)
        status_code = ClientUtils.get_response_status_code(get_shares_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'get_file_shares response',
            ClientUtils.get_response_body(get_shares_response))

        user_names = TestUtils.get_user_names_from_get_file_shares_response(
            get_shares_response)
        expected_user_names = [self.user_name, user_name_to_share_with]
        self.assertItemsEqual(
            expected_user_names, user_names,
            'Expected users ' + str(expected_user_names) +
            ' to have permissions on file but got: ' + str(user_names) +
            self.extra_data.get_all())

    def test_remove_file_share(self):
        file_name = 'test_file_remove_file_share' + str(int(time())) + '.dwg'
        expected_code_and_description = (0, 'SUCCESS')
        user_name_to_share_with = 'rest_tests_share_with_user_' + str(
            int(time())) + '@autodesk.com'

        login_data = self.main_register_and_login_mixin.login_or_register(
            user_name=user_name_to_share_with,
            password=self.password,
            first_name=self.first_name,
            last_name=self.last_name)
        user_id_to_share_with = self.main_register_and_login_mixin.get_user_id_from_login_data(
            login_data)
        auth_user_to_share_with = self.main_register_and_login_mixin.get_auth_from_login_data(
            login_data)

        self.assertIsInstance(
            auth_user_to_share_with, str, 'Invalid auth: ' +
            str(auth_user_to_share_with) + self.extra_data.get_all())

        created_file_id, msg = TestUtils.create_file(
            auth=self.auth, file_name=file_name, extra_data=self.extra_data)
        self.assertIsNotNone(created_file_id, msg + self.extra_data.get_all())

        share_response = self.files_management_client.share_file_v2(
            auth=self.auth,
            file_id=created_file_id,
            emails=[user_name_to_share_with])
        status_code = ClientUtils.get_response_status_code(share_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'share_file response',
            ClientUtils.get_response_body(share_response))

        delete_share_response = self.files_management_client.delete_file_share(
            auth=self.auth,
            file_id=created_file_id,
            user_id=user_id_to_share_with)
        status_code = ClientUtils.get_response_status_code(
            delete_share_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'delete_file_share response',
            ClientUtils.get_response_body(delete_share_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            delete_share_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=auth_user_to_share_with, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        shared_file = TestUtils.get_entry_from_internal_file_system_entries(
            created_file_id, file_system_entries)

        self.assertIsNone(
            shared_file,
            'File no longer shared should not exist in partition' +
            self.extra_data.get_all())
示例#17
0
class RegisterTests(TestCase):
    user_name = 'rest_tests_register_' + str(int(time())) + '@autodesk.com'
    first_name = 'Rest'
    last_name = 'Test'
    valid_password = '******'
    invalid_password = '******'
    empty_password = ''

    extra_data = None
    register_client = RegisterClient()
    main_login_v2_mixin = MainLoginV2Mixin()

    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)

    def test_register_v1_valid(self):
        response = self.register_client.register_v1(user_name=self.user_name, password=self.valid_password,
                                                    first_name=self.first_name,
                                                    last_name=self.last_name)
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(httplib.OK, status_code, 'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data('register response', ClientUtils.get_response_body(response))

        eidm_user_id = ClientUtils.get_value_from_body(response, RegisterClient.KEY_EIDM_USER_ID)
        self.assertIsNotNone(eidm_user_id, 'Expected eidm user id in response but got None' + self.extra_data.get_all())
        self.assertTrue(len(eidm_user_id) > 0, 'Expected a non-empty string as eidm user id but got: ' + str(
            eidm_user_id) + self.extra_data.get_all())

        eidm_user_name = ClientUtils.get_value_from_body(response, RegisterClient.KEY_EIDM_USER_NAME)
        self.assertIsNotNone(eidm_user_name, 'Expected eidm user name in response but got None' + self.extra_data.get_all())
        self.assertTrue(len(eidm_user_name) > 0, 'Expected a non-empty string as eidm user name but got: ' + str(
            eidm_user_name) + self.extra_data.get_all())

        email = ClientUtils.get_value_from_body(response, RegisterClient.KEY_MAIL)
        self.assertEquals(self.user_name, email, 'Expected user_name: ' + str(self.user_name) + ' but got: ' + str(
            email) + self.extra_data.get_all())

    def test_register_v1_valid_account_already_exists(self):
        self.make_sure_user_already_registered(self.user_name, self.valid_password)

        response = self.register_client.register_v1(user_name=self.user_name, password=self.valid_password,
                                                    first_name=self.first_name,
                                                    last_name=self.last_name)
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(httplib.OK, status_code, 'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data('register response', ClientUtils.get_response_body(response))

        email = ClientUtils.get_value_from_body(response, RegisterClient.KEY_MAIL)
        self.assertEquals(self.user_name, email, 'Expected user_name: ' + str(self.user_name) + ' but got: ' + str(
            email) + self.extra_data.get_all())

    def make_sure_user_already_registered(self, user_name, password):
        login_data = self.main_login_v2_mixin.login_request(user_name=user_name, password=password)
        user_id = self.main_login_v2_mixin.get_user_id_from_login_data(login_data)
        self.assertIsNotNone(user_id,
                             'Expected user_id not None. user probably does not exist yet, ' +
                             'previous register test probably failed' + self.extra_data.get_all())

    def test_register_v1_invalid_password(self):
        expected_code_and_description = (2, 'PASSWORD REJECTED')

        response = self.register_client.register_v1(user_name=self.user_name, password=self.invalid_password,
                                                    first_name=self.first_name,
                                                    last_name=self.last_name)
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(httplib.BAD_REQUEST, status_code,
                         'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data('register response', ClientUtils.get_response_body(response))

        code_desc = ClientUtils.get_code_and_description_from_response(response)
        self.assertEqual(expected_code_and_description, code_desc,
                         'Expected ' + str(expected_code_and_description) + ' but got: ' + str(
                             code_desc) + self.extra_data.get_all())

    def test_register_v1_empty_password(self):
        expected_code_and_description = (400, 'One or more parameters are missing.')

        response = self.register_client.register_v1(user_name=self.user_name, password=self.empty_password,
                                                    first_name=self.first_name,
                                                    last_name=self.last_name)
        status_code = ClientUtils.get_response_status_code(response)
        self.assertEqual(httplib.BAD_REQUEST, status_code,
                         'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data('register response', ClientUtils.get_response_body(response))

        code_desc = ClientUtils.get_code_and_description_from_response(response)
        self.assertEqual(expected_code_and_description, code_desc,
                         'Expected ' + str(expected_code_and_description) + ' but got: ' + str(
                             code_desc) + self.extra_data.get_all())
示例#18
0
class FolderTests(TestCase):
    auth = None

    user_name = 'rest_tests_manage_folders_' + str(int(
        time())) + '@autodesk.com'
    first_name = 'Rest'
    last_name = 'Test'
    password = '******'

    extra_data = None
    folders_management_client = FoldersManagementClient()

    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        main_register_and_login = MainRegisterAndLoginMixin()
        if FolderTests.auth is None:
            response = main_register_and_login.login_or_register(
                user_name=self.user_name,
                password=self.password,
                first_name=self.first_name,
                last_name=self.last_name)
            FolderTests.auth = main_register_and_login.get_auth_from_login_data(
                response)
        self.assertIsInstance(
            FolderTests.auth, str, 'Invalid auth: ' + str(FolderTests.auth) +
            self.extra_data.get_all())

    def test_create_folder(self):
        folder_name = 'test_folder_create_folder_' + str(int(time()))
        expected_code_and_description = (0, 'SUCCESS')

        self.extra_data.add_test_data('folder name', folder_name)

        create_folder_response = self.folders_management_client.create_folder(
            auth=self.auth, new_folder_name=folder_name)
        status_code = ClientUtils.get_response_status_code(
            create_folder_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'create_folder response',
            ClientUtils.get_response_body(create_folder_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            create_folder_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        response_folder_id = ClientUtils.get_value_from_body(
            create_folder_response, FoldersManagementClient.KEY_FOLDER_ID)
        self.assertTrue(
            response_folder_id > 0, 'Expected valid folder id but got: ' +
            str(response_folder_id) + self.extra_data.get_all())
        self.extra_data.add_test_data('response folder id', response_folder_id)

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        entry = TestUtils.get_entry_from_internal_file_system_entries(
            response_folder_id, file_system_entries)

        self.assertIsNotNone(
            entry, 'Created folder should exist in partition' +
            self.extra_data.get_all())
        partition_folder_name = TestUtils.get_entry_data_by_keys(
            entry=entry, keys=PartitionClient.KEY_ENTRY_NAME)
        self.assertEqual(
            folder_name, partition_folder_name,
            'Expected folder name: ' + str(folder_name) + ' but got: ' +
            str(partition_folder_name) + self.extra_data.get_all())

    def test_create_folder_v2(self):
        folder_name = 'test_folder_create_folder_v2_' + str(int(time()))
        expected_code_and_description = (0, 'SUCCESS')

        self.extra_data.add_test_data('folder name', folder_name)

        create_folder_response = self.folders_management_client.create_folder_v2(
            auth=self.auth, new_folder_name=folder_name)
        status_code = ClientUtils.get_response_status_code(
            create_folder_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'create_folder response',
            ClientUtils.get_response_body(create_folder_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            create_folder_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        response_folder_id = ClientUtils.get_value_from_body(
            create_folder_response, FoldersManagementClient.KEY_FOLDER_ID)
        self.assertTrue(
            response_folder_id > 0, 'Expected valid folder id but got: ' +
            str(response_folder_id) + self.extra_data.get_all())
        self.extra_data.add_test_data('response folder id', response_folder_id)

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        entry = TestUtils.get_entry_from_internal_file_system_entries(
            response_folder_id, file_system_entries)

        self.assertIsNotNone(
            entry, 'Created folder should exist in partition' +
            self.extra_data.get_all())
        partition_folder_name = TestUtils.get_entry_data_by_keys(
            entry=entry, keys=PartitionClient.KEY_ENTRY_NAME)
        self.assertEqual(
            folder_name, partition_folder_name,
            'Expected folder name: ' + str(folder_name) + ' but got: ' +
            str(partition_folder_name) + self.extra_data.get_all())

    def test_rename_folder(self):
        folder_name = 'test_folder_rename_folder_' + str(int(time()))
        folder_new_name = 'test_folder_rename_folder_renamed_' + str(
            int(time()))
        expected_code_and_description = (0, 'SUCCESS')

        self.extra_data.add_test_data('folder name', folder_name)
        self.extra_data.add_test_data('folder new name', folder_new_name)

        created_folder_id, msg = TestUtils.create_folder(
            auth=self.auth,
            folder_name=folder_name,
            extra_data=self.extra_data)
        self.assertIsNotNone(created_folder_id,
                             msg + self.extra_data.get_all())

        rename_folder_response = self.folders_management_client.rename_folder(
            auth=self.auth, folder_id=created_folder_id, name=folder_new_name)
        status_code = ClientUtils.get_response_status_code(
            rename_folder_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'rename_folder response',
            ClientUtils.get_response_body(rename_folder_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            rename_folder_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        entry = TestUtils.get_entry_from_internal_file_system_entries(
            created_folder_id, file_system_entries)

        self.assertIsNotNone(
            entry, 'Renamed folder should exist in partition' +
            self.extra_data.get_all())
        partition_folder_name = TestUtils.get_entry_data_by_keys(
            entry=entry, keys=PartitionClient.KEY_ENTRY_NAME)
        self.assertEqual(
            folder_new_name, partition_folder_name,
            'Expected folder name: ' + str(folder_new_name) + ' but got: ' +
            str(partition_folder_name) + self.extra_data.get_all())

    def test_rename_folder_v2(self):
        folder_name = 'test_folder_rename_folder_v2_' + str(int(time()))
        folder_new_name = 'test_folder_rename_folder_v2_renamed_' + str(
            int(time()))
        expected_code_and_description = (0, 'SUCCESS')

        self.extra_data.add_test_data('folder name', folder_name)
        self.extra_data.add_test_data('folder new name', folder_new_name)

        created_folder_id, msg = TestUtils.create_folder(
            auth=self.auth,
            folder_name=folder_name,
            extra_data=self.extra_data)
        self.assertIsNotNone(created_folder_id,
                             msg + self.extra_data.get_all())

        rename_folder_response = self.folders_management_client.rename_folder_v2(
            auth=self.auth, folder_id=created_folder_id, name=folder_new_name)
        status_code = ClientUtils.get_response_status_code(
            rename_folder_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'rename_folder response',
            ClientUtils.get_response_body(rename_folder_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            rename_folder_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        entry = TestUtils.get_entry_from_internal_file_system_entries(
            created_folder_id, file_system_entries)

        self.assertIsNotNone(
            entry, 'Renamed folder should exist in partition' +
            self.extra_data.get_all())
        partition_folder_name = TestUtils.get_entry_data_by_keys(
            entry=entry, keys=PartitionClient.KEY_ENTRY_NAME)
        self.assertEqual(
            folder_new_name, partition_folder_name,
            'Expected folder name: ' + str(folder_new_name) + ' but got: ' +
            str(partition_folder_name) + self.extra_data.get_all())

    def test_delete_folder(self):
        folder_name = 'test_folder_delete_folder_' + str(int(time()))
        expected_code_and_description = (0, 'SUCCESS')

        self.extra_data.add_test_data('folder name', folder_name)

        created_folder_id, msg = TestUtils.create_folder(
            auth=self.auth,
            folder_name=folder_name,
            extra_data=self.extra_data)
        self.assertIsNotNone(created_folder_id,
                             msg + self.extra_data.get_all())

        delete_folder_response = self.folders_management_client.delete_folder(
            auth=self.auth, folder_id=created_folder_id)
        status_code = ClientUtils.get_response_status_code(
            delete_folder_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'delete_folder response',
            ClientUtils.get_response_body(delete_folder_response))

        code_desc = ClientUtils.get_code_and_description_from_response(
            delete_folder_response)
        self.assertEqual(
            expected_code_and_description, code_desc,
            'Expected ' + str(expected_code_and_description) + ' but got: ' +
            str(code_desc) + self.extra_data.get_all())

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        entry = TestUtils.get_entry_from_internal_file_system_entries(
            created_folder_id, file_system_entries)

        self.assertIsNone(
            entry, 'Deleted folder should not exist in partition' +
            self.extra_data.get_all())
示例#19
0
class ShardingTests(TestCase):
    auth = None

    user_name = 'rest_tests_sharding_' + str(int(time())) + '@autodesk.com'
    password = '******'
    first_name = 'Rest'
    last_name = 'Test'

    extra_data = None
    files_management_client = FilesManagementClient()
    s3_client = S3Client()
    poll_client = PollClient()

    def setUp(self):
        self.extra_data = ExtraDataManager()
        self.extra_data.add_test_data('user name', self.user_name)
        main_register_and_login_mixin = MainRegisterAndLoginMixin()
        if ShardingTests.auth is None:
            response = main_register_and_login_mixin.login_or_register(
                user_name=self.user_name,
                password=self.password,
                first_name=self.first_name,
                last_name=self.last_name)
            ShardingTests.auth = main_register_and_login_mixin.get_auth_from_login_data(
                response)
        self.assertIsInstance(
            ShardingTests.auth, str, 'Invalid auth: ' +
            str(ShardingTests.auth) + self.extra_data.get_all())

    def test_get_url_to_upload_v1(self):
        file_name = 'LiveView_Clean.dwg'
        file_size = 64128

        url_to_upload_response = self.files_management_client.get_url_to_upload_v1(
            auth=self.auth,
            folder_id=0,
            file_name=file_name,
            file_size=file_size)
        status_code = ClientUtils.get_response_status_code(
            url_to_upload_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'get_url_to_upload response',
            ClientUtils.get_response_body(url_to_upload_response))

        version_id = ClientUtils.get_value_from_body(
            url_to_upload_response, FilesManagementClient.KEY_VERSION_ID)
        request_type = ClientUtils.get_value_from_body(
            url_to_upload_response, FilesManagementClient.KEY_REQUEST_TYPE)
        upload_url = ClientUtils.get_value_from_body(
            url_to_upload_response, FilesManagementClient.KEY_URL_TO_UPLOAD)
        header_x_amz_date = ClientUtils.get_value_from_body(
            url_to_upload_response, json_path='headers.x-amz-date')
        header_x_amz_acl = ClientUtils.get_value_from_body(
            url_to_upload_response, json_path='headers.x-amz-acl')
        header_authorization = ClientUtils.get_value_from_body(
            url_to_upload_response, json_path='headers.Authorization')
        headers_content_type = ClientUtils.get_value_from_body(
            url_to_upload_response, json_path='headers.Content-Type')

        self.assertTrue(
            version_id > 0, 'Expected valid version id but got: ' +
            str(version_id) + self.extra_data.get_all())
        self.extra_data.add_test_data('version id', version_id)

        self.assertEqual(
            'PUT', request_type, 'Expected request type PUT but got: ' +
            str(request_type) + self.extra_data.get_all())

        self.assertTrue(
            len(upload_url) > 0, 'Expected non empty upload url but got: ' +
            str(upload_url) + self.extra_data.get_all())

        self.assertTrue(
            header_x_amz_date > 0, 'Expected valid date but got: ' +
            str(header_x_amz_date) + self.extra_data.get_all())

        self.assertEqual(
            'authenticated-read', header_x_amz_acl,
            'Expected x-amz-acl header: authenticated-read but got: ' +
            str(header_x_amz_acl) + self.extra_data.get_all())

        self.assertTrue(
            len(header_authorization) > 0,
            'Expected at least one authorization header but got: ' +
            str(header_authorization) + self.extra_data.get_all())

        self.assertEqual(
            'application/octet-stream', headers_content_type,
            'Expected content-type header: ' + str(headers_content_type) +
            ' but got: ' + str(headers_content_type) +
            self.extra_data.get_all())

    def test_upload_file_to_s3_and_compress_dwg(self):
        file_name = 'LiveView_Clean.dwg'
        file_full_path = settings.BASE_DIR + '/rest_test/main_rest_tests/sharding/testfiles/' + file_name
        file_size = 64128
        compression_type = 1
        polling_timeout_in_seconds = 30
        delay_between_polls = 1

        self.upload_file_to_s3_and_compress(compression_type,
                                            delay_between_polls,
                                            file_full_path, file_name,
                                            file_size,
                                            polling_timeout_in_seconds)

    def test_upload_file_to_s3_and_compress_bmp(self):
        file_name = 'BMP-25.bmp'
        file_full_path = settings.BASE_DIR + '/rest_test/main_rest_tests/sharding/testfiles/' + file_name
        file_size = 264978
        compression_type = 4
        polling_timeout_in_seconds = 30
        delay_between_polls = 1

        self.upload_file_to_s3_and_compress(compression_type,
                                            delay_between_polls,
                                            file_full_path, file_name,
                                            file_size,
                                            polling_timeout_in_seconds)

    def test_upload_file_to_s3_and_compress_jpg(self):
        file_name = 'background.jpg'
        file_full_path = settings.BASE_DIR + '/rest_test/main_rest_tests/sharding/testfiles/' + file_name
        file_size = 87965
        compression_type = 4
        polling_timeout_in_seconds = 30
        delay_between_polls = 1

        self.upload_file_to_s3_and_compress(compression_type,
                                            delay_between_polls,
                                            file_full_path, file_name,
                                            file_size,
                                            polling_timeout_in_seconds)

    def test_upload_file_to_s3_and_compress_png(self):
        file_name = 'PngImage.png'
        file_full_path = settings.BASE_DIR + '/rest_test/main_rest_tests/sharding/testfiles/' + file_name
        file_size = 44454
        compression_type = 4
        polling_timeout_in_seconds = 30
        delay_between_polls = 1

        self.upload_file_to_s3_and_compress(compression_type,
                                            delay_between_polls,
                                            file_full_path, file_name,
                                            file_size,
                                            polling_timeout_in_seconds)

    def test_upload_file_to_s3_and_compress_gif(self):
        file_name = 'GifImage.gif'
        file_full_path = settings.BASE_DIR + '/rest_test/main_rest_tests/sharding/testfiles/' + file_name
        file_size = 42340
        compression_type = 4
        polling_timeout_in_seconds = 30
        delay_between_polls = 1

        self.upload_file_to_s3_and_compress(compression_type,
                                            delay_between_polls,
                                            file_full_path, file_name,
                                            file_size,
                                            polling_timeout_in_seconds)

    def test_upload_file_to_s3_and_compress_tif(self):
        file_name = 'TifImage.tif'
        file_full_path = settings.BASE_DIR + '/rest_test/main_rest_tests/sharding/testfiles/' + file_name
        file_size = 71189
        compression_type = 4
        polling_timeout_in_seconds = 30
        delay_between_polls = 1

        self.upload_file_to_s3_and_compress(compression_type,
                                            delay_between_polls,
                                            file_full_path, file_name,
                                            file_size,
                                            polling_timeout_in_seconds)

    # --- Currently sharding of font files is not working, un-comment when fixed ---
    # def test_upload_file_to_s3_and_compress_ttf(self):
    #     file_name = '47564.ttf'
    #     file_full_path = settings.BASE_DIR + '/rest_test/main_rest_tests/sharding/testfiles/' + file_name
    #     file_size = 16086
    #     compression_type = 5
    #     polling_timeout_in_seconds = 30
    #     delay_between_polls = 1
    #
    #     self.upload_file_to_s3_and_compress(compression_type, delay_between_polls, file_full_path, file_name, file_size,
    #                                         polling_timeout_in_seconds)

    def test_upload_file_to_s3_and_compress_pdf(self):
        file_name = 'LineTransparency.pdf'
        file_full_path = settings.BASE_DIR + '/rest_test/main_rest_tests/sharding/testfiles/' + file_name
        file_size = 59041
        compression_type = 11
        polling_timeout_in_seconds = 30
        delay_between_polls = 1

        self.upload_file_to_s3_and_compress(compression_type,
                                            delay_between_polls,
                                            file_full_path, file_name,
                                            file_size,
                                            polling_timeout_in_seconds)

    def test_upload_file_to_s3_and_compress_shx(self):
        file_name = 'mvt-mirym.shx'
        file_full_path = settings.BASE_DIR + '/rest_test/main_rest_tests/sharding/testfiles/' + file_name
        file_size = 27058
        compression_type = 5
        polling_timeout_in_seconds = 30
        delay_between_polls = 1

        self.upload_file_to_s3_and_compress(compression_type,
                                            delay_between_polls,
                                            file_full_path, file_name,
                                            file_size,
                                            polling_timeout_in_seconds)

    def upload_file_to_s3_and_compress(self, compression_type,
                                       delay_between_polls, file_full_path,
                                       file_name, file_size,
                                       polling_timeout_in_seconds):
        url_to_upload_response = self.files_management_client.get_url_to_upload_v1(
            auth=self.auth,
            folder_id=0,
            file_name=file_name,
            file_size=file_size)
        status_code = ClientUtils.get_response_status_code(
            url_to_upload_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'get_url_to_upload response',
            ClientUtils.get_response_body(url_to_upload_response))
        version_id = ClientUtils.get_value_from_body(
            url_to_upload_response, FilesManagementClient.KEY_VERSION_ID)
        request_type = ClientUtils.get_value_from_body(
            url_to_upload_response, FilesManagementClient.KEY_REQUEST_TYPE)
        upload_url = ClientUtils.get_value_from_body(
            url_to_upload_response, FilesManagementClient.KEY_URL_TO_UPLOAD)
        header_x_amz_acl = ClientUtils.get_value_from_body(
            url_to_upload_response, json_path='headers.x-amz-acl')
        header_authorization = ClientUtils.get_value_from_body(
            url_to_upload_response, json_path='headers.Authorization')
        header_content_type = ClientUtils.get_value_from_body(
            url_to_upload_response, json_path='headers.Content-Type')
        header_x_amz_date = ClientUtils.get_value_from_body(
            url_to_upload_response, json_path='headers.x-amz-date')
        self.extra_data.add_test_data('version id', version_id)
        self.extra_data.add_test_data('request type', request_type)
        self.extra_data.add_test_data('upload url', upload_url)
        self.extra_data.add_test_data('header x_amz_acl', header_x_amz_acl)
        self.extra_data.add_test_data('header authorization',
                                      header_authorization)
        self.extra_data.add_test_data('header content_type',
                                      header_content_type)
        self.extra_data.add_test_data('header x_amz_date', header_x_amz_date)

        upload_to_s3_response = self.s3_client.upload_to_s3(
            file_full_path=file_full_path,
            url_to_upload=upload_url,
            method=request_type,
            acl=header_x_amz_acl,
            auth=header_authorization,
            date=header_x_amz_date,
            content_type=header_content_type)
        status_code = ClientUtils.get_response_status_code(
            upload_to_s3_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())

        upload_to_compressor_response = self.files_management_client.upload_to_compressor(
            auth=self.auth,
            version_id=version_id,
            compression_type=compression_type)
        status_code = ClientUtils.get_response_status_code(
            upload_to_compressor_response)
        self.assertEqual(
            httplib.NO_CONTENT, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())

        successful_upload, msg = TestUtils.poll_for_upload(
            auth=self.auth,
            version_id=version_id,
            sleep_period=delay_between_polls,
            timeout_in_seconds=polling_timeout_in_seconds,
            extra_data=self.extra_data)
        self.assertIsNotNone(successful_upload,
                             msg + self.extra_data.get_all())

        return version_id

    def test_download_file(self):
        polling_timeout_in_seconds = 30
        delay_between_polls = 1

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())
        entry = TestUtils.get_first_drawing_from_internal_file_system(
            file_system_entries)
        self.extra_data.add_test_data('entry', entry)

        version_id_to_download = TestUtils.get_entry_data_by_keys(
            entry, 'versionId')
        self.assertTrue(
            version_id_to_download > 0, 'Expected valid version id but got: ' +
            str(version_id_to_download) + self.extra_data.get_all())
        self.extra_data.add_test_data('version id to download',
                                      version_id_to_download)

        prepare_file_to_download_response = self.files_management_client.prepare_file_to_download(
            auth=self.auth, version_id=version_id_to_download)
        status_code = ClientUtils.get_response_status_code(
            prepare_file_to_download_response)
        self.assertEqual(
            httplib.ACCEPTED, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'prepare_file_to_download response',
            ClientUtils.get_response_body(prepare_file_to_download_response))

        download_id = ClientUtils.get_value_from_body(
            prepare_file_to_download_response,
            FilesManagementClient.KEY_DOWNLOAD_ID)
        self.assertIsInstance(
            download_id, unicode, 'Expected unicode download id but got: ' +
            str(download_id) + self.extra_data.get_all())
        self.extra_data.add_test_data('download id', download_id)

        default_name, msg = TestUtils.poll_for_download(
            auth=self.auth,
            download_id=download_id,
            sleep_period=delay_between_polls,
            timeout_in_seconds=polling_timeout_in_seconds,
            extra_data=self.extra_data)
        self.assertIsNotNone(default_name, msg + self.extra_data.get_all())

        download_response = self.files_management_client.download_file(
            auth=self.auth,
            download_id=download_id,
            download_file_name=default_name)
        status_code = ClientUtils.get_response_status_code(download_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())

        downloaded_content = ClientUtils.get_response_raw_content(
            download_response)
        self.assertIsNotNone(
            downloaded_content,
            'Expected non empty content download' + self.extra_data.get_all())

    def test_plot_and_send_to_mail(self):  # workflow for web-client plotting
        polling_timeout_in_seconds = 30
        delay_between_polls = 1
        send_to = settings.GMAIL_USER_NAME
        password = settings.GMAIL_PASSWORD

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())
        entry = TestUtils.get_first_drawing_from_internal_file_system(
            file_system_entries)
        self.extra_data.add_test_data('entry', entry)

        version_id_to_plot = TestUtils.get_entry_data_by_keys(
            entry, 'versionId')
        self.assertTrue(
            version_id_to_plot > 0, 'Expected valid version id but got: ' +
            str(version_id_to_plot) + self.extra_data.get_all())
        self.extra_data.add_test_data('version id to plot', version_id_to_plot)

        plot_and_send_to_mail_response = self.files_management_client.plot_and_send_to_mail(
            auth=self.auth, version_id=version_id_to_plot, send_to=send_to)
        status_code = ClientUtils.get_response_status_code(
            plot_and_send_to_mail_response)
        self.assertEqual(
            httplib.ACCEPTED, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'plot_and_send_to_mail response',
            ClientUtils.get_response_body(plot_and_send_to_mail_response))

        download_id = ClientUtils.get_value_from_body(
            plot_and_send_to_mail_response,
            FilesManagementClient.KEY_DOWNLOAD_ID)
        self.assertIsInstance(
            download_id, unicode, 'Expected unicode download id but got: ' +
            str(download_id) + self.extra_data.get_all())
        self.extra_data.add_test_data('download id', download_id)

        default_name, msg = TestUtils.poll_for_plot(
            auth=self.auth,
            version_id=download_id,
            sleep_period=delay_between_polls,
            timeout_in_seconds=polling_timeout_in_seconds,
            extra_data=self.extra_data)

        self.assertIsNotNone(default_name, msg + self.extra_data.get_all())

        sleep(20)  # wait for email to be sent

        gmail_client = GmailClient()
        try:
            gmail_client.connect_to_account(send_to, password)
        except Exception as e:
            self.fail('Could not connect to mail account ' + str(send_to) +
                      ' to verify mail was sent after plot. Exception msg: ' +
                      str(e.message) + '. Exception args: ' + str(e.args) +
                      self.extra_data.get_all())
        self.assertTrue(
            gmail_client.open_label('INBOX'),
            'Failed to open INBOX label in ' + str(send_to) +
            self.extra_data.get_all())
        expected_mail_subject = default_name + ' was sent to you by ' + self.first_name + ' ' + self.last_name
        self.extra_data.add_test_data('expected mail subject',
                                      expected_mail_subject)
        self.assertIsNotNone(
            gmail_client.search_mails_in_label(
                subject_to_search=expected_mail_subject),
            'Could not find sent mail in ' + str(send_to) + ' INBOX' +
            self.extra_data.get_all())

    def test_plot_and_download(self):  # workflow for mobile-client plotting
        polling_timeout_in_seconds = 30
        delay_between_polls = 1

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())
        entry = TestUtils.get_first_drawing_from_internal_file_system(
            file_system_entries)
        self.extra_data.add_test_data('entry', entry)

        version_id_to_plot = TestUtils.get_entry_data_by_keys(
            entry, 'versionId')
        self.assertTrue(
            version_id_to_plot > 0, 'Expected integer version id but got: ' +
            str(version_id_to_plot) + self.extra_data.get_all())
        self.extra_data.add_test_data('version id to plot', version_id_to_plot)

        prepare_file_to_plot_response = self.files_management_client.prepare_file_to_download(
            auth=self.auth, version_id=version_id_to_plot, format='plot')
        status_code = ClientUtils.get_response_status_code(
            prepare_file_to_plot_response)
        self.assertEqual(
            httplib.ACCEPTED, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())
        self.extra_data.add_test_data(
            'prepare_file_to_download response',
            ClientUtils.get_response_body(prepare_file_to_plot_response))

        download_id = ClientUtils.get_value_from_body(
            prepare_file_to_plot_response,
            FilesManagementClient.KEY_DOWNLOAD_ID)
        self.assertIsInstance(
            download_id, unicode, 'Expected unicode download id but got: ' +
            str(download_id) + self.extra_data.get_all())
        self.extra_data.add_test_data('download id', download_id)

        default_name, msg = TestUtils.poll_for_download(
            auth=self.auth,
            download_id=download_id,
            sleep_period=delay_between_polls,
            timeout_in_seconds=polling_timeout_in_seconds,
            extra_data=self.extra_data)
        self.assertIsNotNone(default_name, msg + self.extra_data.get_all())

        download_response = self.files_management_client.download_file(
            auth=self.auth,
            download_id=download_id,
            download_file_name=default_name)
        status_code = ClientUtils.get_response_status_code(download_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())

        downloaded_content = ClientUtils.get_response_raw_content(
            download_response)
        self.assertIsNotNone(
            downloaded_content,
            'Expected non empty content download' + self.extra_data.get_all())

    def test_get_xrefs_uploaded_as_zip(self):
        zip_file_name_without_extension = 'xref with block - Standard'
        zip_file_name = zip_file_name_without_extension + '.zip'
        zip_file_full_path = settings.BASE_DIR + '/rest_test/main_rest_tests/sharding/testfiles/' + zip_file_name
        zip_file_size = 108960

        file_name_with_xrefs = 'xref with block.dwg'
        file_xref_name = '\one block.dwg'

        compression_type = 8
        polling_timeout_in_seconds = 60
        delay_between_polls = 2

        self.upload_file_to_s3_and_compress(compression_type,
                                            delay_between_polls,
                                            zip_file_full_path, zip_file_name,
                                            zip_file_size,
                                            polling_timeout_in_seconds)

        # Must wait for all files in zip to upload. No better way, since urlToUpload resource returns only 1 version id
        sleep(20)

        root_file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth, extra_data=self.extra_data)
        self.assertIsNotNone(root_file_system_entries,
                             msg + self.extra_data.get_all())

        xrefs_folder_version_id = None
        for entry in root_file_system_entries:
            if entry['name'] == zip_file_name_without_extension and entry[
                    'type'] == 'FOLDER':
                xrefs_folder_version_id = entry[
                    PartitionClient.
                    KEY_FOLDER_ID]  # created when zip was uploaded
                break
        self.assertIsNotNone(
            xrefs_folder_version_id, 'Expected a new folder created named ' +
            str(zip_file_name_without_extension) + self.extra_data.get_all())
        self.extra_data.add_test_data('xrefs folder version id',
                                      xrefs_folder_version_id)

        file_system_entries, msg = TestUtils.get_internal_partition(
            auth=self.auth,
            partition_folder_id=xrefs_folder_version_id,
            extra_data=self.extra_data)
        self.assertIsNotNone(file_system_entries,
                             msg + self.extra_data.get_all())

        file_with_xrefs_version_id = None
        for entry in file_system_entries:
            if entry['name'] == file_name_with_xrefs and entry[
                    'type'] == 'DRAWING':
                file_with_xrefs_version_id = entry[
                    PartitionClient.KEY_PRIMARY_VERSION_ID]
                break
        self.assertIsNotNone(
            file_with_xrefs_version_id,
            'Expected the new file named ' + str(file_name_with_xrefs) +
            ' uploaded into folder' + self.extra_data.get_all())
        self.extra_data.add_test_data('file with xrefs version id',
                                      file_with_xrefs_version_id)

        xrefs_client = XrefsClient()
        get_xrefs_response = xrefs_client.get_all_xrefs(
            auth=self.auth, version_id=file_with_xrefs_version_id)
        status_code = ClientUtils.get_response_status_code(get_xrefs_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())

        response_xrefs = ClientUtils.get_response_body(get_xrefs_response)
        self.assertIsNotNone(
            response_xrefs, 'Expected non empty get_all_xrefs response body' +
            self.extra_data.get_all())

        self.assertTrue(
            len(response_xrefs) > 0, 'Expected at least one xref, but got: ' +
            str(response_xrefs) + self.extra_data.get_all())
        self.extra_data.add_test_data('get_all_xrefs response', response_xrefs)

        for xref in response_xrefs:
            xref_name = xref['name']
            xref_is_missing = xref['missing']
            xref_type = xref['type']
            self.assertEqual(
                file_xref_name, xref_name,
                'Expected xref name: ' + str(file_xref_name) + ' but got: ' +
                str(xref_name) + self.extra_data.get_all())
            self.assertFalse(
                xref_is_missing,
                'Xref was uploaded to s3, should not be missing' +
                self.extra_data.get_all())
            self.assertIsNotNone(
                xref_type,
                'Expected non empty xref type' + self.extra_data.get_all())

    def test_get_xrefs_all_missing(self):
        file_name = 'xref with block.dwg'
        file_full_path = settings.BASE_DIR + '/rest_test/main_rest_tests/sharding/testfiles/file_with_xref/' + file_name
        file_size = 64687
        file_xref_name = '\one block.dwg'

        compression_type = 1
        polling_timeout_in_seconds = 60
        delay_between_polls = 2

        version_id = self.upload_file_to_s3_and_compress(
            compression_type, delay_between_polls, file_full_path, file_name,
            file_size, polling_timeout_in_seconds)

        xrefs_client = XrefsClient()
        get_xrefs_response = xrefs_client.get_all_xrefs(auth=self.auth,
                                                        version_id=version_id)
        status_code = ClientUtils.get_response_status_code(get_xrefs_response)
        self.assertEqual(
            httplib.OK, status_code,
            'Got status code: ' + str(status_code) + self.extra_data.get_all())

        response_xrefs = ClientUtils.get_response_body(get_xrefs_response)
        self.assertIsNotNone(
            response_xrefs, 'Expected non empty get_all_xrefs response body' +
            self.extra_data.get_all())

        self.assertTrue(
            len(response_xrefs) > 0, 'Expected at least one xref, but got: ' +
            str(response_xrefs) + self.extra_data.get_all())
        self.extra_data.add_test_data('get_all_xrefs response', response_xrefs)

        for xref in response_xrefs:
            xref_name = xref['name']
            xref_is_missing = xref['missing']
            xref_type = xref['type']
            self.assertEqual(
                file_xref_name, xref_name,
                'Expected xref name: ' + str(file_xref_name) + ' but got: ' +
                str(xref_name) + self.extra_data.get_all())
            self.assertTrue(
                xref_is_missing,
                'Xref was not uploaded to s3, should be missing' +
                self.extra_data.get_all())
            self.assertIsNotNone(
                xref_type,
                'Expected non empty xref type' + self.extra_data.get_all())