当前位置: 首页>>代码示例>>Python>>正文


Python APITestHelper.request方法代码示例

本文整理汇总了Python中tests.ozpcenter.helper.APITestHelper.request方法的典型用法代码示例。如果您正苦于以下问题:Python APITestHelper.request方法的具体用法?Python APITestHelper.request怎么用?Python APITestHelper.request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tests.ozpcenter.helper.APITestHelper的用法示例。


在下文中一共展示了APITestHelper.request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_create_subscription_invalid_entity_type

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
 def test_create_subscription_invalid_entity_type(self):
     url = '/api/subscription/'
     data = {
         'entity_type': 'none',
         'entity_id': 5
     }
     APITestHelper.request(self, url, 'POST', data=data, username='bigbrother', status_code=400)
开发者ID:aml-development,项目名称:ozp-backend,代码行数:9,代码来源:test_api_subscription.py

示例2: test_storefront_authorized_with_ordering

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
    def test_storefront_authorized_with_ordering(self):
        # Recommended
        url = '/api/storefront/recommended/?ordering=title'
        response = APITestHelper.request(self, url, 'GET', username='wsmith', status_code=200)
        data = response.data['recommended']
        sorted_data = sorted(data, key=lambda x: x['title'])
        self.assertEqual(data, sorted_data)

        # Featured
        url = '/api/storefront/featured/?ordering=-title'
        response = APITestHelper.request(self, url, 'GET', username='wsmith', status_code=200)
        data = response.data['featured']
        sorted_data = sorted(data, key=lambda x: x['title'], reverse=True)
        self.assertEqual(data, sorted_data)

        # Most Popular
        url = '/api/storefront/most_popular/?ordering=-edited_date'
        response = APITestHelper.request(self, url, 'GET', username='wsmith', status_code=200)
        data = response.data['most_popular']
        sorted_data = sorted(data, key=lambda x: x['edited_date'], reverse=True)
        self.assertEqual(data, sorted_data)

        # Recent
        url = '/api/storefront/recent/?ordering=-approved_date'
        response = APITestHelper.request(self, url, 'GET', username='wsmith', status_code=200)
        data = response.data['recent']
        sorted_data = sorted(data, key=lambda x: x['approved_date'], reverse=True)
        self.assertEqual(data, sorted_data)
开发者ID:aml-development,项目名称:ozp-backend,代码行数:30,代码来源:test_api_storefront.py

示例3: test_get_deleted_tag_subscription

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
    def test_get_deleted_tag_subscription(self):
        subscription_response = self._create_subscription('tag', username='bigbrother')
        url = '/api/tag/{}/'.format(subscription_response.data['entity_id'])
        APITestHelper.request(self, url, 'DELETE', username='bigbrother', status_code=204)

        url = '/api/subscription/{}/'.format(subscription_response.data['id'])
        response = APITestHelper.request(self, url, 'GET', username='bigbrother', status_code=200)
        # TODO: should status_code be 404?
        self.assertEqual(response.data['entity_description'], 'OBJECT NOT FOUND')
开发者ID:aml-development,项目名称:ozp-backend,代码行数:11,代码来源:test_api_subscription.py

示例4: test_frequently_visited_listings_with_ordering

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
    def test_frequently_visited_listings_with_ordering(self):
        url = '/api/profile/self/listingvisits/frequent/?ordering=-title'
        response = APITestHelper.request(self, url, 'GET', username='bigbrother', status_code=200)
        data = response.data

        url = '/api/profile/self/listingvisits/frequent/?ordering=title'
        response = APITestHelper.request(self, url, 'GET', username='bigbrother', status_code=200)
        reverse_data = response.data

        self.assertEqual(data, reverse_data[::-1])
开发者ID:aml-development,项目名称:ozp-backend,代码行数:12,代码来源:test_api_profile_listingvisit.py

示例5: test_increment_visit

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
    def test_increment_visit(self):
        # assumes bigbrother has at least one listing visit
        url = '/api/profile/self/listingvisits/'
        response = APITestHelper.request(self, url, 'GET', username='bigbrother', status_code=200)
        visit = response.data[0]

        url = '/api/profile/self/listingvisits/increment/'
        data = {'listing': {'id': visit['listing']['id']}}
        response = APITestHelper.request(self, url, 'POST', data=data, username='bigbrother', status_code=200)
        new_visit = response.data

        self.assertEqual(visit['count'] + 1, new_visit['count'])
开发者ID:aml-development,项目名称:ozp-backend,代码行数:14,代码来源:test_api_profile_listingvisit.py

示例6: test_negative_feedback_listing

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
    def test_negative_feedback_listing(self):
        # Create a negative feedback
        url = '/api/listing/1/feedback/'
        data = {"feedback": -1}
        APITestHelper.request(self, url, 'POST', data=data, username='bettafish', status_code=201)

        # Check to see if created
        response = APITestHelper.request(self, url, 'GET', username='bettafish', status_code=200)
        self.assertEqual(response.data['feedback'], -1)

        # Check with a different beta group user to see if feedback exists for said user
        response = APITestHelper.request(self, url, 'GET', username='betaraybill', status_code=404)
        self.assertEqual(response.data['feedback'], 0)
开发者ID:aml-development,项目名称:ozp-backend,代码行数:15,代码来源:test_api_listing_feedback.py

示例7: test_frequently_visited_listings

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
    def test_frequently_visited_listings(self):
        url = '/api/profile/self/listingvisits/frequent/'
        response = APITestHelper.request(self, url, 'GET', username='bigbrother', status_code=200)
        freq_visit_ids = [i['id'] for i in response.data]

        url = '/api/profile/self/listingvisits/'
        response = APITestHelper.request(self, url, 'GET', username='bigbrother', status_code=200)
        visit_counts = dict((i['listing']['id'], i['count']) for i in response.data)

        curr_count = None
        for id in freq_visit_ids:
            if curr_count is not None:
                self.assertTrue(visit_counts[id] <= curr_count)
            curr_count = visit_counts[id]
开发者ID:aml-development,项目名称:ozp-backend,代码行数:16,代码来源:test_api_profile_listingvisit.py

示例8: test_delete_listing

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
    def test_delete_listing(self):
        url = '/api/listing/1/'
        response = APITestHelper.request(self, url, 'GET', username='wsmith', status_code=200)
        self.assertFalse(response.data.get('is_deleted'))
        self.assertEqual(validate_listing_map_keys(response.data), [])

        url = '/api/listing/1/'
        data = {'description': 'deleting listing'}
        response = APITestHelper.request(self, url, 'DELETE', data=data, username='wsmith', status_code=204)

        url = '/api/listing/1/'
        response = APITestHelper.request(self, url, 'GET', username='wsmith', status_code=200)
        self.assertTrue(response.data.get('is_deleted'))
        self.assertEqual(validate_listing_map_keys(response.data), [])
开发者ID:aml-development,项目名称:ozp-backend,代码行数:16,代码来源:test_api_listing.py

示例9: test_subscription_subscribe_unsubscribe

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
    def test_subscription_subscribe_unsubscribe(self):
        for entity_type in self.entity_types:
            subscription_response = self._create_subscription(entity_type)

            # unsubscribe
            url = '/api/self/subscription/{}/'.format(subscription_response.data['id'])
            APITestHelper.request(self, url, 'DELETE', username='bigbrother', status_code=204)

            # Verify that subscription does not exist
            url = '/api/subscription/{}/'.format(subscription_response.data['id'])
            response = APITestHelper.request(self, url, 'GET', username='bigbrother', status_code=404)
            # response.data = {'error_code': 'not_found', 'error': True, 'detail': 'Not found.'}

            url = '/api/self/subscription/{}/'.format(subscription_response.data['id'])
            response = APITestHelper.request(self, url, 'GET', username='bigbrother', status_code=404)
开发者ID:aml-development,项目名称:ozp-backend,代码行数:17,代码来源:test_api_subscription.py

示例10: test_recommendation_baseline

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
    def test_recommendation_baseline(self):
        recommender_wrapper_obj = RecommenderDirectory()
        actual_result = recommender_wrapper_obj.recommend('baseline')
        expected_result = {'Baseline': {}}
        self.assertEquals(actual_result, expected_result)

        url = '/api/storefront/recommended/?randomize=False'
        response = APITestHelper.request(self, url, 'GET', username='wsmith', status_code=200)

        title_scores = [{'title': listing['title'], '_score': listing['_score']} for listing in response.data['recommended']]
        title_scores = sorted(title_scores, key=lambda k: (k['_score']['_sort_score'], k['title']))  # Order can change between postgres and sqlite
        title_scores = shorthand_dict(title_scores)

        expected_result = [
            '(_score:(Baseline:(raw_score:9.0,weight:1.0),_sort_score:9.0),title:Astrology software)',
            '(_score:(Baseline:(raw_score:9.0,weight:1.0),_sort_score:9.0),title:Bass Fishing)',
            '(_score:(Baseline:(raw_score:9.0,weight:1.0),_sort_score:9.0),title:Dragons)',
            '(_score:(Baseline:(raw_score:9.0,weight:1.0),_sort_score:9.0),title:House Targaryen)',
            '(_score:(Baseline:(raw_score:9.0,weight:1.0),_sort_score:9.0),title:Informational Book)',
            '(_score:(Baseline:(raw_score:9.0,weight:1.0),_sort_score:9.0),title:JotSpot)',
            '(_score:(Baseline:(raw_score:10.0,weight:1.0),_sort_score:10.0),title:Acoustic Guitar)',
            '(_score:(Baseline:(raw_score:10.5,weight:1.0),_sort_score:10.5),title:Killer Whale)',
            '(_score:(Baseline:(raw_score:11.5,weight:1.0),_sort_score:11.5),title:Chart Course)',
            '(_score:(Baseline:(raw_score:11.5,weight:1.0),_sort_score:11.5),title:Wolf Finder)'
        ]

        # import pprint
        # print(pprint.pprint(title_scores))
        self.assertEquals(expected_result, title_scores)

        sorted_scores = [listing['_score']['_sort_score'] for listing in response.data['recommended']]
        self.assertEquals(sorted(sorted_scores, reverse=True), sorted_scores)
开发者ID:aml-development,项目名称:ozp-backend,代码行数:34,代码来源:test_recommend.py

示例11: test_update_contact_type_apps_mall_steward

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
    def test_update_contact_type_apps_mall_steward(self):
        url = '/api/contact_type/1/'
        data = {'name': 'Updated Type', 'required': True}
        response = APITestHelper.request(self, url, 'PUT', data=data, username='bigbrother', status_code=200)

        self.assertEqual(response.data['name'], 'Updated Type')
        self.assertEqual(response.data['required'], True)
开发者ID:aml-development,项目名称:ozp-backend,代码行数:9,代码来源:test_api_contact_type.py

示例12: test_recommendation_graph

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
    def test_recommendation_graph(self):
        recommender_wrapper_obj = RecommenderDirectory()
        actual_result = recommender_wrapper_obj.recommend('graph_cf')
        expected_result = {'Bookmark Collaborative Filtering': {}}
        self.assertEquals(actual_result, expected_result)

        url = '/api/storefront/recommended/?randomize=False'
        response = APITestHelper.request(self, url, 'GET', username='wsmith', status_code=200)

        title_scores = [{'title': listing['title'], '_score': listing['_score']} for listing in response.data['recommended']]
        title_scores = sorted(title_scores, key=lambda k: (k['_score']['_sort_score'], k['title']))  # Order can change between postgres and sqlite
        title_scores = shorthand_dict(title_scores)

        import pprint
        pprint.pprint(title_scores)

        expected_result = [
            '(_score:(Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:5.0),title:Acoustic Guitar)',
            '(_score:(Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:5.0),title:Bleach)',
            '(_score:(Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:5.0),title:Bourbon)',
            '(_score:(Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:5.0),title:India Pale Ale)',
            '(_score:(Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:5.0),title:Informational Book)',
            '(_score:(Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:5.0),title:Internet meme)',
            '(_score:(Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:5.0),title:Killer Whale)',
            '(_score:(Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:5.0),title:Screamin Eagle CVO)',
            '(_score:(Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:5.0),title:Snow)',
            '(_score:(Bookmark Collaborative Filtering:(raw_score:2.0,weight:5.0),_sort_score:10.0),title:Chart Course)'
        ]
        # import pprint
        # print(pprint.pprint(title_scores))
        self.assertEquals(expected_result, title_scores)

        sorted_scores = [listing['_score']['_sort_score'] for listing in response.data['recommended']]
        self.assertEquals(sorted(sorted_scores, reverse=True), sorted_scores)
开发者ID:aml-development,项目名称:ozp-backend,代码行数:36,代码来源:test_recommend.py

示例13: test_recommendation_baseline_graph

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
    def test_recommendation_baseline_graph(self):
        recommender_wrapper_obj = RecommenderDirectory()
        actual_result = recommender_wrapper_obj.recommend('baseline,graph_cf')
        expected_result = {'Baseline': {}, 'Bookmark Collaborative Filtering': {}}
        self.assertEquals(actual_result, expected_result)

        url = '/api/storefront/recommended/?randomize=False'
        response = APITestHelper.request(self, url, 'GET', username='wsmith', status_code=200)

        title_scores = [{'title': listing['title'], '_score': listing['_score']} for listing in response.data['recommended']]
        title_scores = sorted(title_scores, key=lambda k: (k['_score']['_sort_score'], k['title']))  # Order can change between postgres and sqlite
        title_scores = shorthand_dict(title_scores)

        expected_result = [
            '(_score:(Baseline:(raw_score:8.2,weight:1.0),Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:13.2),title:Navigation)',
            '(_score:(Baseline:(raw_score:8.5,weight:1.0),Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:13.5),title:Bleach)',
            '(_score:(Baseline:(raw_score:9.0,weight:1.0),Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:14.0),title:Informational Book)',
            '(_score:(Baseline:(raw_score:9.0,weight:1.0),Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:14.0),title:JotSpot)',
            '(_score:(Baseline:(raw_score:9.0,weight:1.0),Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:14.0),title:LocationLister)',
            '(_score:(Baseline:(raw_score:9.0,weight:1.0),Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:14.0),title:Stop sign)',
            '(_score:(Baseline:(raw_score:10.0,weight:1.0),Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:15.0),title:Acoustic Guitar)',
            '(_score:(Baseline:(raw_score:10.5,weight:1.0),Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:15.5),title:Killer Whale)',
            '(_score:(Baseline:(raw_score:11.5,weight:1.0),Bookmark Collaborative Filtering:(raw_score:1.0,weight:5.0),_sort_score:16.5),title:Wolf Finder)',
            '(_score:(Baseline:(raw_score:11.5,weight:1.0),Bookmark Collaborative Filtering:(raw_score:2.0,weight:5.0),_sort_score:21.5),title:Chart Course)'
        ]

        # import pprint
        # print(pprint.pprint(title_scores))
        self.assertEquals(expected_result, title_scores)

        sorted_scores = [listing['_score']['_sort_score'] for listing in response.data['recommended']]
        self.assertEquals(sorted(sorted_scores, reverse=True), sorted_scores)
开发者ID:aml-development,项目名称:ozp-backend,代码行数:34,代码来源:test_recommend.py

示例14: test_get_bookmark_list_shared_folder_permissions

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
    def test_get_bookmark_list_shared_folder_permissions(self):
        """
        Test getting permissions for a shared folder, test between owner, viewer, other
        """
        username = 'bigbrother2'
        url = '/api/bookmark/'
        response = APITestHelper.request(self, url, 'GET', username=username, status_code=200)
        bookmark_folder = BookmarkFolder.parse_endpoint(response.data)
        # Getting the id of the first shared folder
        shared_folder_id = bookmark_folder.first_shared_folder().id

        bigbrother2_permission_shorthand_expected = [
            'bigbrother2(OWNER)',
            'julia(OWNER)',
            'johnson(VIEWER)'
        ]

        # Check OWNER permission
        _get_folder_permission(self, 'bigbrother2', shared_folder_id, bigbrother2_permission_shorthand_expected)
        # Check OWNER permission
        _get_folder_permission(self, 'julia', shared_folder_id, bigbrother2_permission_shorthand_expected)
        # Check VIEWER permission
        _get_folder_permission(self, 'johnson', shared_folder_id, bigbrother2_permission_shorthand_expected, status_code=403)
        # Check OTHER permission
        _get_folder_permission(self, 'bigbrother', shared_folder_id, bigbrother2_permission_shorthand_expected, status_code=403)
开发者ID:aml-development,项目名称:ozp-backend,代码行数:27,代码来源:test_api_bookmark.py

示例15: test_recommendation_user_base

# 需要导入模块: from tests.ozpcenter.helper import APITestHelper [as 别名]
# 或者: from tests.ozpcenter.helper.APITestHelper import request [as 别名]
    def test_recommendation_user_base(self):
        if self.es_failed:
            self.skipTest('Elasticsearch is not currently up: {}'.format(self.error_string))
        recommender_wrapper_obj = RecommenderDirectory()
        actual_result = recommender_wrapper_obj.recommend('elasticsearch_user_base')
        expected_result = {'Elasticsearch User Based Filtering': {}}

        self.assertEquals(actual_result, expected_result)

        url = '/api/storefront/recommended/?randomize=False'
        response = APITestHelper.request(self, url, 'GET', username='wsmith', status_code=200)

        title_scores = [{'title': listing['title'], '_score': listing['_score']} for listing in response.data['recommended']]
        # title_scores = sorted(title_scores, key=lambda k: (k['_score']['_sort_score'], k['title']))
        title_scores = shorthand_dict(title_scores)

        expected_result = [
            '(_score:(Elasticsearch User Based Filtering:(raw_score:10.0,weight:1.0),_sort_score:10.0),title:Railroad)',
            '(_score:(Elasticsearch User Based Filtering:(raw_score:10.0,weight:1.0),_sort_score:10.0),title:Barsoom)',
            '(_score:(Elasticsearch User Based Filtering:(raw_score:10.0,weight:1.0),_sort_score:10.0),title:Snow)',
            '(_score:(Elasticsearch User Based Filtering:(raw_score:10.0,weight:1.0),_sort_score:10.0),title:Business Management System)',
            '(_score:(Elasticsearch User Based Filtering:(raw_score:10.0,weight:1.0),_sort_score:10.0),title:Tornado)',
            '(_score:(Elasticsearch User Based Filtering:(raw_score:8.333,weight:1.0),_sort_score:8.333),title:Pluto (Not a planet))',
            '(_score:(Elasticsearch User Based Filtering:(raw_score:8.333,weight:1.0),_sort_score:8.333),title:Project Management)',
            '(_score:(Elasticsearch User Based Filtering:(raw_score:8.333,weight:1.0),_sort_score:8.333),title:BeiDou Navigation Satellite System)',
            '(_score:(Elasticsearch User Based Filtering:(raw_score:8.333,weight:1.0),_sort_score:8.333),title:Satellite navigation)',
            '(_score:(Elasticsearch User Based Filtering:(raw_score:8.333,weight:1.0),_sort_score:8.333),title:Stop sign)'
        ]

        # import json; print(json.dumps(title_scores, indent=4))
        self.assertEquals(expected_result, title_scores)
开发者ID:aml-development,项目名称:ozp-backend,代码行数:33,代码来源:test_recommend_es.py


注:本文中的tests.ozpcenter.helper.APITestHelper.request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。