| 430 | def assertNumberofQueries(self, num, callable, *args, **kwargs): |
| 431 | """ |
| 432 | Asserts that exactly num queries were used when callable was invoked. |
| 433 | """ |
| 434 | DEBUG = settings.DEBUG |
| 435 | settings.DEBUG = True |
| 436 | |
| 437 | num_queries_before = len(connection.queries) |
| 438 | callable(*args, **kwargs) |
| 439 | num_queries_after = len(connection.queries) |
| 440 | actual = (num_queries_after - num_queries_before) |
| 441 | |
| 442 | settings.DEBUG = DEBUG |
| 443 | self.failUnlessEqual(num, actual, |
| 444 | (u"Callable did not execute %s queries as expected." |
| 445 | u" Actual number of queries: %s.") % (num, actual)) |
| 446 | |