Ejemplo n.º 1
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.º 2
0
    def test_search_agency(self):
        user = generic_model_access.get_profile('wsmith').user
        self.client.force_authenticate(user=user)
        url = '/api/listings/search/?agency=Minipax&agency=Miniluv'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        titles = [i['title'] for i in response.data]
        self.assertTrue('Chatter Box' in titles)
        for listing_map in response.data:
            self.assertEquals(validate_listing_map_keys(listing_map), [])
    def test_self_deleted_listing(self):
        user = generic_model_access.get_profile('wsmith').user
        self.client.force_authenticate(user=user)
        url = '/api/self/listing/'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        titles = [i['id'] for i in response.data]
        self.assertTrue('1' not in titles)
        for listing_map in response.data:
            self.assertEquals(validate_listing_map_keys(listing_map), [])
Ejemplo n.º 4
0
    def test_search_tags_startwith(self):
        user = generic_model_access.get_profile('wsmith').user
        self.client.force_authenticate(user=user)
        url = '/api/listings/search/?search=tag_'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        titles = [i['title'] for i in response.data]
        self.assertTrue('Air Mail' in titles)
        self.assertTrue(len(titles) == 1)
        for listing_map in response.data:
            self.assertEquals(validate_listing_map_keys(listing_map), [])
Ejemplo n.º 5
0
    def test_search_offset_limit(self):
        user = generic_model_access.get_profile('wsmith').user
        self.client.force_authenticate(user=user)
        url = '/api/listings/search/?offset=1&limit=1'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        titles = [i['title'] for i in response.data['results']]
        # TODO: Not predictable, This will change every time listing.yaml changes
        self.assertTrue('Map of the world' in titles)
        self.assertEqual(len(titles), 1)
        for listing_map in response.data['results']:
            self.assertEquals(validate_listing_map_keys(listing_map), [])
    def test_self_listing(self):
        user = generic_model_access.get_profile('julia').user
        self.client.force_authenticate(user=user)
        url = '/api/self/listing/'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        titles = [i['title'] for i in response.data]
        self.assertTrue('Bread Basket' in titles)
        self.assertTrue('Chatter Box' in titles)
        self.assertTrue('Air Mail' not in titles)
        for listing_map in response.data:
            self.assertEquals(validate_listing_map_keys(listing_map), [])
Ejemplo n.º 7
0
    def test_search_text_partial(self):
        user = generic_model_access.get_profile('wsmith').user
        self.client.force_authenticate(user=user)
        url = '/api/listings/search/?search=air ma'

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

        titles = [i['title'] for i in response.data]
        excepted_titles = ['Air Mail']
        #  TODO: Figure out why 'air ma' returns
        # ['Sun',  'Barbecue',  'Wolf Finder',  'LIT RANCH',  'Navigation using Maps',
        #                     'Air Mail',  'Rogue',  'Cheese and Crackers',
        #                     'Double Heroides',  'KIAA0319',  'Karta GPS',  'Sir Baboon McGood']
        self.assertEqual(titles, excepted_titles)
        for listing_map in response.data:
            self.assertEquals(validate_listing_map_keys(listing_map), [])
Ejemplo n.º 8
0
    def test_search_tags(self):
        user = generic_model_access.get_profile('wsmith').user
        self.client.force_authenticate(user=user)
        url = '/api/listings/search/?search=demo_tag'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        titles = sorted([i['title'] for i in response.data])
        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])
        print(titles)
        print(sorted_listings_from_file)
        self.assertEqual(titles, sorted_listings_from_file)

        for listing_map in response.data:
            self.assertEquals(validate_listing_map_keys(listing_map), [])
Ejemplo n.º 9
0
    def test_search_categories_multiple_with_space(self):
        user = generic_model_access.get_profile('wsmith').user
        self.client.force_authenticate(user=user)
        url = '/api/listings/search/?category=Health and Fitness&category=Communication'
        response = self.client.get(url, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        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', 'Communication'])
        sorted_listings_from_file = sorted(
            [listing['title'] for listing in listings_from_file])

        self.assertEqual(titles, sorted_listings_from_file)
        # TODO: TEST listing_title = Newspaper when is_private = True
        for listing_map in response.data:
            self.assertEquals(validate_listing_map_keys(listing_map), [])
Ejemplo n.º 10
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.º 11
0
    def test_search_is_enable(self):
        user = generic_model_access.get_profile('wsmith').user
        self.client.force_authenticate(user=user)
        url = '/api/listings/search/?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]
        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'
        ]

        self.assertEqual(titles, expected_titles)

        for listing_map in response.data:
            self.assertEquals(validate_listing_map_keys(listing_map), [])

        # Disable one app
        user = generic_model_access.get_profile('bigbrother').user
        self.client.force_authenticate(user=user)

        url = '/api/listing/{}/'.format(titles_ids[0][1])
        title = 'JotSpot_disabled'

        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 = self.client.put(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        # Check
        user = generic_model_access.get_profile('wsmith').user
        self.client.force_authenticate(user=user)
        url = '/api/listings/search/?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]
        titles = sorted([i[0] for i in titles_ids])

        expected_titles = [
            'Air Mail', 'Bread Basket', 'Chart Course', 'Chatter Box',
            'Clipboard', 'FrameIt', 'Hatch Latch', 'LocationAnalyzer',
            'LocationLister', 'LocationViewer', 'Monkey Finder', 'Skybox'
        ]

        self.assertEqual(titles, expected_titles)
        for listing_map in response.data:
            self.assertEquals(validate_listing_map_keys(listing_map), [])