def test_sort_order(self): # sortorder--not db row order--sets the order of the # suggestions. rules = [ TriggerRuleFactory( sortorder=10, locales=['en-US'], slug='a', is_enabled=True ), TriggerRuleFactory( sortorder=1, locales=['en-US'], slug='b', is_enabled=True ), ] resp = self.post_feedback( locale='en-US', data={'happy': 0, 'description': u'rc4 is awesome'} ) links = resp.jinja_context['suggestions'] # The disabled one won't match, but the other two will match in the # sort order. assert len(links) == 2 assert ( links[0].url == build_redirect_url(format_redirect(rules[1].slug)) ) assert ( links[1].url == build_redirect_url(format_redirect(rules[0].slug)) )
def test_sort_order(self): # sortorder--not db row order--sets the order of the # suggestions. rules = [ TriggerRuleFactory( sortorder=10, locales=['en-US'], slug='a', is_enabled=True ), TriggerRuleFactory( sortorder=1, locales=['en-US'], slug='b', is_enabled=True ), ] resp = self.post_feedback( locale='en-US', data={'happy': 0, 'description': u'rc4 is awesome'} ) links = resp.context['suggestions'] # The disabled one won't match, but the other two will match in the # sort order. assert len(links) == 2 assert ( links[0].url == build_redirect_url(format_redirect(rules[1].slug)) ) assert ( links[1].url == build_redirect_url(format_redirect(rules[0].slug)) )
def test_with_multiple_rules(self): rules = [ TriggerRuleFactory( sortorder=0, locales=['en-US'], slug='a', is_enabled=False ), TriggerRuleFactory( sortorder=1, locales=['en-US'], slug='b', is_enabled=True ), TriggerRuleFactory( sortorder=2, locales=['en-US'], slug='c', is_enabled=True ), ] resp = self.post_feedback( locale='en-US', data={'happy': 0, 'description': u'rc4 is awesome'} ) links = resp.jinja_context['suggestions'] # The disabled one won't match, but the other two will match in the # sort order. assert len(links) == 2 assert ( links[0].url == build_redirect_url(format_redirect(rules[1].slug)) ) assert ( links[1].url == build_redirect_url(format_redirect(rules[2].slug)) )
def get_suggestions(self, feedback, request=None): # Note: This implementation assumes there aren't a fajillion # active rules. If that becomes a problem, we should # re-architect the db so that this is easier to implement. # # Further, each matching rule will kick off a GA event # request. We have to do those synchronously so that we're # guaranteed to have the "suggest" event before the "click" # event. Otherwise the data is not as meaningful. rules = TriggerRule.objects.all_enabled() links = [] # Go through the rules and accrue links until we're done. # FIXME: Can we do one ga_track_event call for all the rules? for rule in rules: if rule.get_matcher().match(feedback): links.append( Link(provider=PROVIDER, provider_version=PROVIDER_VERSION, cssclass=u'document', summary=rule.title, description=rule.description, url=build_redirect_url(format_redirect(rule.slug)))) # Track category: trigger-slug, action: suggest ga_track_event({ 'cid': str(feedback.id), 'ec': build_ga_category(rule), 'ea': 'suggest', 'el': rule.url }) return links
def docs_to_links(self, docs): """Converts docs from SUMO Suggest API to links and adds AAQ link""" links = [ Link(provider=PROVIDER, provider_version=PROVIDER_VERSION, cssclass=u'document', summary=doc['summary'], description=doc['description'], url=build_redirect_url(format_redirect(i))) for i, doc in enumerate(docs) ] links.append( Link(provider=PROVIDER, provider_version=PROVIDER_VERSION, cssclass=u'support', summary=_(u'Ask a question in our support forum'), description='', url=build_redirect_url(format_redirect('aaq')))) return links
def test_redirector(self): tr = TriggerRuleFactory(url=u'http://example.com/', is_enabled=True) resp = self.post_feedback( locale='en-US', data={'happy': 0, 'description': u'rc4 is awesome'} ) links = resp.context['suggestions'] assert len(links) == 1 assert links[0].url == build_redirect_url(format_redirect(tr.slug)) resp = self.client.get(links[0].url) assert resp.status_code == 302 assert resp.url == 'http://example.com/'
def test_enabled_rule_matches_and_returns_correct_data(self): tr = TriggerRuleFactory(locales=['en-US'], is_enabled=True) resp = self.post_feedback( locale='en-US', data={'happy': 0, 'description': u'rc4 is awesome'} ) links = resp.context['suggestions'] assert len(links) == 1 assert links[0].provider == PROVIDER assert links[0].provider_version == PROVIDER_VERSION assert links[0].summary == tr.title assert links[0].description == tr.description assert links[0].url == build_redirect_url(format_redirect(tr.slug))
def test_redirector(self): tr = TriggerRuleFactory(url=u'http://example.com/', is_enabled=True) resp = self.post_feedback( locale='en-US', data={'happy': 0, 'description': u'rc4 is awesome'} ) links = resp.jinja_context['suggestions'] assert len(links) == 1 assert links[0].url == build_redirect_url(format_redirect(tr.slug)) resp = self.client.get(links[0].url) assert resp.status_code == 302 assert resp.url == 'http://example.com/'
def test_enabled_rule_matches_and_returns_correct_data(self): tr = TriggerRuleFactory(locales=['en-US'], is_enabled=True) resp = self.post_feedback( locale='en-US', data={'happy': 0, 'description': u'rc4 is awesome'} ) links = resp.jinja_context['suggestions'] assert len(links) == 1 assert links[0].provider == PROVIDER assert links[0].provider_version == PROVIDER_VERSION assert links[0].summary == tr.title assert links[0].description == tr.description assert links[0].url == build_redirect_url(format_redirect(tr.slug))
def docs_to_links(self, docs): """Converts docs from SUMO Suggest API to links and adds AAQ link""" links = [ Link( provider=PROVIDER, provider_version=PROVIDER_VERSION, cssclass=u'document', summary=doc['summary'], description=doc['description'], url=build_redirect_url(format_redirect(i)) ) for i, doc in enumerate(docs) ] links.append( Link( provider=PROVIDER, provider_version=PROVIDER_VERSION, cssclass=u'support', summary=_(u'Ask a question in our support forum'), description='', url=build_redirect_url(format_redirect('aaq')) ) ) return links
def get_suggestions(self, feedback, request=None): # Note: This implementation assumes there aren't a fajillion # active rules. If that becomes a problem, we should # re-architect the db so that this is easier to implement. # # Further, each matching rule will kick off a GA event # request. We have to do those synchronously so that we're # guaranteed to have the "suggest" event before the "click" # event. Otherwise the data is not as meaningful. rules = TriggerRule.objects.all_enabled() links = [] # Go through the rules and accrue links until we're done. # FIXME: Can we do one ga_track_event call for all the rules? for rule in rules: if rule.match(feedback): links.append( Link( provider=PROVIDER, provider_version=PROVIDER_VERSION, cssclass=u'document', summary=rule.title, description=rule.description, url=build_redirect_url(format_redirect(rule.slug)) ) ) # Track category: trigger-slug, action: suggest ga_track_event({ 'cid': str(feedback.id), 'ec': build_ga_category(rule), 'ea': 'suggest', 'el': rule.url }) return links