def test_test_url_method(self):
        validator = Validator(None)

        expect(validator.test_url("the-url", Mock(status_code=200, url="the-url"))).to_equal(True)
        expect(validator.test_url("the-url", Mock(status_code=404))).to_equal(False)
        expect(validator.test_url("the-url", Mock(status_code=302))).to_equal(False)
        expect(validator.test_url("the-url", Mock(status_code=307))).to_equal(False)
        expect(validator.test_url("the-url-root", Mock(status_code=200, url="the-url-index"))).to_equal(False)

        callback_1 = Mock()
        callback_2 = Mock()
        expect(validator.test_url("the-url", Mock(status_code=404), callback_1, callback_2)).to_equal(False)
        expect(callback_1.call_count).to_equal(1)
        expect(callback_2.call_count).to_equal(0)

        callback_1 = Mock()
        callback_2 = Mock()
        expect(validator.test_url("the-url", Mock(status_code=302), callback_1, callback_2)).to_equal(False)
        expect(callback_1.call_count).to_equal(0)
        expect(callback_2.call_count).to_equal(1)

        callback_1 = Mock()
        callback_2 = Mock()
        expect(validator.test_url("the-url", Mock(status_code=307), callback_1, callback_2)).to_equal(False)
        expect(callback_1.call_count).to_equal(0)
        expect(callback_2.call_count).to_equal(1)
Example #2
0
    def test_test_url_method(self):
        validator = Validator(None)

        expect(validator.test_url('the-url', Mock(status_code=200, url='the-url'))).to_equal(True)
        expect(validator.test_url('the-url', Mock(status_code=404))).to_equal(False)
        expect(validator.test_url('the-url', Mock(status_code=302))).to_equal(False)
        expect(validator.test_url('the-url', Mock(status_code=307))).to_equal(False)
        expect(validator.test_url('the-url-root', Mock(status_code=200, url='the-url-index'))).to_equal(False)

        callback_1 = Mock()
        callback_2 = Mock()
        expect(validator.test_url('the-url', Mock(status_code=404), callback_1, callback_2)).to_equal(False)
        expect(callback_1.call_count).to_equal(1)
        expect(callback_2.call_count).to_equal(0)

        callback_1 = Mock()
        callback_2 = Mock()
        expect(validator.test_url('the-url', Mock(status_code=302), callback_1, callback_2)).to_equal(False)
        expect(callback_1.call_count).to_equal(0)
        expect(callback_2.call_count).to_equal(1)

        callback_1 = Mock()
        callback_2 = Mock()
        expect(validator.test_url('the-url', Mock(status_code=307), callback_1, callback_2)).to_equal(False)
        expect(callback_1.call_count).to_equal(0)
        expect(callback_2.call_count).to_equal(1)
    def test_send_url(self):
        validator = Validator(Mock(config=Mock(MAX_ENQUEUE_BUFFER_LENGTH=1)))

        validator.flush = Mock()
        validator.test_url = Mock(return_value=True)

        expect(len(validator.url_buffer)).to_equal(0)

        validator.send_url("the-url", 0.0, "the-response")

        expect(len(validator.url_buffer)).to_equal(1)
        expect(validator.flush.call_count).to_equal(0)

        validator.send_url("the-url-2", 0.0, "the-response-2")

        expect(len(validator.url_buffer)).to_equal(2)
        expect(validator.flush.call_count).to_equal(1)
Example #4
0
    def test_send_url(self):
        validator = Validator(Mock(config=Mock(MAX_ENQUEUE_BUFFER_LENGTH=1)))

        validator.flush = Mock()
        validator.test_url = Mock(return_value=True)

        expect(len(validator.url_buffer)).to_equal(0)

        validator.send_url('the-url', 0.0, 'the-response')

        expect(len(validator.url_buffer)).to_equal(1)
        expect(validator.flush.call_count).to_equal(0)

        validator.send_url('the-url-2', 0.0, 'the-response-2')

        expect(len(validator.url_buffer)).to_equal(2)
        expect(validator.flush.call_count).to_equal(1)