Exemplo n.º 1
0
    def test_multi_match(self):
        client = self._client(version='1.0', locale='en-US')
        pass_rule = ClientMatchRuleFactory(version='1.0', locale='en-US')
        fail_rule = ClientMatchRuleFactory(version='1.0', locale='fr')

        self.assertTrue(pass_rule.matches(client))
        self.assertTrue(not fail_rule.matches(client))
Exemplo n.º 2
0
    def test_regex_match(self):
        client = self._client(version='15.2.4')
        pass_rule = ClientMatchRuleFactory(version=r'/[\d\.]+/')
        fail_rule = ClientMatchRuleFactory(version=r'/\D+/')

        self.assertTrue(pass_rule.matches(client))
        self.assertTrue(not fail_rule.matches(client))
Exemplo n.º 3
0
    def test_string_match(self):
        client = self._client(channel='aurora')
        pass_rule = ClientMatchRuleFactory(channel='aurora')
        fail_rule = ClientMatchRuleFactory(channel='nightly')

        self.assertTrue(pass_rule.matches(client))
        self.assertTrue(not fail_rule.matches(client))
Exemplo n.º 4
0
    def test_match_client_base(self):
        client_match_rule_pass_1 = ClientMatchRuleFactory(channel='nightly')
        client_match_rule_pass_2 = ClientMatchRuleFactory(
            channel='/(beta|nightly)/')
        client_match_rule_fail = ClientMatchRuleFactory(channel='release')

        # Matching snippets.
        snippet_1 = SnippetFactory.create(
            on_nightly=True, client_match_rules=[client_match_rule_pass_1])
        snippet_2 = SnippetFactory.create(
            on_beta=True,
            on_nightly=True,
            client_match_rules=[client_match_rule_pass_2])
        snippet_3 = SnippetFactory.create(on_nightly=True)

        # Not matching snippets.
        SnippetFactory.create(on_beta=True)
        SnippetFactory.create(on_nightly=True,
                              client_match_rules=[client_match_rule_fail])
        SnippetFactory.create(on_nightly=True,
                              client_match_rules=[
                                  client_match_rule_fail,
                                  client_match_rule_pass_2
                              ])
        client = self._build_client(channel='nightly')
        snippets = Snippet.objects.match_client(client)
        self.assertEqual(set(snippets), set([snippet_1, snippet_2, snippet_3]))
Exemplo n.º 5
0
    def test_exclusion_rule_match(self):
        client = self._client(channel='aurora')
        fail_rule = ClientMatchRuleFactory(channel='aurora', is_exclusion=True)
        pass_rule = ClientMatchRuleFactory(channel='nightly',
                                           is_exclusion=True)

        self.assertTrue(pass_rule.matches(client))
        self.assertTrue(not fail_rule.matches(client))
Exemplo n.º 6
0
 def test_base(self):
     cmr_el = ClientMatchRuleFactory(locale='/^el/')
     cmr_ast = ClientMatchRuleFactory(locale='ast|ja-JP-mac',
                                      channel='aurora')
     cmr_es = ClientMatchRuleFactory(locale='/(es-MX)|(es-AR)/')
     cmr_bogus = ClientMatchRuleFactory(locale='/foo/')
     snippet = SnippetFactory(
         client_match_rules=[cmr_el, cmr_ast, cmr_es, cmr_bogus],
         locale_set=[
             SnippetLocale(locale='pl'),
             SnippetLocale(locale='en')
         ])
     cmr_to_locales_action(None, None, [snippet])
     eq_(snippet.locale_set.count(), 5)
     eq_(set(snippet.locale_set.values_list('locale', flat=True)),
         set(['el', 'ast', 'ja-jp-mac', 'es-mx', 'es-ar']))
     eq_(snippet.client_match_rules.count(), 1)
     eq_(snippet.client_match_rules.all()[0], cmr_ast)
Exemplo n.º 7
0
 def test_exclusion_cmr(self):
     cmr_el = ClientMatchRuleFactory(locale='/^el/', is_exclusion=True)
     snippet = SnippetFactory(client_match_rules=[cmr_el],
                              locale_set=[
                                  SnippetLocale(locale='pl'),
                                  SnippetLocale(locale='en')
                              ])
     cmr_to_locales_action(None, None, [snippet])
     eq_(snippet.locale_set.count(), len(LANGUAGE_VALUES) - 1)
     ok_(not snippet.locale_set.filter(locale='el').exists())
     eq_(snippet.client_match_rules.count(), 0)
Exemplo n.º 8
0
    def test_empty_match(self):
        client = self._client(version='1.0', locale='fr')
        rule = ClientMatchRuleFactory()

        self.assertTrue(rule.matches(client))