コード例 #1
0
    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)
コード例 #2
0
    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()
コード例 #3
0
    async def test_detector_sends_to_queue(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()

        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.decode("utf-8"))).to_be_like(expected_payload)
コード例 #4
0
    async def detector_fails_properly(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_true()
        expect(detector.queue).to_be_null()
コード例 #5
0
    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()
コード例 #6
0
    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()
コード例 #7
0
    async def detector_send_to_queues(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()

        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.decode("utf-8"))).to_be_like(expected_payload)