Beispiel #1
0
    def test_recommendations(self):
        author = user_factory()
        recommendations = {
            101: addon_factory(id=101, guid='101@mozilla', users=[author]),
            102: addon_factory(id=102, guid='102@mozilla', users=[author]),
            103: addon_factory(id=103, guid='103@mozilla', users=[author]),
            104: addon_factory(id=104, guid='104@mozilla', users=[author]),
        }
        replacement_items = [
            DiscoItem(addon_id=101),
            DiscoItem(addon_id=102),
            DiscoItem(addon_id=103),
            DiscoItem(addon_id=104),
        ]
        self.addons.update(recommendations)
        self.get_recommendations.return_value = replacement_items

        response = self.client.get(self.url, {
            'lang': 'en-US',
            'telemetry-client-id': '666'
        })
        # should still be the same number of results.
        assert response.data['count'] == len(discopane_items)
        assert response.data['results']

        # personas aren't replaced by recommendations, so should be as before.
        new_discopane_items = replace_extensions(discopane_items,
                                                 replacement_items)
        for i, result in enumerate(response.data['results']):
            if 'theme_data' in result['addon']:
                self._check_disco_theme(result, new_discopane_items[i])
            else:
                self._check_disco_addon(result, new_discopane_items[i])
Beispiel #2
0
    def test_no_recommendations_for_china_edition(self):
        author = user_factory()
        recommendations = {
            101: addon_factory(id=101, guid='101@mozilla', users=[author]),
        }
        replacement_items = [
            DiscoItem(addon_id=101, is_recommendation=True),
        ]
        self.addons.update(recommendations)
        self.get_recommendations.return_value = replacement_items

        response = self.client.get(
            self.url, {'lang': 'en-US', 'telemetry-client-id': '666',
                       'platform': 'WINNT', 'edition': 'china'})
        self.get_recommendations.assert_not_called()

        # should be normal results
        discopane_items_china = disco_data['china']
        assert response.data['count'] == len(discopane_items_china)
        for i, result in enumerate(response.data['results']):
            assert result['is_recommendation'] is False
            if 'theme_data' in result['addon']:
                self._check_disco_theme(result, discopane_items_china[i])
            else:
                self._check_disco_addon(result, discopane_items_china[i])
Beispiel #3
0
    def test_extra_params(self):
        author = user_factory()
        recommendations = {
            101: addon_factory(id=101, guid='101@mozilla', users=[author]),
        }
        replacement_items = [
            DiscoItem(addon_id=101, is_recommendation=True),
        ]
        self.addons.update(recommendations)
        self.get_recommendations.return_value = replacement_items

        # send known taar parameters
        known_params = {
            'lang': 'en-US', 'telemetry-client-id': '666', 'platform': 'WINNT',
            'branch': 'bob', 'study': 'sally'}
        response = self.client.get(self.url, known_params)
        self.get_recommendations.assert_called_with(
            '666', {'locale': 'en-US', 'platform': 'WINNT', 'branch': 'bob',
                    'study': 'sally'})
        assert response.data['results']

        # Sense check to make sure we're testing all known params in this test
        # strip out 'edition' as providing it means no taar.
        taar_allowed_params = [p for p in amo.DISCO_API_ALLOWED_PARAMETERS
                               if p != 'edition']
        assert sorted(known_params.keys()) == sorted(taar_allowed_params)

        # Send some extra unknown parameters to be ignored.
        with_unknown_params = {
            'lang': 'en-US', 'telemetry-client-id': '666', 'platform': 'WINNT',
            'extra': 'stuff', 'this': 'too'}
        response = self.client.get(self.url, with_unknown_params)
        self.get_recommendations.assert_called_with(
            '666', {'locale': 'en-US', 'platform': 'WINNT'})
        assert response.data['results']
def test_replace_extensions():
    source = [
        DiscoItem(addon_id=101, addon_name=u'replacê me'),
        DiscoItem(addon_id=102, addon_name=u'replace me tøø'),
        DiscoItem(addon_id=103, addon_name=u'ŋot me', type=amo.ADDON_PERSONA),
        DiscoItem(addon_id=104, addon_name=u'ŋor me', type=amo.ADDON_PERSONA),
        DiscoItem(addon_id=105, addon_name=u'probably me'),
        DiscoItem(addon_id=106, addon_name=u'safê', type=amo.ADDON_PERSONA),
    ]
    # Just 2 replacements
    replacements = [
        DiscoItem(addon_id=999, addon_name=u'just for you'),
        DiscoItem(addon_id=998, addon_name=u'and this øne'),
    ]
    result = replace_extensions(source, replacements)
    assert result == [
        replacements[0],
        replacements[1],  # we only had two replacements.
        source[2],
        source[3],
        source[4],
        source[5],
    ], result

    # Add a few more so all extensions are replaced, with one spare.
    replacements.append(DiscoItem(addon_id=997, addon_name='extra one'))
    replacements.append(DiscoItem(addon_id=997, addon_name='extra too'))
    result = replace_extensions(source, replacements)
    assert result == [
        replacements[0],
        replacements[1],
        source[2],  # Not an extension, so not replaced.
        source[3],  # Not an extension, so not replaced.
        replacements[2],
        source[5],  # Not an extension, so not replaced.
    ], result