def test_regex_match(self): client = self._client(version='15.2.4') pass_rule = ClientMatchRuleFactory(version='/[\d\.]+/') fail_rule = ClientMatchRuleFactory(version='/\D+/') ok_(pass_rule.matches(client)) ok_(not fail_rule.matches(client))
def test_string_match(self): client = self._client(channel='aurora') pass_rule = ClientMatchRuleFactory(channel='aurora') fail_rule = ClientMatchRuleFactory(channel='nightly') ok_(pass_rule.matches(client)) ok_(not fail_rule.matches(client))
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') ok_(pass_rule.matches(client)) ok_(not fail_rule.matches(client))
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]))
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) ok_(pass_rule.matches(client)) ok_(not fail_rule.matches(client))
def _dup_test(self, snippet): snippet.client_match_rules.add(*ClientMatchRuleFactory.create_batch(3)) snippet_copy = snippet.duplicate() eq_(snippet_copy.disabled, True) ok_(snippet_copy.id != snippet.id) eq_(snippet_copy.locale_set.count(), 1) ok_(snippet_copy.locale_set.all()[0] != snippet.locale_set.all()[0]) eq_(set(snippet_copy.client_match_rules.all()), set(snippet.client_match_rules.all()))
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)
def _dup_test(self, snippet): snippet.client_match_rules.add(*ClientMatchRuleFactory.create_batch(3)) snippet_copy = snippet.duplicate() self.assertEqual(snippet_copy.disabled, True) self.assertTrue(snippet_copy.id != snippet.id) self.assertEqual(snippet_copy.locales.count(), 1) self.assertTrue(snippet_copy.locales.all()[0] == snippet.locales.all()[0]) self.assertEqual(set(snippet_copy.client_match_rules.all()), set(snippet.client_match_rules.all()))
def _dup_test(self, snippet): snippet.client_match_rules.add(*ClientMatchRuleFactory.create_batch(3)) snippet_copy = snippet.duplicate() self.assertEqual(snippet_copy.disabled, True) self.assertTrue(snippet_copy.id != snippet.id) self.assertEqual(snippet_copy.locales.count(), 1) self.assertTrue( snippet_copy.locales.all()[0] == snippet.locales.all()[0]) self.assertEqual(set(snippet_copy.client_match_rules.all()), set(snippet.client_match_rules.all()))
def test_basic(self, matches): rule1_pass = ClientMatchRuleFactory.create() rule2_pass = ClientMatchRuleFactory.create() rule3_fail = ClientMatchRuleFactory.create() rule4_pass = ClientMatchRuleFactory.create() rule5_fail = ClientMatchRuleFactory.create() return_values = { rule1_pass.id: True, rule2_pass.id: True, rule3_fail.id: False, rule4_pass.id: True, rule5_fail.id: False, } matches.side_effect = lambda self, client: return_values.get(self.id, False) passed, failed = self.manager.all().evaluate('asdf') eq_(set([rule1_pass, rule2_pass, rule4_pass]), set(passed)) eq_(set([rule3_fail, rule5_fail]), set(failed))
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)
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))
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))
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))
def _dup_test(self, snippet): user = UserFactory.create() snippet.client_match_rules.add(*ClientMatchRuleFactory.create_batch(3)) snippet_copy = snippet.duplicate(user) self.assertEqual(snippet_copy.published, False) self.assertNotEqual(snippet_copy.id, snippet.id) self.assertEqual(snippet_copy.locales.count(), 1) self.assertTrue( snippet_copy.locales.all()[0] == snippet.locales.all()[0]) self.assertEqual(set(snippet_copy.client_match_rules.all()), set(snippet.client_match_rules.all())) self.assertNotEqual(snippet_copy.creator, snippet.creator)
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))
def test_empty_match(self): client = self._client(version='1.0', locale='fr') rule = ClientMatchRuleFactory() self.assertTrue(rule.matches(client))
def test_empty_match(self): client = self._client(version='1.0', locale='fr') rule = ClientMatchRuleFactory() ok_(rule.matches(client))