def test_check_operator_comparison(self): string_type = StringType('yo yo') with patch.object(string_type, 'contains', return_value=True): result = engine._do_operator_comparison( string_type, 'contains', 'its mocked') self.assertTrue(result) string_type.contains.assert_called_once_with('its mocked')
def test_non_empty(self): self.assertTrue(StringType("hello").non_empty()) self.assertFalse(StringType("").non_empty()) self.assertFalse(StringType(None).non_empty())
def test_string_contains(self): self.assertTrue(StringType("hello").contains("ell")) self.assertTrue(StringType("hello").contains("he")) self.assertTrue(StringType("hello").contains("lo")) self.assertFalse(StringType("hello").contains("asdf")) self.assertFalse(StringType("hello").contains("ElL"))
def test_string_matches_regex(self): self.assertTrue(StringType("hello").matches_regex(r"^h")) self.assertFalse(StringType("hello").matches_regex(r"^sh"))
def test_string_starts_with(self): self.assertTrue(StringType("hello").starts_with("he")) self.assertFalse(StringType("hello").starts_with("hey")) self.assertFalse(StringType("hello").starts_with("He"))
def test_string_ends_with(self): self.assertTrue(StringType("hello").ends_with("lo")) self.assertFalse(StringType("hello").ends_with("boom")) self.assertFalse(StringType("hello").ends_with("Lo"))
def test_string_equal_to_case_insensitive(self): self.assertTrue(StringType("foo").equal_to_case_insensitive("FOo")) self.assertTrue(StringType("foo").equal_to_case_insensitive("foo")) self.assertFalse(StringType("foo").equal_to_case_insensitive("blah"))
def test_string_equal_to(self): self.assertTrue(StringType("foo").equal_to("foo")) self.assertFalse(StringType("foo").equal_to("Foo"))
def test_operator_decorator(self): self.assertTrue(StringType("foo").equal_to.is_operator)
def test_invalid_value(self): with self.assertRaises(AssertionError): StringType(123)
def test_string_not_equal_to(self): self.assertTrue(StringType("foo").not_equal_to("bar")) self.assertTrue(StringType("foo").not_equal_to("Foo"))