bc.check
Check
Mixin with the purpose of cover all the related with the custom asserts
Source code in breathecode/tests/mixins/breathecode_mixin/check.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 |
|
calls(first, second)
Fail if the two objects are partially unequal as determined by the '==' operator.
Usage:
Source code in breathecode/tests/mixins/breathecode_mixin/check.py
datetime_in_range(start, end, date)
Check if a range if between start and end argument.
Usage:
from django.utils import timezone
start = timezone.now()
in_range = timezone.now()
end = timezone.now()
out_of_range = timezone.now()
# pass because this datetime is between start and end
self.bc.check.datetime_in_range(start, end, in_range) # 🟢
# fail because this datetime is not between start and end
self.bc.check.datetime_in_range(start, end, out_of_range) # 🔴
Source code in breathecode/tests/mixins/breathecode_mixin/check.py
list_with_pks(query, pks)
Check if the list have the following primary keys.
Usage:
from breathecode.admissions.models import Cohort, Academy
model = self.bc.database.create(cohort=1)
collection = [model.cohort]
# pass because the QuerySet has the primary keys 1
self.bc.check.list_with_pks(collection, [1]) # 🟢
# fail because the QuerySet has the primary keys 1 but the second argument is empty
self.bc.check.list_with_pks(collection, []) # 🔴
Source code in breathecode/tests/mixins/breathecode_mixin/check.py
partial_equality(first, second)
Fail if the two objects are partially unequal as determined by the '==' operator.
Usage:
obj1 = {'key1': 1, 'key2': 2}
obj2 = {'key2': 2, 'key3': 1}
obj3 = {'key2': 2}
# it's fail because the key3 is not in the obj1
self.bc.check.partial_equality(obj1, obj2) # 🔴
# it's fail because the key1 is not in the obj2
self.bc.check.partial_equality(obj2, obj1) # 🔴
# it's pass because the key2 exists in the obj1
self.bc.check.partial_equality(obj1, obj3) # 🟢
# it's pass because the key2 exists in the obj2
self.bc.check.partial_equality(obj2, obj3) # 🟢
# it's fail because the key1 is not in the obj3
self.bc.check.partial_equality(obj3, obj1) # 🔴
# it's fail because the key3 is not in the obj3
self.bc.check.partial_equality(obj3, obj2) # 🔴
Source code in breathecode/tests/mixins/breathecode_mixin/check.py
queryset_of(query, model)
Check if the first argument is a queryset of a models provided as second argument.
Usage:
from breathecode.admissions.models import Cohort, Academy
self.bc.database.create(cohort=1)
collection = []
queryset = Cohort.objects.filter()
# pass because the first argument is a QuerySet and it's type Cohort
self.bc.check.queryset_of(queryset, Cohort) # 🟢
# fail because the first argument is a QuerySet and it is not type Academy
self.bc.check.queryset_of(queryset, Academy) # 🔴
# fail because the first argument is not a QuerySet
self.bc.check.queryset_of(collection, Academy) # 🔴
Source code in breathecode/tests/mixins/breathecode_mixin/check.py
queryset_with_pks(query, pks)
Check if the queryset have the following primary keys.
Usage:
from breathecode.admissions.models import Cohort, Academy
self.bc.database.create(cohort=1)
collection = []
queryset = Cohort.objects.filter()
# pass because the QuerySet has the primary keys 1
self.bc.check.queryset_with_pks(queryset, [1]) # 🟢
# fail because the QuerySet has the primary keys 1 but the second argument is empty
self.bc.check.queryset_with_pks(queryset, []) # 🔴