Пример #1
0
    def test_item_popularity_num_comments(self):

        response = self.client.post(self.cultural_heritage_item_url,
                                    {'title': 'Lee Sin'},
                                    format='json')
        self.assertEqual(response.status_code, 201)
        response_content = json.loads(smart_text(response.content))
        id = response_content['id']

        item = Cultural_Heritage.objects.all()[0]
        self.assertEqual(popularity_score(item), 0)

        num_comments = 6
        for i in range(num_comments):
            response = self.client.post(
                self.cultural_heritage_item_url + str(id) + '/comment',
                {'comment': {
                    'text': 'Comment {}'.format(i)
                }},
                format='json')
            self.assertEqual(response.status_code, 201)

        item = Cultural_Heritage.objects.all()[0]
        expected_popularity = log(1 + num_comments * COEFF_NUM_COMMENTS)
        self.assertAlmostEqual(popularity_score(item), expected_popularity)
Пример #2
0
    def test_item_popularity_num_favorites(self):
        response = self.client.post(self.cultural_heritage_item_url,
                                    {'title': 'Lee Sin'},
                                    format='json')
        self.assertEqual(response.status_code, 201)
        response_content = json.loads(smart_text(response.content))

        response = self.client.post(
            '/user/cultural_heritage_item/' + str(response_content['id']) +
            '/favorite/',
            format='json',
        )
        self.assertEqual(response.status_code, 201)

        item = Cultural_Heritage.objects.all()[0]
        expected_popularity = log(1 + COEFF_NUM_FAVORITES)
        self.assertAlmostEqual(popularity_score(item), expected_popularity)

        response = self.client.delete(
            '/user/cultural_heritage_item/' + str(response_content['id']) +
            '/favorite/',
            format='json',
        )
        self.assertEqual(response.status_code, 204)

        item = Cultural_Heritage.objects.all()[0]
        self.assertEqual(popularity_score(item), 0)
Пример #3
0
    def test_item_popularity_visit_time(self):
        response = self.client.post(self.cultural_heritage_item_url,
                                    {'title': 'Lee Sin'},
                                    format='json')
        self.assertEqual(response.status_code, 201)
        response_content = json.loads(smart_text(response.content))

        item = Cultural_Heritage.objects.all()[0]
        self.assertEqual(popularity_score(item), 0)

        visit_time = 10
        response = self.client.put(
            self.item_visit_url, {
                'cultural_heritage_item': response_content['id'],
                'duration': visit_time
            },
            format='json')
        self.assertEqual(response.status_code, 200)
        item = Cultural_Heritage.objects.all()[0]

        expected_popularity = log(1 + visit_time * COEFF_VIEW_SEC)
        self.assertAlmostEqual(popularity_score(item), expected_popularity)
Пример #4
0
    def test_item_popularity_too_short_description(self):
        too_short_description = 'This is a Turkish coffee.'
        response = self.client.post(self.cultural_heritage_item_url, {
            'title': 'Turkish Coffee',
            'description': too_short_description
        },
                                    format='json')
        self.assertEqual(response.status_code, 201)
        response_content = json.loads(smart_text(response.content))
        id = response_content['id']

        item = Cultural_Heritage.objects.filter(id=id)[0]
        self.assertEqual(popularity_score(item), 0)
Пример #5
0
    def test_item_popularity_complete_location(self):
        item_data = {
            'title': 'Lee Sin',
            'latitude': '37.460044',
            'longitude': '48.247236'
        }
        response = self.client.post(self.cultural_heritage_item_url,
                                    item_data,
                                    format='json')
        self.assertEqual(response.status_code, 201)
        response_content = json.loads(smart_text(response.content))
        id = response_content['id']

        item = Cultural_Heritage.objects.filter(id=id)[0]
        self.assertEqual(popularity_score(item), COEFF_COMPLETENESS)
Пример #6
0
    def test_item_popularity_too_few_images(self):
        item_data = {'title': 'Lee Sin'}
        item_data['images'] = []
        for i in range(COMPLETE_IMG_NUM - 1):
            item_data['tags'].append({'url': 'url {}'.format(i)})

        response = self.client.post(self.cultural_heritage_item_url,
                                    item_data,
                                    format='json')
        self.assertEqual(response.status_code, 201)
        response_content = json.loads(smart_text(response.content))
        id = response_content['id']

        item = Cultural_Heritage.objects.filter(id=id)[0]
        self.assertEqual(popularity_score(item), 0)
Пример #7
0
    def test_item_popularity_long_description(self):
        long_description = '''
Sadistic and cunning, Thresh is an ambitious and restless spirit of the Shadow
Isles. Once the custodian of countless arcane secrets, he sought a power
greater than life or death, and now sustains himself by tormenting and breaking
others with slow, excruciating inventiveness. His victims suffer far beyond their
brief mortal coil as Thresh wreaks agony upon their souls, imprisoning them in
his unholy lantern to torture for all eternity.
'''
        response = self.client.post(self.cultural_heritage_item_url, {
            'title': 'Thresh',
            'description': long_description
        },
                                    format='json')
        self.assertEqual(response.status_code, 201)
        response_content = json.loads(smart_text(response.content))
        id = response_content['id']

        item = Cultural_Heritage.objects.filter(id=id)[0]
        self.assertAlmostEqual(popularity_score(item), COEFF_COMPLETENESS)