def __init__(self): from johnny.signals import qc_hit, qc_miss, qc_skip from Queue import Queue as queue self.q = queue() qc_hit.connect(self._hit) qc_miss.connect(self._miss) qc_skip.connect(self._skip)
def _inner(_query): msg = [] def hit(*args, **kwargs): msg.append(True) def miss(*args, **kwargs): msg.append(False) def skip(*args, **kwargs): msg.append(False) qc_hit.connect(hit) qc_miss.connect(miss) qc_skip.connect(skip) obj = eval(_query, data) msg.append(obj) queue.put(msg)
def test_signals(self): """Test that the signals we say we're sending are being sent.""" misses = [] hits = [] def qc_hit_listener(sender, **kwargs): hits.append(kwargs['key']) def qc_miss_listener(*args, **kwargs): misses.append(kwargs['key']) qc_hit.connect(qc_hit_listener) qc_miss.connect(qc_miss_listener) qc_skip.connect(qc_miss_listener) first = list(Genre.objects.filter(title__startswith='A').order_by('slug')) second = list(Genre.objects.filter(title__startswith='A').order_by('slug')) self.assertEqual(len(misses), 1) self.assertEqual(len(hits), 1)
def test_signals(self): """Test that the signals we say we're sending are being sent.""" from testapp.models import Genre from johnny.signals import qc_hit, qc_miss, qc_skip connection.queries = [] misses = [] hits = [] def qc_hit_listener(sender, **kwargs): hits.append(kwargs['key']) def qc_miss_listener(*args, **kwargs): misses.append(kwargs['key']) qc_hit.connect(qc_hit_listener) qc_miss.connect(qc_miss_listener) qc_skip.connect(qc_miss_listener) first = list(Genre.objects.filter(title__startswith='A').order_by('slug')) second = list(Genre.objects.filter(title__startswith='A').order_by('slug')) self.failUnless(len(misses) == len(hits) == 1)
def _inner(_query): msg = [] def hit(*args, **kwargs): msg.append(True) def miss(*args, **kwargs): msg.append(False) qc_hit.connect(hit) qc_miss.connect(miss) qc_skip.connect(miss) obj = eval(_query) msg.append(obj) queue.put(msg) if connections is not None: #this is to fix a race condition with the #thread to ensure that we close it before #the next test runs connections['default'].close()
def _inner(_query): from testapp.models import Genre, Book, Publisher, Person from johnny.signals import qc_hit, qc_miss, qc_skip from johnny.cache import local from django.db import transaction msg = [] def hit(*args, **kwargs): msg.append(True) def miss(*args, **kwargs): msg.append(False) def skip(*args, **kwargs): msg.append(False) qc_hit.connect(hit) qc_miss.connect(miss) qc_skip.connect(skip) obj = eval(_query) msg.append(obj) queue.put(msg)
def _inner(_query): from testapp.models import Genre, Book, Publisher, Person from johnny.signals import qc_hit, qc_miss, qc_skip msg = [] def hit(*args, **kwargs): msg.append(True) def miss(*args, **kwargs): msg.append(False) qc_hit.connect(hit) qc_miss.connect(miss) qc_skip.connect(miss) obj = eval(_query) msg.append(obj) queue.put(msg) if connections is not None: #this is to fix a race condition with the #thread to ensure that we close it before #the next test runs connections['default'].close()
def test_signals(self): """Test that the signals we say we're sending are being sent.""" misses = [] hits = [] def qc_hit_listener(sender, **kwargs): hits.append(kwargs['key']) def qc_miss_listener(*args, **kwargs): misses.append(kwargs['key']) qc_hit.connect(qc_hit_listener) qc_miss.connect(qc_miss_listener) qc_skip.connect(qc_miss_listener) first = list( Genre.objects.filter(title__startswith='A').order_by('slug')) second = list( Genre.objects.filter(title__startswith='A').order_by('slug')) self.assertEqual(len(misses), 1) self.assertEqual(len(hits), 1)
def __init__(self): self.q = Queue() qc_hit.connect(self._hit) qc_miss.connect(self._miss) qc_skip.connect(self._skip)