15 | 15 | DumbCategory, ExtraInfo, Fan, Item, LeafA, LoopX, LoopZ, ManagedModel, |
16 | 16 | Member, NamedCategory, Note, Number, Plaything, PointerA, Ranking, Related, |
17 | 17 | Report, ReservedName, Tag, TvChef, Valid, X, Food, Eaten, Node, ObjectA, ObjectB, |
| 1043 | ci1 = CategoryItem(category=c1) |
| 1044 | ci2 = CategoryItem(category=c2) |
| 1045 | ci3 = CategoryItem(category=c3) |
| 1046 | ci1.save() |
| 1047 | ci2.save() |
| 1048 | ci3.save() |
| 1049 | |
| 1050 | self.assertEqual( |
| 1051 | CategoryItem.objects.filter(category__specialcategory__isnull=False).count(), |
| 1052 | 2 |
| 1053 | ) |
| 1054 | |
| 1055 | self.assertItemsEqual( |
| 1056 | CategoryItem.objects.filter(category__specialcategory__isnull=False), |
| 1057 | CategoryItem.objects.filter(pk__in=[ci2.pk, ci3.pk]) |
| 1058 | ) |
| 1059 | |
| 1060 | def test_ticket15316_exclude_false(self): |
| 1061 | c1 = SimpleCategory(name="category1") |
| 1062 | c2 = SpecialCategory(name="named category1", special_name="special1") |
| 1063 | c3 = SpecialCategory(name="named category2", special_name="special2") |
| 1064 | c1.save() |
| 1065 | c2.save() |
| 1066 | c3.save() |
| 1067 | |
| 1068 | ci1 = CategoryItem(category=c1) |
| 1069 | ci2 = CategoryItem(category=c2) |
| 1070 | ci3 = CategoryItem(category=c3) |
| 1071 | ci1.save() |
| 1072 | ci2.save() |
| 1073 | ci3.save() |
| 1074 | |
| 1075 | self.assertEqual( |
| 1076 | CategoryItem.objects.exclude(category__specialcategory__isnull=False).count(), |
| 1077 | 1 |
| 1078 | ) |
| 1079 | |
| 1080 | self.assertItemsEqual( |
| 1081 | CategoryItem.objects.exclude(category__specialcategory__isnull=False), |
| 1082 | CategoryItem.objects.filter(pk__in=[ci1.pk]) |
| 1083 | ) |
| 1084 | |
| 1085 | def test_ticket15316_filter_true(self): |
| 1086 | c1 = SimpleCategory(name="category1") |
| 1087 | c2 = SpecialCategory(name="named category1", special_name="special1") |
| 1088 | c3 = SpecialCategory(name="named category2", special_name="special2") |
| 1089 | c1.save() |
| 1090 | c2.save() |
| 1091 | c3.save() |
| 1092 | |
| 1093 | ci1 = CategoryItem(category=c1) |
| 1094 | ci2 = CategoryItem(category=c2) |
| 1095 | ci3 = CategoryItem(category=c3) |
| 1096 | ci1.save() |
| 1097 | ci2.save() |
| 1098 | ci3.save() |
| 1099 | |
| 1100 | self.assertEqual( |
| 1101 | CategoryItem.objects.filter(category__specialcategory__isnull=True).count(), |
| 1102 | 1 |
| 1103 | ) |
| 1104 | |
| 1105 | self.assertItemsEqual( |
| 1106 | CategoryItem.objects.filter(category__specialcategory__isnull=True), |
| 1107 | CategoryItem.objects.filter(pk__in=[ci1.pk]) |
| 1108 | ) |
| 1109 | |
| 1110 | def test_ticket15316_exclude_true(self): |
| 1111 | c1 = SimpleCategory(name="category1") |
| 1112 | c2 = SpecialCategory(name="named category1", special_name="special1") |
| 1113 | c3 = SpecialCategory(name="named category2", special_name="special2") |
| 1114 | c1.save() |
| 1115 | c2.save() |
| 1116 | c3.save() |
| 1117 | |
| 1118 | ci1 = CategoryItem(category=c1) |
| 1119 | ci2 = CategoryItem(category=c2) |
| 1120 | ci3 = CategoryItem(category=c3) |
| 1121 | ci1.save() |
| 1122 | ci2.save() |
| 1123 | ci3.save() |
| 1124 | |
| 1125 | self.assertEqual( |
| 1126 | CategoryItem.objects.exclude(category__specialcategory__isnull=True).count(), |
| 1127 | 2 |
| 1128 | ) |
| 1129 | |
| 1130 | self.assertItemsEqual( |
| 1131 | CategoryItem.objects.exclude(category__specialcategory__isnull=True), |
| 1132 | CategoryItem.objects.filter(pk__in=[ci2.pk, ci3.pk]) |
| 1133 | ) |
| 1134 | |