| 1054 | ci1 = CategoryItem(category=c1) |
| 1055 | ci2 = CategoryItem(category=c2) |
| 1056 | ci3 = CategoryItem(category=c3) |
| 1057 | ci1.save() |
| 1058 | ci2.save() |
| 1059 | ci3.save() |
| 1060 | |
| 1061 | self.assertEqual( |
| 1062 | CategoryItem.objects.filter(category__specialcategory__isnull=False).count(), |
| 1063 | 2 |
| 1064 | ) |
| 1065 | self.assertItemsEqual( |
| 1066 | CategoryItem.objects.filter(category__specialcategory__isnull=False), |
| 1067 | CategoryItem.objects.filter(pk__in=[ci2.pk, ci3.pk]) |
| 1068 | ) |
| 1069 | |
| 1070 | def test_ticket15316_exclude_false(self): |
| 1071 | c1 = SimpleCategory(name="category1") |
| 1072 | c2 = SpecialCategory(name="named category1", special_name="special1") |
| 1073 | c3 = SpecialCategory(name="named category2", special_name="special2") |
| 1074 | c1.save() |
| 1075 | c2.save() |
| 1076 | c3.save() |
| 1077 | |
| 1078 | ci1 = CategoryItem(category=c1) |
| 1079 | ci2 = CategoryItem(category=c2) |
| 1080 | ci3 = CategoryItem(category=c3) |
| 1081 | ci1.save() |
| 1082 | ci2.save() |
| 1083 | ci3.save() |
| 1084 | |
| 1085 | self.assertEqual( |
| 1086 | CategoryItem.objects.exclude(category__specialcategory__isnull=False).count(), |
| 1087 | 1 |
| 1088 | ) |
| 1089 | self.assertItemsEqual( |
| 1090 | CategoryItem.objects.exclude(category__specialcategory__isnull=False), |
| 1091 | CategoryItem.objects.filter(pk__in=[ci1.pk]) |
| 1092 | ) |
| 1093 | |
| 1094 | def test_ticket15316_filter_true(self): |
| 1095 | c1 = SimpleCategory(name="category1") |
| 1096 | c2 = SpecialCategory(name="named category1", special_name="special1") |
| 1097 | c3 = SpecialCategory(name="named category2", special_name="special2") |
| 1098 | c1.save() |
| 1099 | c2.save() |
| 1100 | c3.save() |
| 1101 | ci1 = CategoryItem(category=c1) |
| 1102 | ci2 = CategoryItem(category=c2) |
| 1103 | ci3 = CategoryItem(category=c3) |
| 1104 | ci1.save() |
| 1105 | ci2.save() |
| 1106 | ci3.save() |
| 1107 | |
| 1108 | self.assertEqual( |
| 1109 | CategoryItem.objects.filter(category__specialcategory__isnull=True).count(), |
| 1110 | 1 |
| 1111 | ) |
| 1112 | |
| 1113 | self.assertItemsEqual( |
| 1114 | CategoryItem.objects.filter(category__specialcategory__isnull=True), |
| 1115 | CategoryItem.objects.filter(pk__in=[ci1.pk]) |
| 1116 | ) |
| 1117 | |
| 1118 | def test_ticket15316_exclude_true(self): |
| 1119 | c1 = SimpleCategory(name="category1") |
| 1120 | c2 = SpecialCategory(name="named category1", special_name="special1") |
| 1121 | c3 = SpecialCategory(name="named category2", special_name="special2") |
| 1122 | c1.save() |
| 1123 | c2.save() |
| 1124 | c3.save() |
| 1125 | |
| 1126 | ci1 = CategoryItem(category=c1) |
| 1127 | ci2 = CategoryItem(category=c2) |
| 1128 | ci3 = CategoryItem(category=c3) |
| 1129 | ci1.save() |
| 1130 | ci2.save() |
| 1131 | ci3.save() |
| 1132 | |
| 1133 | self.assertEqual( |
| 1134 | CategoryItem.objects.exclude(category__specialcategory__isnull=True).count(), |
| 1135 | 2 |
| 1136 | ) |
| 1137 | |
| 1138 | self.assertItemsEqual( |
| 1139 | CategoryItem.objects.exclude(category__specialcategory__isnull=True), |
| 1140 | CategoryItem.objects.filter(pk__in=[ci2.pk, ci3.pk]) |
| 1141 | ) |
| 1142 | |
| 1143 | def test_ticket15316_one2one_filter_false(self): |
| 1144 | c = SimpleCategory(name="cat") |
| 1145 | c0 = SimpleCategory(name="cat0") |
| 1146 | c1 = SimpleCategory(name="category1") |
| 1147 | |
| 1148 | c.save() |
| 1149 | c0.save() |
| 1150 | c1.save() |
| 1151 | |
| 1152 | c2 = OneToOneCategory(category = c1, new_name="new1") |
| 1153 | c3 = OneToOneCategory(category = c0, new_name="new2") |
| 1154 | |
| 1155 | c2.save() |
| 1156 | c3.save() |
| 1157 | |
| 1158 | ci1 = CategoryItem(category=c) |
| 1159 | ci2 = CategoryItem(category=c0) |
| 1160 | ci3 = CategoryItem(category=c1) |
| 1161 | ci1.save() |
| 1162 | ci2.save() |
| 1163 | ci3.save() |
| 1164 | |
| 1165 | self.assertEqual( |
| 1166 | CategoryItem.objects.filter(category__onetoonecategory__isnull=False).count(), |
| 1167 | 2 |
| 1168 | ) |
| 1169 | self.assertItemsEqual( |
| 1170 | CategoryItem.objects.filter(category__onetoonecategory__isnull=False), |
| 1171 | CategoryItem.objects.filter(pk__in=[ci2.pk, ci3.pk]) |
| 1172 | ) |
| 1173 | |
| 1174 | def test_ticket15316_one2one_exclude_false(self): |
| 1175 | c = SimpleCategory(name="cat") |
| 1176 | c0 = SimpleCategory(name="cat0") |
| 1177 | c1 = SimpleCategory(name="category1") |
| 1178 | |
| 1179 | c.save() |
| 1180 | c0.save() |
| 1181 | c1.save() |
| 1182 | |
| 1183 | c2 = OneToOneCategory(category = c1, new_name="new1") |
| 1184 | c3 = OneToOneCategory(category = c0, new_name="new2") |
| 1185 | |
| 1186 | c2.save() |
| 1187 | c3.save() |
| 1188 | |
| 1189 | ci1 = CategoryItem(category=c) |
| 1190 | ci2 = CategoryItem(category=c0) |
| 1191 | ci3 = CategoryItem(category=c1) |
| 1192 | ci1.save() |
| 1193 | ci2.save() |
| 1194 | ci3.save() |
| 1195 | |
| 1196 | self.assertEqual( |
| 1197 | CategoryItem.objects.exclude(category__onetoonecategory__isnull=False).count(), |
| 1198 | 1 |
| 1199 | ) |
| 1200 | self.assertItemsEqual( |
| 1201 | CategoryItem.objects.exclude(category__onetoonecategory__isnull=False), |
| 1202 | CategoryItem.objects.filter(pk__in=[ci1.pk]) |
| 1203 | ) |
| 1204 | |
| 1205 | def test_ticket15316_one2one_filter_true(self): |
| 1206 | c = SimpleCategory(name="cat") |
| 1207 | c0 = SimpleCategory(name="cat0") |
| 1208 | c1 = SimpleCategory(name="category1") |
| 1209 | |
| 1210 | c.save() |
| 1211 | c0.save() |
| 1212 | c1.save() |
| 1213 | |
| 1214 | c2 = OneToOneCategory(category = c1, new_name="new1") |
| 1215 | c3 = OneToOneCategory(category = c0, new_name="new2") |
| 1216 | |
| 1217 | c2.save() |
| 1218 | c3.save() |
| 1219 | |
| 1220 | ci1 = CategoryItem(category=c) |
| 1221 | ci2 = CategoryItem(category=c0) |
| 1222 | ci3 = CategoryItem(category=c1) |
| 1223 | ci1.save() |
| 1224 | ci2.save() |
| 1225 | ci3.save() |
| 1226 | |
| 1227 | self.assertEqual( |
| 1228 | CategoryItem.objects.filter(category__onetoonecategory__isnull=True).count(), |
| 1229 | 1 |
| 1230 | ) |
| 1231 | |
| 1232 | self.assertItemsEqual( |
| 1233 | CategoryItem.objects.filter(category__onetoonecategory__isnull=True), |
| 1234 | CategoryItem.objects.filter(pk__in=[ci1.pk]) |
| 1235 | ) |
| 1236 | |
| 1237 | def test_ticket15316_one2one_exclude_true(self): |
| 1238 | c = SimpleCategory(name="cat") |
| 1239 | c0 = SimpleCategory(name="cat0") |
| 1240 | c1 = SimpleCategory(name="category1") |
| 1241 | |
| 1242 | c.save() |
| 1243 | c0.save() |
| 1244 | c1.save() |
| 1245 | |
| 1246 | c2 = OneToOneCategory(category = c1, new_name="new1") |
| 1247 | c3 = OneToOneCategory(category = c0, new_name="new2") |
| 1248 | |
| 1249 | c2.save() |
| 1250 | c3.save() |
| 1251 | |
| 1252 | ci1 = CategoryItem(category=c) |
| 1253 | ci2 = CategoryItem(category=c0) |
| 1254 | ci3 = CategoryItem(category=c1) |
| 1255 | ci1.save() |
| 1256 | ci2.save() |
| 1257 | ci3.save() |
| 1258 | |
| 1259 | self.assertEqual( |
| 1260 | CategoryItem.objects.exclude(category__onetoonecategory__isnull=True).count(), |
| 1261 | 2 |
| 1262 | ) |
| 1263 | |
| 1264 | self.assertItemsEqual( |
| 1265 | CategoryItem.objects.exclude(category__onetoonecategory__isnull=True), |
| 1266 | CategoryItem.objects.filter(pk__in=[ci2.pk, ci3.pk]) |
| 1267 | ) |
| 1268 | |
| 1269 | |
| 1270 | |