Пример #1
0
    def test_category_ordering(self):
        # Create new category
        url = '/api/category/'
        data = {
            'title': 'AAA new category',
            'description': 'category description'
        }
        response = APITestHelper.request(self,
                                         url,
                                         'POST',
                                         data=data,
                                         username='******',
                                         status_code=201)
        shorten_data = shorthand_dict(response.data,
                                      exclude_keys=['id', 'import_metadata'])

        expected_results = '(description:category description,title:AAA new category)'
        self.assertEqual(shorten_data, expected_results)

        # GET request
        url = '/api/category/'
        response = APITestHelper.request(self,
                                         url,
                                         'GET',
                                         username='******',
                                         status_code=200)
        shorten_data = shorthand_dict(response.data,
                                      exclude_keys=['id', 'import_metadata'])
        expected_results = [
            '(description:category description,title:AAA new category)'
        ] + self.expected_categories
        self.assertListEqual(shorten_data, expected_results)
Пример #2
0
    def test_get_all_review_for_listing(self):
        url = '/api/listing/1/review/'
        response = APITestHelper.request(self,
                                         url,
                                         'GET',
                                         username='******',
                                         status_code=200)
        keys_to_include = [
            'author', 'author.user', 'author.user.username', 'rate', 'text',
            'review_responses', 'review_responses[*]',
            'review_responses[*].rate', 'review_responses[*].text'
        ]
        response_shorten = shorthand_dict(response.data,
                                          include_keys=keys_to_include,
                                          list_star=True)

        expected_data = [
            '(author:(user:(username:charrington)),rate:3,review_responses:[],text:I love the sound of acoustic guitars rock on)',
            '(author:(user:(username:syme)),rate:5,review_responses:[(rate:0,text:Review for syme loving acoustic guitars)],text:I love the sound of acoustic guitars)',
            '(author:(user:(username:wsmith)),rate:1,review_responses:[],text:I don\'t like the sound of acoustic guitars. I like electric guitars more)',
            '(author:(user:(username:bigbrother)),rate:3,review_responses:[],text:Favorite Instrument by far. BY. FAR.)'
        ]

        self.assertEqual(
            response_shorten,
            shorthand_dict(expected_data,
                           include_keys=keys_to_include,
                           list_star=True))
Пример #3
0
    def test_email_sync(self):
        email_results = create_email(3)

        actual_results = shorthand_dict(email_results, exclude_keys='time')
        expected_results = '(error:False,message:13 New Notifications for username: khaleesi)'
        self.assertEqual(actual_results, expected_results)

        email_results = create_email(3)

        actual_results = shorthand_dict(email_results, exclude_keys='time')
        expected_results = '(error:False,message:No New Notifications for username: khaleesi)'
        self.assertEqual(actual_results, expected_results)
    def test_get_all_review_for_listing(self):
        url = '/api/listing/1/review/'
        response = APITestHelper.request(self, url, 'GET', username='******', status_code=200)
        keys_to_include = ['author', 'author.user', 'author.user.username', 'rate', 'text',
                           'review_responses', 'review_responses[*]', 'review_responses[*].rate', 'review_responses[*].text']
        response_shorten = shorthand_dict(response.data, include_keys=keys_to_include, list_star=True)

        expected_data = [
            '(author:(user:(username:charrington)),rate:3,review_responses:[],text:I love the sound of acoustic guitars rock on)',
            '(author:(user:(username:syme)),rate:5,review_responses:[(rate:0,text:Review for syme loving acoustic guitars)],text:I love the sound of acoustic guitars)',
            '(author:(user:(username:wsmith)),rate:1,review_responses:[],text:I don\'t like the sound of acoustic guitars. I like electric guitars more)',
            '(author:(user:(username:bigbrother)),rate:3,review_responses:[],text:Favorite Instrument by far. BY. FAR.)'
        ]

        self.assertEqual(response_shorten, shorthand_dict(expected_data, include_keys=keys_to_include, list_star=True))
    def test_get_category(self):
        url = '/api/category/1/'
        response = APITestHelper.request(self, url, 'GET', username='******', status_code=200)
        shorten_data = shorthand_dict(response.data, exclude_keys=['id'])

        expected_results = '(description:Accessories Description,title:Accessories)'
        self.assertEqual(shorten_data, expected_results)
    def test_category_ordering(self):
        # Create new category
        url = '/api/category/'
        data = {'title': 'AAA new category', 'description': 'category description'}
        response = APITestHelper.request(self, url, 'POST', data=data, username='******', status_code=201)
        shorten_data = shorthand_dict(response.data, exclude_keys=['id'])

        expected_results = '(description:category description,title:AAA new category)'
        self.assertEqual(shorten_data, expected_results)

        # GET request
        url = '/api/category/'
        response = APITestHelper.request(self, url, 'GET', username='******', status_code=200)
        shorten_data = shorthand_dict(response.data, exclude_keys=['id'])
        expected_results = ['(description:category description,title:AAA new category)'] + self.expected_categories
        self.assertListEqual(shorten_data, expected_results)
Пример #7
0
def _create_bookmark_listing(testcase_instance,
                             username,
                             listing_id,
                             listing_title,
                             shared_folder_id=None):
    """
    Create Listing bookmark under shared_folder_bookmark

    CREATE [LISTING/FOLDER] BOOKMARK FOR USER {username} WHERE LISTING = {listing_id}
    """
    url = '/api/bookmark/'
    # TODO: How to elimate listing id from call
    data = {"type": "LISTING", "listing": {"id": listing_id}}

    if shared_folder_id:
        data['bookmark_parent'] = [{"id": shared_folder_id}]

    response = APITestHelper.request(testcase_instance,
                                     url,
                                     'POST',
                                     data=data,
                                     username=username,
                                     status_code=201)

    shorten_data = shorthand_dict(
        response.data,
        include_keys=['is_shared', 'listing', 'listing.title', 'type'])
    expected_results = "(is_shared:False,listing:(title:{}),type:LISTING)".format(
        listing_title)
    testcase_instance.assertEqual(shorten_data, expected_results)
    return response
Пример #8
0
    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='******', 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:(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)
Пример #9
0
    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='******', 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: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:9.0,weight:1.0),_sort_score:9.0),title:LocationLister)',
            '(_score:(Baseline:(raw_score:9.0,weight:1.0),_sort_score:9.0),title:Stop sign)',
            '(_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)
Пример #10
0
    def test_get_agency(self):
        url = '/api/agency/1/'
        response = APITestHelper.request(self, url, 'GET', username='******', status_code=200)
        shorten_data = shorthand_dict(response.data, exclude_keys=['id'])

        expected_results = '(short_name:Minitrue,title:Ministry of Truth)'
        self.assertEqual(shorten_data, expected_results)
Пример #11
0
    def test_create_agency_apps_mall_steward(self):
        url = '/api/agency/'
        data = {'title': 'new agency', 'short_name': 'orgname'}
        response = APITestHelper.request(self, url, 'POST', data=data, username='******', status_code=201)
        shorten_data = shorthand_dict(response.data, exclude_keys=['id'])

        self.assertEqual(shorten_data, '(short_name:orgname,title:new agency)')
Пример #12
0
    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='******', 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)
Пример #13
0
    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='******', 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)
Пример #14
0
    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='******', 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)
Пример #15
0
    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='******', 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)
Пример #16
0
    def test_recommendation_content_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_content_base')
        expected_result = {'Elasticsearch Content Filtering': {}}
        self.assertEquals(actual_result, expected_result)

        url = '/api/storefront/recommended/?randomize=False'
        response = APITestHelper.request(self, url, 'GET', username='******', 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 Content Filtering:(raw_score:8.762,weight:0.9),_sort_score:7.886),title:BeiDou Navigation Satellite System)",
            "(_score:(Elasticsearch Content Filtering:(raw_score:8.677,weight:0.9),_sort_score:7.809),title:Rogue)",
            "(_score:(Elasticsearch Content Filtering:(raw_score:8.572,weight:0.9),_sort_score:7.715),title:Wolverine)",
            "(_score:(Elasticsearch Content Filtering:(raw_score:8.544,weight:0.9),_sort_score:7.69),title:Navigation using Maps)",
            "(_score:(Elasticsearch Content Filtering:(raw_score:8.475,weight:0.9),_sort_score:7.627),title:Neptune)",
            "(_score:(Elasticsearch Content Filtering:(raw_score:8.439,weight:0.9),_sort_score:7.595),title:Komodo Dragon)",
            "(_score:(Elasticsearch Content Filtering:(raw_score:8.303,weight:0.9),_sort_score:7.473),title:Magneto)",
            "(_score:(Elasticsearch Content Filtering:(raw_score:8.283,weight:0.9),_sort_score:7.455),title:Jupiter)",
            "(_score:(Elasticsearch Content Filtering:(raw_score:8.273,weight:0.9),_sort_score:7.446),title:Uranus)",
            "(_score:(Elasticsearch Content Filtering:(raw_score:8.261,weight:0.9),_sort_score:7.435),title:Cyclops)"
        ]

        import json
        print(json.dumps(title_scores, indent=4))
        self.assertEquals(expected_result, title_scores)
Пример #17
0
    def test_recommendation_content_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_content_base')
        expected_result = {'Elasticsearch Content Filtering': {}}
        self.assertEquals(actual_result, expected_result)

        url = '/api/storefront/recommended/?randomize=False'
        response = APITestHelper.request(self, url, 'GET', username='******', 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 Content Filtering:(raw_score:8.762,weight:0.9),_sort_score:7.886),title:Wolverine)',
            '(_score:(Elasticsearch Content Filtering:(raw_score:8.315,weight:0.9),_sort_score:7.483),title:Beast)',
            '(_score:(Elasticsearch Content Filtering:(raw_score:8.268,weight:0.9),_sort_score:7.441),title:Magneto)',
            '(_score:(Elasticsearch Content Filtering:(raw_score:8.213,weight:0.9),_sort_score:7.392),title:Jupiter)',
            '(_score:(Elasticsearch Content Filtering:(raw_score:8.112,weight:0.9),_sort_score:7.301),title:Pokemon Ruby and Sapphire)',
            '(_score:(Elasticsearch Content Filtering:(raw_score:8.096,weight:0.9),_sort_score:7.286),title:Cyclops)',
            '(_score:(Elasticsearch Content Filtering:(raw_score:8.094,weight:0.9),_sort_score:7.285),title:Barsoom)',
            '(_score:(Elasticsearch Content Filtering:(raw_score:8.088,weight:0.9),_sort_score:7.279),title:Blink)',
            '(_score:(Elasticsearch Content Filtering:(raw_score:8.08,weight:0.9),_sort_score:7.272),title:Clerks)',
            '(_score:(Elasticsearch Content Filtering:(raw_score:7.999,weight:0.9),_sort_score:7.199),title:Rogue)'
        ]

        # import json; print(json.dumps(title_scores, indent=4))
        self.assertEquals(expected_result, title_scores)
Пример #18
0
def _create_bookmark_folder(testcase_instance,
                            username,
                            folder_title,
                            listing_id=None,
                            shared_folder_id=None):
    """
    Create Listing bookmark under shared_folder_bookmark

    CREATE [LISTING/FOLDER] BOOKMARK FOR USER {username} WHERE LISTING = {listing_id}
    """
    url = '/api/bookmark/'
    data = {"type": "FOLDER", "title": folder_title}

    if listing_id:
        data['listing'] = {}
        data['listing']['id'] = listing_id

    if shared_folder_id:
        data['bookmark_parent'] = [{"id": shared_folder_id}]

    response = APITestHelper.request(testcase_instance,
                                     url,
                                     'POST',
                                     data=data,
                                     username=username,
                                     status_code=201)

    shorten_data = shorthand_dict(response.data,
                                  include_keys=['is_shared', 'type', 'title'])
    expected_results = "(is_shared:False,title:{},type:FOLDER)".format(
        folder_title)
    testcase_instance.assertEqual(shorten_data, expected_results)
    return response
    def test_update_category_apps_mall_steward(self):
        url = '/api/category/1/'
        data = {'title': 'updated category', 'description': 'updated description'}
        response = APITestHelper.request(self, url, 'PUT', data=data, username='******', status_code=200)
        shorten_data = shorthand_dict(response.data, exclude_keys=['id'])

        expected_results = '(description:updated description,title:updated category)'
        self.assertEqual(shorten_data, expected_results)
Пример #20
0
 def test_get_categories_list(self):
     url = '/api/category/'
     response = APITestHelper.request(self,
                                      url,
                                      'GET',
                                      username='******',
                                      status_code=200)
     shorten_data = shorthand_dict(response.data, exclude_keys=['id'])
     self.assertListEqual(shorten_data, self.expected_categories)
Пример #21
0
    def test_get_category(self):
        url = '/api/category/1/'
        response = APITestHelper.request(self,
                                         url,
                                         'GET',
                                         username='******',
                                         status_code=200)
        shorten_data = shorthand_dict(response.data, exclude_keys=['id'])

        expected_results = '(description:Accessories Description,title:Accessories)'
        self.assertEqual(shorten_data, expected_results)
Пример #22
0
    def test_get_agency(self):
        url = '/api/agency/1/'
        response = APITestHelper.request(self,
                                         url,
                                         'GET',
                                         username='******',
                                         status_code=200)
        shorten_data = shorthand_dict(response.data, exclude_keys=['id'])

        expected_results = '(short_name:Minitrue,title:Ministry of Truth)'
        self.assertEqual(shorten_data, expected_results)
Пример #23
0
    def test_create_agency_apps_mall_steward(self):
        url = '/api/agency/'
        data = {'title': 'new agency', 'short_name': 'orgname'}
        response = APITestHelper.request(self,
                                         url,
                                         'POST',
                                         data=data,
                                         username='******',
                                         status_code=201)
        shorten_data = shorthand_dict(response.data, exclude_keys=['id'])

        self.assertEqual(shorten_data, '(short_name:orgname,title:new agency)')
Пример #24
0
 def test_shorthand_dict(self):
     input_object = {
         'title': 'app1',
         'category': [{
             'title': 'weather'
         }, {
             'title': 'utils'
         }]
     }
     expected_results = '(category:[(title:weather),(title:utils)],title:app1)'
     result = utils.shorthand_dict(input_object)
     self.assertEqual(result, expected_results)
Пример #25
0
    def test_create_category_apps_mall_steward(self):
        url = '/api/category/'
        data = {'title': 'new category', 'description': 'category description'}
        response = APITestHelper.request(self,
                                         url,
                                         'POST',
                                         data=data,
                                         username='******',
                                         status_code=201)
        shorten_data = shorthand_dict(response.data, exclude_keys=['id'])

        expected_results = '(description:category description,title:new category)'
        self.assertEqual(shorten_data, expected_results)
Пример #26
0
    def test_update_category_apps_mall_steward(self):
        url = '/api/category/1/'
        data = {
            'title': 'updated category',
            'description': 'updated description'
        }
        response = APITestHelper.request(self,
                                         url,
                                         'PUT',
                                         data=data,
                                         username='******',
                                         status_code=200)
        shorten_data = shorthand_dict(response.data,
                                      exclude_keys=['id', 'import_metadata'])

        expected_results = '(description:updated description,title:updated category)'
        self.assertEqual(shorten_data, expected_results)
Пример #27
0
    def test_get_agencies_list(self):
        url = '/api/agency/'
        response = APITestHelper.request(self, url, 'GET', username='******', status_code=200)
        shorten_data = shorthand_dict(response.data, exclude_keys=['id'])

        expected_results = [
         '(short_name:Miniluv,title:Ministry of Love)',
         '(short_name:Minipax,title:Ministry of Peace)',
         '(short_name:Miniplen,title:Ministry of Plenty)',
         '(short_name:Minitrue,title:Ministry of Truth)',
         '(short_name:Test,title:Test)',
         '(short_name:Test 1,title:Test 1)',
         '(short_name:Test2,title:Test 2)',
         '(short_name:Test 3,title:Test 3)',
         '(short_name:Test 4,title:Test 4)']

        self.assertEqual(shorten_data, expected_results)
def _create_bookmark_listing(testcase_instance, username, listing_id, listing_title, shared_folder_id=None):
    """
    Create Listing bookmark under shared_folder_bookmark

    CREATE [LISTING/FOLDER] BOOKMARK FOR USER {username} WHERE LISTING = {listing_id}
    """
    url = '/api/bookmark/'
    # TODO: How to elimate listing id from call
    data = {"type": "LISTING", "listing": {"id": listing_id}}

    if shared_folder_id:
        data['bookmark_parent'] = [{"id": shared_folder_id}]

    response = APITestHelper.request(testcase_instance, url, 'POST', data=data, username=username, status_code=201)

    shorten_data = shorthand_dict(response.data, include_keys=['is_shared', 'listing', 'listing.title', 'type'])
    expected_results = "(is_shared:False,listing:(title:{}),type:LISTING)".format(listing_title)
    testcase_instance.assertEqual(shorten_data, expected_results)
    return response
Пример #29
0
    def test_get_agencies_list(self):
        url = '/api/agency/'
        response = APITestHelper.request(self,
                                         url,
                                         'GET',
                                         username='******',
                                         status_code=200)
        shorten_data = shorthand_dict(response.data, exclude_keys=['id'])

        expected_results = [
            '(short_name:Miniluv,title:Ministry of Love)',
            '(short_name:Minipax,title:Ministry of Peace)',
            '(short_name:Miniplen,title:Ministry of Plenty)',
            '(short_name:Minitrue,title:Ministry of Truth)',
            '(short_name:Test,title:Test)', '(short_name:Test 1,title:Test 1)',
            '(short_name:Test2,title:Test 2)',
            '(short_name:Test 3,title:Test 3)',
            '(short_name:Test 4,title:Test 4)'
        ]

        self.assertEqual(shorten_data, expected_results)
def _create_bookmark_folder(testcase_instance, username, folder_title, listing_id=None, shared_folder_id=None):
    """
    Create Listing bookmark under shared_folder_bookmark

    CREATE [LISTING/FOLDER] BOOKMARK FOR USER {username} WHERE LISTING = {listing_id}
    """
    url = '/api/bookmark/'
    data = {"type": "FOLDER", "title": folder_title}

    if listing_id:
        data['listing'] = {}
        data['listing']['id'] = listing_id

    if shared_folder_id:
        data['bookmark_parent'] = [{"id": shared_folder_id}]

    response = APITestHelper.request(testcase_instance, url, 'POST', data=data, username=username, status_code=201)

    shorten_data = shorthand_dict(response.data, include_keys=['is_shared', 'type', 'title'])
    expected_results = "(is_shared:False,title:{},type:FOLDER)".format(folder_title)
    testcase_instance.assertEqual(shorten_data, expected_results)
    return response
Пример #31
0
from ozpcenter.utils import shorthand_dict




obj = {'a':'string', 'b':[{'b':'string'},{'b':[{'c':'string'},{'d':4}]}]}
print(obj)
print('==')
print("""
a=string
b[0].b=string
b[0].c=string
b[1].d=4
""")
print('==')
print(shorthand_dict(obj))
print('==')
print(shorthand_types(obj))
print('==')
print(shorthand_dict(shorthand_types(obj)))

"""
(props:(a:(type:str),b:(items:[(props:(b:(type:str)),type:dict),(props:(b:(items:[(props:(c:(type:str)),type:dict),(props:(d:(type:int)),type:dict)],len:2,type:list)),type:dict)],len:2,type:list)),type:dict)

level0


props
  a:
   type:str
  b:
 def test_get_categories_list(self):
     url = '/api/category/'
     response = APITestHelper.request(self, url, 'GET', username='******', status_code=200)
     shorten_data = shorthand_dict(response.data, exclude_keys=['id'])
     self.assertListEqual(shorten_data, self.expected_categories)
Пример #33
0
    def test_bulk_category_update_owner(self):
        # Update category listing by owner (test remove, add and validate)
        # POST url = '/api/category/{0!s}/listing/'.format(category_id)

        # Finance (id = 7)
        # Weather (id = 16)
        starting_list = [{
            "id":
            6,
            "categories": [{
                "title": "Finance"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            16,
            "categories": [{
                "title": "Finance"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            19,
            "categories": [{
                "title": "Finance"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            41,
            "categories": [{
                "title": "Finance"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            42,
            "categories": [{
                "title": "Finance"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            77,
            "categories": [{
                "title": "Finance"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            81,
            "categories": [{
                "title": "Finance"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            100,
            "categories": [{
                "title": "Finance"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            135,
            "categories": [{
                "title": "Finance"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            187,
            "categories": [{
                "title": "Finance"
            }, {
                "title": "Weather"
            }]
        }]

        # test case: remove a category - Finance (id = 7)
        data_removed = [{
            "id": 6,
            "categories": [{
                "title": "Weather"
            }]
        }, {
            "id": 16,
            "categories": [{
                "title": "Weather"
            }]
        }, {
            "id": 19,
            "categories": [{
                "title": "Weather"
            }]
        }, {
            "id": 41,
            "categories": [{
                "title": "Weather"
            }]
        }, {
            "id": 42,
            "categories": [{
                "title": "Weather"
            }]
        }, {
            "id": 77,
            "categories": [{
                "title": "Weather"
            }]
        }, {
            "id": 81,
            "categories": [{
                "title": "Weather"
            }]
        }, {
            "id": 100,
            "categories": [{
                "title": "Weather"
            }]
        }, {
            "id": 135,
            "categories": [{
                "title": "Weather"
            }]
        }, {
            "id": 187,
            "categories": [{
                "title": "Weather"
            }]
        }]

        # test case: add a category - Accessories (id = 1)
        data_added = [{
            "id":
            6,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            16,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            19,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            41,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            42,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            77,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            81,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            100,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            135,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            187,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }]

        # test case validation - Attempt to add more than three(3) categories or  Zero categories
        data_validated = [{
            "id":
            6,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "News",
            }, {
                "title": "Shopping",
            }, {
                "title": "Weather"
            }]
        }, {
            "id": 16,
            "categories": [{}]
        }, {
            "id":
            19,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            41,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            42,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            77,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            81,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            100,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            135,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Weather"
            }]
        }, {
            "id":
            187,
            "categories": [{
                "title": "Accessories"
            }, {
                "title": "Finance"
            }]
        }]

        # retrieve starting category listings for this owner
        url = '/api/category/7/listing/'
        response = APITestHelper.request(self,
                                         url,
                                         'GET',
                                         username='******',
                                         status_code=200)

        actual_data = self._transform_categories(response.data)
        self.assertListEqual(shorthand_dict(actual_data),
                             shorthand_dict(starting_list))
        # ------------------------------------------------
        #    Test case # 1: Remove categories
        # ------------------------------------------------
        url = '/api/category/7/listing/'
        response = APITestHelper.request(self,
                                         url,
                                         'POST',
                                         data=data_removed,
                                         username='******',
                                         status_code=201)

        actual_data = self._transform_categories(response.data)
        self.assertListEqual(shorthand_dict(actual_data),
                             shorthand_dict(data_removed))

        # retrieve updated category listings for this owner under Finance (id = 7)
        url = '/api/category/7/listing/'
        response = APITestHelper.request(self,
                                         url,
                                         'GET',
                                         username='******',
                                         status_code=200)

        actual_data = self._transform_categories(response.data)
        self.assertListEqual(shorthand_dict(actual_data), [])

        # retrieve updated category listings for this owner under Weather (id = 16)
        url = '/api/category/16/listing/'
        response = APITestHelper.request(self,
                                         url,
                                         'GET',
                                         username='******',
                                         status_code=200)

        actual_data = self._transform_categories(response.data)
        self.assertListEqual(shorthand_dict(actual_data),
                             shorthand_dict(data_removed))

        # ------------------------------------------------
        #    Test case # 2:  Add categories
        # ------------------------------------------------
        url = '/api/category/1/listing/'
        response = APITestHelper.request(self,
                                         url,
                                         'POST',
                                         data=data_added,
                                         username='******',
                                         status_code=201)

        # retrieve updated category listings for this owner
        response = APITestHelper.request(self,
                                         url,
                                         'GET',
                                         username='******',
                                         status_code=200)

        actual_data = self._transform_categories(response.data)
        self.assertListEqual(shorthand_dict(actual_data),
                             shorthand_dict(data_added))

        # ------------------------------------------------
        #    Test case # 3: Validate categories
        # ------------------------------------------------
        url = '/api/category/1/listing/'
        response = APITestHelper.request(self,
                                         url,
                                         'POST',
                                         data=data_validated,
                                         username='******',
                                         status_code=400)

        self.assertEquals(response.data['error'], True)
        self.assertEquals(response.data['error_code'], 'validation_error')
        self.assertEquals(
            response.data['detail'],
            "[{'non_field_errors': ['Can not add more than 3 categories for one listing']}, {'categories': [{'title': ['This field is required.']}]}, {}, {}, {}, {}, {}, {}, {}, {}]"
        )
    def test_update_listing_full(self):
        url = '/api/listing/1/'
        title = 'julias app 2'
        data = {
            "title": title,
            "description": "description of app",
            "launch_url": "http://www.google.com/launch",
            "version_name": "2.1.8",
            "unique_name": "org.apps.julia-one",
            "what_is_new": "nothing is new",
            "description_short": "a shorter description",
            "usage_requirements": "Many new things",
            "system_requirements": "Good System",
            "is_private": "true",
            "is_enabled": "false",
            "is_featured": "false",
            "feedback_score": 0,
            "contacts": [
                {"email": "*****@*****.**", "secure_phone": "111-222-3434",
                    "unsecure_phone": "444-555-4545", "name": "me",
                    "contact_type": {"name": "Government"}
                },
                {"email": "*****@*****.**", "secure_phone": "222-222-3333",
                    "unsecure_phone": "555-555-5555", "name": "you",
                    "contact_type": {"name": "Military"}
                }
            ],
            "security_marking": "SECRET",
            "listing_type": {"title": "Widget"},
            "small_icon": {"id": 1},
            "large_icon": {"id": 2},
            "banner_icon": {"id": 3},
            "large_banner_icon": {"id": 4},
            "categories": [
                {"title": "Business"},
                {"title": "Education"}
            ],
            "owners": [
                {"user": {"username": "******"}},
                {"user": {"username": "******"}}
            ],
            "tags": [
                {"name": "demo"},
                {"name": "map"}
            ],
            "intents": [
                {"action": "/application/json/view"},
                {"action": "/application/json/edit"}
            ],
            "doc_urls": [
                {"name": "wiki", "url": "http://www.google.com/wiki2"},
                {"name": "guide", "url": "http://www.google.com/guide2"}
            ],
            "screenshots": [
                {"small_image": {"id": 1}, "large_image": {"id": 2}, "description": "Test Description"},
                {"small_image": {"id": 3}, "large_image": {"id": 4}, "description": "Test Description"}
            ]

        }

        # for checking Activity status later on
        user = generic_model_access.get_profile('julia').user
        self.client.force_authenticate(user=user)
        old_listing_data = self.client.get(url, format='json').data

        response = self.client.put(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        compare_keys_data_exclude = [
            {'key': 'title', 'exclude': []},
            {'key': 'description', 'exclude': []},
            {'key': 'launch_url', 'exclude': []},
            {'key': 'version_name', 'exclude': []},
            {'key': 'unique_name', 'exclude': []},
            {'key': 'what_is_new', 'exclude': []},
            {'key': 'description_short', 'exclude': []},
            {'key': 'usage_requirements', 'exclude': []},
            {'key': 'system_requirements', 'exclude': []},
            {'key': 'security_marking', 'exclude': []},
            {'key': 'listing_type', 'exclude': []},
            {'key': 'small_icon', 'exclude': ['security_marking', 'url']},
            {'key': 'large_icon', 'exclude': ['security_marking', 'url']},
            {'key': 'banner_icon', 'exclude': ['security_marking', 'url']},
            {'key': 'large_banner_icon', 'exclude': ['security_marking', 'url']},
            {'key': 'contacts', 'exclude': ['id', 'organization']},
            {'key': 'categories', 'exclude': ['id', 'description']},
            {'key': 'tags', 'exclude': ['id']},
            {'key': 'owners', 'exclude': ['id', 'display_name', 'avatar']},
            {'key': 'intents', 'exclude': ['id', 'icon', 'label', 'media_type']},
            {'key': 'doc_urls', 'exclude': ['id']},
            {'key': 'screenshots', 'exclude': ['small_image.security_marking', 'large_image.security_marking', 'small_image.url', 'large_image.url', 'order']},
        ]

        for key_to_compare_dict in compare_keys_data_exclude:
            key_to_compare = key_to_compare_dict['key']
            key_exclude = key_to_compare_dict['exclude']

            response_key_value = shorthand_dict(response.data[key_to_compare], exclude_keys=key_exclude)
            data_expected_value = shorthand_dict(data[key_to_compare], exclude_keys=key_exclude)

            # Fix Order for Sqlite/Postgres diffrences
            if isinstance(response_key_value, list):
                response_key_value = sorted(response_key_value)

            if isinstance(data_expected_value, list):
                data_expected_value = sorted(data_expected_value)

            self.assertEqual(response_key_value, data_expected_value, 'Comparing {} key'.format(key_to_compare))

        self.assertEqual(response.data['is_private'], True)
        self.assertEqual(response.data['is_enabled'], False)
        self.assertEqual(response.data['is_featured'], False)
        self.assertEqual(response.data['approval_status'], models.Listing.APPROVED)
        self.assertEqual(response.data['avg_rate'], 3.0)
        self.assertEqual(response.data['total_votes'], 4)
        self.assertEqual(response.data['total_rate5'], 1)
        self.assertEqual(response.data['total_rate4'], 0)
        self.assertEqual(response.data['total_rate3'], 2)
        self.assertEqual(response.data['total_rate2'], 0)
        self.assertEqual(response.data['total_rate1'], 1)
        self.assertEqual(response.data['total_reviews'], 4)
        self.assertEqual(response.data['iframe_compatible'], False)
        self.assertEqual(response.data['required_listings'], None)
        self.assertTrue(response.data['edited_date'])
        self.assertTrue(response.data['approved_date'])
        self.assertEqual(validate_listing_map_keys(response.data), [])

        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        #                   verify change_details
        # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        activity_url = url + 'activity/'
        activity_response = self.client.get(activity_url, format='json')
        activity_data = activity_response.data

        fields = ['title', 'description', 'description_short', 'version_name',
            'usage_requirements', 'system_requirements', 'unique_name', 'what_is_new', 'launch_url',
            'is_enabled', 'is_featured', 'is_private', 'feedback_score', 'doc_urls', 'contacts',
            'screenshots', 'categories', 'owners', 'tags', 'small_icon',
            'large_icon', 'banner_icon', 'large_banner_icon', 'security_marking',
            'listing_type', 'approval_status', 'intents']

        changed_found_fields = []

        for activity in activity_data:
            if activity['action'] == 'MODIFIED':
                for change in activity['change_details']:
                    # Field Set 1
                    temp_change_fields = ['title', 'description', 'description_short',
                        'version_name', 'usage_requirements', 'system_requirements', 'what_is_new', 'unique_name', 'launch_url', 'feedback_score',
                        'is_private', 'is_featured', 'listing_type', 'security_marking']

                    for temp_field in temp_change_fields:
                        if change['field_name'] == temp_field:
                            if temp_field == 'listing_type':
                                self.assertEqual(change['new_value'], data[temp_field]['title'], 'new_value assertion for {}'.format(temp_field))
                            else:
                                self.assertEqual(change['new_value'], data[temp_field], 'new_value assertion for {}'.format(temp_field))

                            if temp_field.startswith('is_'):
                                self.assertEqual(change['old_value'], model_access.bool_to_string(old_listing_data[temp_field]), 'old_value assertion for {}'.format(temp_field))
                            elif temp_field == 'listing_type':
                                self.assertEqual(change['old_value'], old_listing_data[temp_field]['title'], 'old_value assertion for {}'.format(temp_field))
                            else:
                                self.assertEqual(change['old_value'], old_listing_data[temp_field], 'old_value assertion for {}'.format(temp_field))
                            changed_found_fields.append(temp_field)

                    # Field Set 2
                    temp_change_fields = ['small_icon', 'large_icon', 'banner_icon', 'large_banner_icon']
                    for temp_field in temp_change_fields:
                        if change['field_name'] == temp_field:
                            self.assertEqual(change['new_value'], str(data[temp_field]['id']) + '.UNCLASSIFIED', 'new_value assertion for {}'.format(temp_field))
                            self.assertEqual(change['old_value'], str(old_listing_data[temp_field]['id']) + '.UNCLASSIFIED', 'old_value assertion for {}'.format(temp_field))
                            changed_found_fields.append(temp_field)

                    # Field Set 3
                    temp_change_fields = ['doc_urls', 'screenshots', 'contacts', 'intents', 'categories', 'tags', 'owners']
                    for temp_field in temp_change_fields:
                        if change['field_name'] == temp_field:
                            temp_field_function = getattr(model_access, '{}_to_string'.format(temp_field))
                            self.assertEqual(change['new_value'], temp_field_function(data[temp_field]))
                            self.assertEqual(change['old_value'], temp_field_function(old_listing_data[temp_field]))
                            changed_found_fields.append(temp_field)

        difference_in_fields = sorted(list(set(fields) - set(changed_found_fields)))  # TODO: Better way to do this
        self.assertEqual(difference_in_fields, ['approval_status', 'feedback_score', 'is_enabled', 'is_featured'])
    def test_z_create_listing_full(self):
        url = '/api/listing/'
        title = 'julias app'
        data = {
            "title": title,
            "description": "description of app",
            "launch_url": "http://www.google.com/launch",
            "version_name": "1.0.0",
            "unique_name": "org.apps.julia-one",
            "what_is_new": "nothing is new",
            "description_short": "a shorter description",
            "usage_requirements": "None",
            "system_requirements": "None",
            "is_private": "true",
            "feedback_score": 0,
            "contacts": [
                {"email": "*****@*****.**", "secure_phone": "111-222-3434",
                    "unsecure_phone": "444-555-4545", "name": "me",
                    "contact_type": {"name": "Government"}
                },
                {"email": "*****@*****.**", "secure_phone": "222-222-3333",
                    "unsecure_phone": "555-555-5555", "name": "you",
                    "contact_type": {"name": "Military"}
                }
            ],
            "security_marking": "UNCLASSIFIED",
            "listing_type": {"title": "Web Application"},
            "small_icon": {"id": 1},
            "large_icon": {"id": 2},
            "banner_icon": {"id": 3},
            "large_banner_icon": {"id": 4},
            "categories": [
                {"title": "Business"},
                {"title": "Education"}
            ],
            "owners": [
                {"user": {"username": "******"}},
                {"user": {"username": "******"}}
            ],
            "tags": [
                {"name": "demo"},
                {"name": "map"}
            ],
            "intents": [
                {"action": "/application/json/view"},
                {"action": "/application/json/edit"}
            ],
            "doc_urls": [
                {"name": "wiki", "url": "http://www.google.com/wiki"},
                {"name": "guide", "url": "http://www.google.com/guide"}
            ],
            "screenshots": [
                {"small_image": {"id": 1}, "large_image": {"id": 2}},
                {"small_image": {"id": 3}, "large_image": {"id": 4}}
            ]

        }
        response = APITestHelper.request(self, url, 'POST', data=data, username='******', status_code=201)

        compare_keys_data_exclude = [
            {'key': 'title', 'exclude': []},
            {'key': 'description', 'exclude': []},
            {'key': 'launch_url', 'exclude': []},
            {'key': 'version_name', 'exclude': []},
            {'key': 'unique_name', 'exclude': []},
            {'key': 'what_is_new', 'exclude': []},
            {'key': 'description_short', 'exclude': []},
            {'key': 'usage_requirements', 'exclude': []},
            {'key': 'system_requirements', 'exclude': []},
            {'key': 'security_marking', 'exclude': []},
            {'key': 'listing_type', 'exclude': []},
            {'key': 'small_icon', 'exclude': ['security_marking', 'url']},
            {'key': 'large_icon', 'exclude': ['security_marking', 'url']},
            {'key': 'banner_icon', 'exclude': ['security_marking', 'url']},
            {'key': 'large_banner_icon', 'exclude': ['security_marking', 'url']},
            {'key': 'contacts', 'exclude': ['id', 'organization']},
            {'key': 'categories', 'exclude': ['id', 'description']},
            {'key': 'tags', 'exclude': ['id']},
            {'key': 'owners', 'exclude': ['id', 'display_name', 'avatar']},
            {'key': 'intents', 'exclude': ['id', 'icon', 'label', 'media_type']},
            {'key': 'doc_urls', 'exclude': ['id']},
            {'key': 'screenshots', 'exclude': ['small_image.security_marking', 'large_image.security_marking', 'small_image.url', 'large_image.url', 'order', 'description']},
        ]

        for key_to_compare_dict in compare_keys_data_exclude:
            key_to_compare = key_to_compare_dict['key']
            key_exclude = key_to_compare_dict['exclude']

            response_key_value = shorthand_dict(response.data[key_to_compare], exclude_keys=key_exclude)
            data_expected_value = shorthand_dict(data[key_to_compare], exclude_keys=key_exclude)

            # Fix Order for Sqlite/Postgres diffrences
            if isinstance(response_key_value, list):
                response_key_value = sorted(response_key_value)

            if isinstance(data_expected_value, list):
                data_expected_value = sorted(data_expected_value)

            self.assertEqual(response_key_value, data_expected_value, 'Comparing {} key'.format(key_to_compare))

        # fields that should come back with default values
        self.assertEqual(response.data['approved_date'], None)
        self.assertEqual(response.data['approval_status'], models.Listing.IN_PROGRESS)
        self.assertEqual(response.data['is_enabled'], True)
        self.assertEqual(response.data['is_featured'], False)
        self.assertEqual(response.data['avg_rate'], 0.0)
        self.assertEqual(response.data['total_votes'], 0)
        self.assertEqual(response.data['total_rate5'], 0)
        self.assertEqual(response.data['total_rate4'], 0)
        self.assertEqual(response.data['total_rate3'], 0)
        self.assertEqual(response.data['total_rate2'], 0)
        self.assertEqual(response.data['total_rate1'], 0)
        self.assertEqual(response.data['total_reviews'], 0)
        self.assertEqual(response.data['iframe_compatible'], True)
        self.assertEqual(response.data['required_listings'], None)
        self.assertTrue(response.data['edited_date'])
        self.assertEqual(response.data['is_bookmarked'], False)
        self.assertEqual(validate_listing_map_keys(response.data), [])
Пример #36
0
 def test_shorthand_dict(self):
     input_object = {'title': 'app1', 'category': [{'title': 'weather'}, {'title': 'utils'}]}
     expected_results = '(category:[(title:weather),(title:utils)],title:app1)'
     result = utils.shorthand_dict(input_object)
     self.assertEqual(result, expected_results)
    def test_bulk_category_update_owner(self):
        # Update category listing by owner (test remove, add and validate)
        # POST url = '/api/category/{0!s}/listing/'.format(category_id)

        # Finance (id = 7)
        # Weather (id = 16)
        starting_list = [{"id": 6, "categories": [{"title": "Finance"}, {"title": "Weather"}]},
                         {"id": 16, "categories": [{"title": "Finance"}, {"title": "Weather"}]},
                         {"id": 19, "categories": [{"title": "Finance"}, {"title": "Weather"}]},
                         {"id": 41, "categories": [{"title": "Finance"}, {"title": "Weather"}]},
                         {"id": 42, "categories": [{"title": "Finance"}, {"title": "Weather"}]},
                         {"id": 77, "categories": [{"title": "Finance"}, {"title": "Weather"}]},
                         {"id": 81, "categories": [{"title": "Finance"}, {"title": "Weather"}]},
                         {"id": 100, "categories": [{"title": "Finance"}, {"title": "Weather"}]},
                         {"id": 135, "categories": [{"title": "Finance"}, {"title": "Weather"}]},
                         {"id": 187, "categories": [{"title": "Finance"}, {"title": "Weather"}]}
                        ]

        # test case: remove a category - Finance (id = 7)
        data_removed = [{"id": 6, "categories": [{"title": "Weather"}]},
                        {"id": 16, "categories": [{"title": "Weather"}]},
                        {"id": 19, "categories": [{"title": "Weather"}]},
                        {"id": 41, "categories": [{"title": "Weather"}]},
                        {"id": 42, "categories": [{"title": "Weather"}]},
                        {"id": 77, "categories": [{"title": "Weather"}]},
                        {"id": 81, "categories": [{"title": "Weather"}]},
                        {"id": 100, "categories": [{"title": "Weather"}]},
                        {"id": 135, "categories": [{"title": "Weather"}]},
                        {"id": 187, "categories": [{"title": "Weather"}]}
                        ]

        # test case: add a category - Accessories (id = 1)
        data_added = [{"id": 6, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                      {"id": 16, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                      {"id": 19, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                      {"id": 41, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                      {"id": 42, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                      {"id": 77, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                      {"id": 81, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                      {"id": 100, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                      {"id": 135, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                      {"id": 187, "categories": [{"title": "Accessories"}, {"title": "Weather"}]}
                      ]

        # test case validation - Attempt to add more than three(3) categories or  Zero categories
        data_validated = [{"id": 6, "categories": [{"title": "Accessories"}, {"title": "News", }, {"title": "Shopping", }, {"title": "Weather"}]},
                          {"id": 16, "categories": [{}]},
                          {"id": 19, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                          {"id": 41, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                          {"id": 42, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                          {"id": 77, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                          {"id": 81, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                          {"id": 100, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                          {"id": 135, "categories": [{"title": "Accessories"}, {"title": "Weather"}]},
                          {"id": 187, "categories": [{"title": "Accessories"}, {"title": "Finance"}]}
                        ]

        # retrieve starting category listings for this owner
        url = '/api/category/7/listing/'
        response = APITestHelper.request(self, url, 'GET', username='******', status_code=200)

        actual_data = self._transform_categories(response.data)
        self.assertListEqual(shorthand_dict(actual_data), shorthand_dict(starting_list))
        # ------------------------------------------------
        #    Test case # 1: Remove categories
        # ------------------------------------------------
        url = '/api/category/7/listing/'
        response = APITestHelper.request(self, url, 'POST', data=data_removed, username='******', status_code=201)

        actual_data = self._transform_categories(response.data)
        self.assertListEqual(shorthand_dict(actual_data), shorthand_dict(data_removed))

        # retrieve updated category listings for this owner under Finance (id = 7)
        url = '/api/category/7/listing/'
        response = APITestHelper.request(self, url, 'GET', username='******', status_code=200)

        actual_data = self._transform_categories(response.data)
        self.assertListEqual(shorthand_dict(actual_data), [])

        # retrieve updated category listings for this owner under Weather (id = 16)
        url = '/api/category/16/listing/'
        response = APITestHelper.request(self, url, 'GET', username='******', status_code=200)

        actual_data = self._transform_categories(response.data)
        self.assertListEqual(shorthand_dict(actual_data), shorthand_dict(data_removed))

        # ------------------------------------------------
        #    Test case # 2:  Add categories
        # ------------------------------------------------
        url = '/api/category/1/listing/'
        response = APITestHelper.request(self, url, 'POST', data=data_added, username='******', status_code=201)

        # retrieve updated category listings for this owner
        response = APITestHelper.request(self, url, 'GET', username='******', status_code=200)

        actual_data = self._transform_categories(response.data)
        self.assertListEqual(shorthand_dict(actual_data), shorthand_dict(data_added))

        # ------------------------------------------------
        #    Test case # 3: Validate categories
        # ------------------------------------------------
        url = '/api/category/1/listing/'
        response = APITestHelper.request(self, url, 'POST', data=data_validated, username='******', status_code=400)

        self.assertEquals(response.data['error'], True)
        self.assertEquals(response.data['error_code'], 'validation_error')
        self.assertEquals(response.data['detail'], "[{'non_field_errors': ['Can not add more than 3 categories for one listing']}, {'categories': [{'title': ['This field is required.']}]}, {}, {}, {}, {}, {}, {}, {}, {}]")