|
1 | 1 | import unittest
|
| 2 | +from datetime import datetime |
2 | 3 |
|
3 | 4 | import mock
|
| 5 | +from dateutil import parser |
4 | 6 | from freezegun import freeze_time
|
5 | 7 |
|
6 | 8 | from posthog.client import Client
|
@@ -1118,6 +1120,39 @@ def test_match_properties_math_operators(self):
|
1118 | 1120 | self.assertFalse(match_property(property_d, {"key": "44"}))
|
1119 | 1121 | self.assertFalse(match_property(property_d, {"key": 44}))
|
1120 | 1122 |
|
| 1123 | + def test_match_property_date_operators(self): |
| 1124 | + property_a = self.property(key="key", value="2022-05-01", operator="is_date_before") |
| 1125 | + self.assertTrue(match_property(property_a, {"key": "2022-03-01"})) |
| 1126 | + self.assertTrue(match_property(property_a, {"key": "2022-04-30"})) |
| 1127 | + self.assertTrue(match_property(property_a, {"key": datetime(2022, 4, 30)})) |
| 1128 | + self.assertTrue(match_property(property_a, {"key": parser.parse("2022-04-30")})) |
| 1129 | + self.assertFalse(match_property(property_a, {"key": "2022-05-30"})) |
| 1130 | + |
| 1131 | + # Can't be a number |
| 1132 | + with self.assertRaises(InconclusiveMatchError): |
| 1133 | + match_property(property_a, {"key": 1}) |
| 1134 | + |
| 1135 | + # can't be invalid string |
| 1136 | + with self.assertRaises(InconclusiveMatchError): |
| 1137 | + match_property(property_a, {"key": "abcdef"}) |
| 1138 | + |
| 1139 | + property_b = self.property(key="key", value="2022-05-01", operator="is_date_after") |
| 1140 | + self.assertTrue(match_property(property_b, {"key": "2022-05-02"})) |
| 1141 | + self.assertTrue(match_property(property_b, {"key": "2022-05-30"})) |
| 1142 | + self.assertTrue(match_property(property_b, {"key": datetime(2022, 5, 30)})) |
| 1143 | + self.assertTrue(match_property(property_b, {"key": parser.parse("2022-05-30")})) |
| 1144 | + self.assertFalse(match_property(property_b, {"key": "2022-04-30"})) |
| 1145 | + |
| 1146 | + # can't be invalid string |
| 1147 | + with self.assertRaises(InconclusiveMatchError): |
| 1148 | + match_property(property_b, {"key": "abcdef"}) |
| 1149 | + |
| 1150 | + # Invalid flag property |
| 1151 | + property_c = self.property(key="key", value=1234, operator="is_date_before") |
| 1152 | + |
| 1153 | + with self.assertRaises(InconclusiveMatchError): |
| 1154 | + match_property(property_c, {"key": 1}) |
| 1155 | + |
1121 | 1156 |
|
1122 | 1157 | class TestCaptureCalls(unittest.TestCase):
|
1123 | 1158 | @mock.patch.object(Client, "capture")
|
|
0 commit comments