def test_detector_sends_to_queue(self): ctx = mock.Mock( config=mock.Mock( REDIS_QUEUE_SERVER_HOST='0.0.0.0', REDIS_QUEUE_SERVER_PORT=6668, REDIS_QUEUE_SERVER_DB=0, REDIS_QUEUE_SERVER_PASSWORD='******', ), request=mock.Mock( image_url='/image/test.jpg', detection_error=False, ), ) detector = QueuedDetector(ctx, 1, []) expect(detector).not_to_be_null() def validate(data): expect(data).to_be_empty() detector.detect(validate) expect(ctx.request.detection_error).to_be_false() result = self.redis.get('resque:unique:queue:Detect:/image/test.jpg') expect(result).to_equal('1') expected_payload = { "queue": "Detect", "args": ["all", "/image/test.jpg", "/image/test.jpg"], "class": "remotecv.pyres_tasks.DetectTask", "key": "/image/test.jpg" } result = self.redis.lpop('resque:queue:Detect') expect(loads(result)).to_be_like(expected_payload)
def test_detector_can_detect_twice(self): ctx = mock.Mock( config=mock.Mock( REDIS_QUEUE_SERVER_HOST='0.0.0.0', REDIS_QUEUE_SERVER_PORT=6668, REDIS_QUEUE_SERVER_DB=0, REDIS_QUEUE_SERVER_PASSWORD='******', ), request=mock.Mock( image_url='/image/test.jpg', detection_error=False, ), ) detector = QueuedDetector(ctx, 1, []) expect(detector).not_to_be_null() def validate(data): expect(data).to_be_empty() detector.detect(validate) expect(ctx.request.detection_error).to_be_false() expect(detector.queue).not_to_be_null() detector.detect(validate) expect(detector.queue).not_to_be_null()
async def detector_can_detect_twice(self, ctx): detector = QueuedDetector(ctx, 1, []) expect(detector).not_to_be_null() data = await detector.detect() expect(data).to_be_empty() expect(ctx.request.detection_error).to_be_false() expect(detector.queue).not_to_be_null() data = detector.detect() expect(detector.queue).not_to_be_null()
async def test_detector_can_detect_twice(self): ctx = mock.Mock( config=mock.Mock( REDIS_QUEUE_SERVER_HOST=TEST_REDIS_HOST, REDIS_QUEUE_SERVER_PORT=TEST_REDIS_PORT, REDIS_QUEUE_SERVER_DB=0, REDIS_QUEUE_SERVER_PASSWORD=TEST_REDIS_PASSWORD, ), request=mock.Mock( image_url="/image/test.jpg", detection_error=False, ), ) detector = QueuedDetector(ctx, 1, []) expect(detector).not_to_be_null() data = await detector.detect() expect(data).to_be_empty() expect(ctx.request.detection_error).to_be_false() expect(detector.queue).not_to_be_null() data = detector.detect() expect(detector.queue).not_to_be_null()