Ejemplo n.º 1
0
    def _all_listing_for_app_profile_from_multi_org_profile(self):
        """
        Testing GET /api/profile/4/listing/ endpoint

        Getting
            wsmith (minitrue, stewarded_orgs: minitrue) - Winston Smith - 4
        From
            bigbrother (minipax) - Big Brother - 1
        """
        url = self._get_profile_url_for_username('wsmith', 'listing/')
        response = unittest_request_helper(self,
                                           url,
                                           'GET',
                                           username='******',
                                           status_code=200)

        titles = sorted([i['title'] for i in response.data])
        expected_listing = [
            'Air Mail', 'Applied Ethics Inc.', 'Bleach',
            'Business Insurance Risk', 'Business Management System',
            'Chart Course', 'Clipboard', 'Desktop Virtualization', 'Diamond',
            'FrameIt', 'Hatch Latch', 'Intelligence Unleashed', 'JotSpot',
            'LocationAnalyzer', 'LocationLister', 'LocationViewer',
            'Project Management', 'Ruby', 'Ruby Miner', 'Sapphire', 'Wikipedia'
        ]
        self.assertEquals(expected_listing, titles)
Ejemplo n.º 2
0
    def test_delete_review(self):
        # test_delete_review
        user = generic_model_access.get_profile('wsmith').user
        self.client.force_authenticate(user=user)
        air_mail_id = models.Listing.objects.get(title='Air Mail').id
        url = '/api/listing/{0!s}/review/'.format(air_mail_id)
        data = {'rate': 4, 'text': 'winston test review'}
        response = self.client.post(url, data, format='json')
        review_id = response.data['id']
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        # trying to delete it as a different user should fail...
        url = '/api/listing/{0!s}/review/{1!s}/'.format(air_mail_id, review_id)
        user = generic_model_access.get_profile('jones').user
        self.client.force_authenticate(user=user)
        response = self.client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        # ... unless that user is an org steward or apps mall steward
        user = generic_model_access.get_profile('julia').user
        self.client.force_authenticate(user=user)
        response = self.client.delete(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        # Check listing history
        url = '/api/listing/{0!s}/'.format(air_mail_id)
        response = unittest_request_helper(self, url, 'GET', username='******', status_code=200)
        data = response.data

        self.assertEquals(validate_listing_map_keys(data), [])
        self.assertEquals(data['last_activity']['author']['user']['username'], 'julia')
        self.assertEquals(data['last_activity']['action'], 'REVIEW_DELETED')
        self.assertEquals(data['last_activity']['listing']['id'], air_mail_id)
Ejemplo n.º 3
0
 def _one_listing_for_self_profile(self):
     url = '/api/profile/self/listing/2/'  # 2/7/18/26/27
     response = unittest_request_helper(self,
                                        url,
                                        'GET',
                                        username='******',
                                        status_code=200)
     data = response.data
     self.assertEquals(data['id'], 2)
Ejemplo n.º 4
0
    def test_get_single_review(self):
        air_mail_id = models.Listing.objects.get(title='Air Mail').id
        url = '/api/listing/{0!s}/review/4/'.format(air_mail_id)  # 4/5/6/7
        response = unittest_request_helper(self, url, 'GET', username='******', status_code=200)

        self.assertTrue('rate' in response.data)
        self.assertTrue('text' in response.data)
        self.assertTrue('author' in response.data)
        self.assertTrue('listing' in response.data)
Ejemplo n.º 5
0
    def test_essearch_filter_tag(self):
        if self.es_failed:
            self.skipTest('Elasticsearch is not currently up: {}'.format(self.error_string))

        url = '/api/listings/essearch/?tag=demo_tag'
        response = unittest_request_helper(self, url, 'GET', username='******', status_code=200)

        titles = sorted([i['title'] for i in response.data['results']])
        listings_from_file = ListingFile.filter_listings(is_enabled=True,
                                        approval_status='APPROVED',
                                        tags__in=['demo_tag'])
        sorted_listings_from_file = sorted([listing['title'] for listing in listings_from_file])

        self.assertEqual(titles, sorted_listings_from_file)
Ejemplo n.º 6
0
    def test_essearch_tags(self):
        if self.es_failed:
            self.skipTest('Elasticsearch is not currently up: {}'.format(self.error_string))

        url = '/api/listings/essearch/?search=demo_tag'
        response = unittest_request_helper(self, url, 'GET', username='******', status_code=200)

        titles = sorted([i['title'] for i in response.data['results']])
        expected_listing = ['Air Mail', 'Bread Basket', 'Chart Course', 'Chatter Box', 'Clipboard',
            'Deadpool', 'Desktop Virtualization', 'Diamond', 'Dinosaur', 'Dragons', 'FrameIt',
            'Harley-Davidson CVO', 'Hatch Latch', 'JotSpot', 'LocationAnalyzer', 'LocationLister',
            'LocationViewer', 'Mini Dachshund', 'Monkey Finder', 'Personal Computer', 'Ruby on Rails',
            'Skybox', 'Smart Phone', 'Taxonomy Classifier']

        self.assertEqual(titles, expected_listing)
Ejemplo n.º 7
0
    def test_username_starts_with_no_results(self, mock_request):
        """
        Testing GET /api/profile/?username_starts_with={username} endpoint
        """
        settings.OZP['USE_AUTH_SERVER'] = True

        url = '/api/profile/?username_starts_with=asdf'
        response = unittest_request_helper(self,
                                           url,
                                           'GET',
                                           username='******',
                                           status_code=200)
        usernames = sorted([i['user']['username'] for i in response.data])
        expected_usernames = []
        self.assertEqual(usernames, expected_usernames)
Ejemplo n.º 8
0
    def test_essearch_categories_multiple_with_space(self):
        """
        test_essearch_categories_multiple_with_space
        TODO: TEST listing_title = Newspaper when is_private = True
        """
        if self.es_failed:
            self.skipTest('Elasticsearch is not currently up: {}'.format(self.error_string))
        url = '/api/listings/essearch/?category=Health and Fitness&category=Communication'
        response = unittest_request_helper(self, url, 'GET', username='******', status_code=200)

        titles = sorted([i['title'] for i in response.data['results']])
        listings_from_file = ListingFile.filter_listings(is_enabled=True,
                                        approval_status='APPROVED',
                                        categories__in=['Health and Fitness', 'Communication'])
        sorted_listings_from_file = sorted([listing['title'] for listing in listings_from_file])

        self.assertEqual(titles, sorted_listings_from_file)
Ejemplo n.º 9
0
    def test_essearch_filter_type(self):
        """
        test_essearch_filter_type
        TODO: Iterate through all Listings types in listings_types.yaml file, Deal with Private apps
        """
        if self.es_failed:
            self.skipTest('Elasticsearch is not currently up: {}'.format(self.error_string))

        url = '/api/listings/essearch/?type=Web Application'
        response = unittest_request_helper(self, url, 'GET', username='******', status_code=200)

        titles = sorted([i['title'] for i in response.data['results']])
        listings_from_file = ListingFile.filter_listings(is_enabled=True,
                                        approval_status='APPROVED',
                                        listing_type='Web Application')
        sorted_listings_from_file = sorted([listing['title'] for listing in listings_from_file])
        self.assertEqual(titles, sorted_listings_from_file)
Ejemplo n.º 10
0
 def _all_listing_for_self_profile(self):
     url = '/api/profile/self/listing/'  # 2/7/18/26/27
     response = unittest_request_helper(self,
                                        url,
                                        'GET',
                                        username='******',
                                        status_code=200)
     titles = sorted([i['title'] for i in response.data])
     expected_listing = [
         'Air Mail', 'Applied Ethics Inc.', 'Bleach',
         'Business Insurance Risk', 'Business Management System',
         'Chart Course', 'Clipboard', 'Desktop Virtualization', 'Diamond',
         'FrameIt', 'Hatch Latch', 'Intelligence Unleashed', 'JotSpot',
         'LocationAnalyzer', 'LocationLister', 'LocationViewer',
         'Project Management', 'Ruby', 'Ruby Miner', 'Sapphire', 'Wikipedia'
     ]
     self.assertEquals(expected_listing, titles)
Ejemplo n.º 11
0
    def test_search_categories_single_with_space(self):
        search_category = 'Health and Fitness'
        url = '/api/listings/search/?category={}'.format(search_category)
        response = unittest_request_helper(self,
                                           url,
                                           'GET',
                                           username='******',
                                           status_code=200)

        titles = sorted([i['title'] for i in response.data])
        listings_from_file = ListingFile.filter_listings(
            is_enabled=True,
            approval_status='APPROVED',
            categories__in=['Health and Fitness'])
        sorted_listings_from_file = sorted(
            [listing['title'] for listing in listings_from_file])
        # TODO: TEST listing_title = Newspaper when is_private = True
        self.assertEqual(titles, sorted_listings_from_file)

        for listing_map in response.data:
            self.assertEquals(validate_listing_map_keys(listing_map), [])
Ejemplo n.º 12
0
    def _all_listing_for_minitrue_profile_from_minitrue_profile(self):
        """
        test_all_listing_for_minitrue_profile_from_minitrue_profile

        Getting
            julia (minitrue, stewarded_orgs: minitrue, miniluv) - Julia Dixon - 5
        From
            jones (minitrue) - Jones - 9
        """
        url = self._get_profile_url_for_username('julia', 'listing/')
        response = unittest_request_helper(self,
                                           url,
                                           'GET',
                                           username='******',
                                           status_code=200)

        titles = sorted([i['title'] for i in response.data])
        expected_listing = ['Chatter Box']
        # BreadBasket(Minitrue, private, julia)
        # ChatterBox(Miniluv, public, julia)
        # TODO: Figure out why BreadBasket is not in the list
        self.assertEquals(expected_listing, titles)
    def test_listing_activities(self):
        action_log = []
        # CREATED
        url = '/api/listing/'

        data = {'title': 'mr jones app', 'security_marking': 'UNCLASSIFIED'}

        response = unittest_request_helper(self,
                                           url,
                                           'POST',
                                           data=data,
                                           username='******',
                                           status_code=201)
        app_id = response.data['id']
        data = response.data

        # VERIFY that is was created
        url = '/api/listing/{0!s}/activity/'.format(app_id)
        response = unittest_request_helper(self,
                                           url,
                                           'GET',
                                           username='******',
                                           status_code=200)

        activity_actions = [i['action'] for i in response.data]
        self.assertEqual(len(activity_actions), 1)
        action_log.insert(0, models.ListingActivity.CREATED)
        self.assertEqual(activity_actions, action_log)
        activity_agency = [i['listing']['agency'] for i in response.data]
        self.assertEquals(
            json.dumps(activity_agency[0]),
            '{"title": "Ministry of Truth", "short_name": "Minitrue"}')

        # MODIFIED
        data['title'] = "mr jones mod app"
        url = '/api/listing/{0!s}/'.format(app_id)
        response = unittest_request_helper(self,
                                           url,
                                           'PUT',
                                           data=data,
                                           username='******',
                                           status_code=200)
        data = response.data

        # VERIFY that is was modified
        url = '/api/listing/{0!s}/activity/'.format(app_id)
        response = unittest_request_helper(self,
                                           url,
                                           'GET',
                                           username='******',
                                           status_code=200)

        activity_actions = [i['action'] for i in response.data]
        self.assertEqual(len(activity_actions), 2)
        action_log.insert(0, models.ListingActivity.MODIFIED)
        self.assertEqual(activity_actions, action_log)
        activity_agency = [i['listing']['agency'] for i in response.data]
        self.assertEquals(
            json.dumps(activity_agency[0]),
            '{"title": "Ministry of Truth", "short_name": "Minitrue"}')

        # SUBMITTED
        data['approval_status'] = models.Listing.PENDING
        url = '/api/listing/{0!s}/'.format(app_id)
        response = unittest_request_helper(self,
                                           url,
                                           'PUT',
                                           data=data,
                                           username='******',
                                           status_code=200)

        # Verify that is was submitted
        url = '/api/listing/{0!s}/activity/'.format(app_id)
        response = unittest_request_helper(self,
                                           url,
                                           'GET',
                                           username='******',
                                           status_code=200)

        activity_actions = [i['action'] for i in response.data]
        self.assertEquals(len(activity_actions), 3)
        action_log.insert(0, models.ListingActivity.SUBMITTED)
        self.assertEqual(activity_actions, action_log)
        self.assertTrue(models.ListingActivity.SUBMITTED in activity_actions)
        activity_agency = [i['listing']['agency'] for i in response.data]
        self.assertEquals(
            json.dumps(activity_agency[0]),
            '{"title": "Ministry of Truth", "short_name": "Minitrue"}')

        # APPROVED_ORG

        # APPROVED

        # DISABLE
        data['is_enabled'] = False
        url = '/api/listing/{0!s}/'.format(app_id)
        response = unittest_request_helper(self,
                                           url,
                                           'PUT',
                                           data=data,
                                           username='******',
                                           status_code=200)

        # Verify that it was disabled
        url = '/api/listing/{0!s}/activity/'.format(app_id)
        response = unittest_request_helper(self,
                                           url,
                                           'GET',
                                           username='******',
                                           status_code=200)
        activity_actions = [i['action'] for i in response.data]
        self.assertEquals(len(activity_actions), 4)
        action_log.insert(0, models.ListingActivity.DISABLED)
        self.assertEqual(activity_actions, action_log)
        activity_agency = [i['listing']['agency'] for i in response.data]
        self.assertEquals(
            json.dumps(activity_agency[0]),
            '{"title": "Ministry of Truth", "short_name": "Minitrue"}')

        # ENABLED
        data['is_enabled'] = True
        url = '/api/listing/{0!s}/'.format(app_id)
        response = unittest_request_helper(self,
                                           url,
                                           'PUT',
                                           data=data,
                                           username='******',
                                           status_code=200)

        # Verify that it was enabled
        url = '/api/listing/{0!s}/activity/'.format(app_id)
        response = unittest_request_helper(self,
                                           url,
                                           'GET',
                                           username='******',
                                           status_code=200)
        activity_actions = [i['action'] for i in response.data]
        self.assertEquals(len(activity_actions), 5)
        action_log.insert(0, models.ListingActivity.ENABLED)
        self.assertEqual(activity_actions, action_log)
        activity_agency = [i['listing']['agency'] for i in response.data]
        self.assertEquals(
            json.dumps(activity_agency[0]),
            '{"title": "Ministry of Truth", "short_name": "Minitrue"}')
Ejemplo n.º 14
0
    def test_essearch_is_enable(self):
        if self.es_failed:
            self.skipTest('Elasticsearch is not currently up: {}'.format(self.error_string))

        url = '/api/listings/essearch/?search=demo_tag&type=Web Application'
        response = unittest_request_helper(self, url, 'GET', username='******', status_code=200)

        titles_ids = [[record.get('title'), record.get('id')] for record in response.data['results']]
        titles = sorted([i[0] for i in titles_ids])
        expected_titles = ['Air Mail', 'Bread Basket', 'Chart Course', 'Chatter Box', 'Clipboard',
            'FrameIt', 'Hatch Latch', 'JotSpot', 'LocationAnalyzer', 'LocationLister',
            'LocationViewer', 'Monkey Finder', 'Skybox', 'Smart Phone', 'Taxonomy Classifier']

        self.assertEqual(titles, expected_titles)

        # Disable one app
        url = '/api/listing/{}/'.format(titles_ids[0][1])
        title = '{}_disabled'.format(titles_ids[0][0])

        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",
            "requirements": "None",
            "is_private": "true",
            "is_enable": "false",
            "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}, "description": "Test Description"},
                {"small_image": {"id": 3}, "large_image": {"id": 4}, "description": "Test Description"}
                ]

            }
        response = unittest_request_helper(self, url, 'PUT', data=data, username='******', status_code=200)

        elasticsearch_factory.wait_for_yellow_cluster_heath()

        # Check
        user = generic_model_access.get_profile('wsmith').user
        self.client.force_authenticate(user=user)
        url = '/api/listings/essearch/?search=demo_tag&type=Web Application'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        titles_ids = [[record.get('title'), record.get('id')] for record in response.data['results']]
        titles = sorted([i[0] for i in titles_ids])

        expected_titles = ['Bread Basket', 'Chart Course', 'Chatter Box', 'Clipboard',
            'FrameIt', 'Hatch Latch', 'JotSpot', 'LocationAnalyzer', 'LocationLister',
            'LocationViewer', 'Monkey Finder', 'Skybox', 'Smart Phone', 'Taxonomy Classifier']

        self.assertEqual(titles, expected_titles)
Ejemplo n.º 15
0
 def test_get_reviews(self):
     air_mail_id = models.Listing.objects.get(title='Air Mail').id
     url = '/api/listing/{0!s}/review/'.format(air_mail_id)
     response = unittest_request_helper(self, url, 'GET', username='******', status_code=200)
     self.assertEqual(4, len(response.data))