Esempio n. 1
0
    def test_allow_requests_by_default(self):
        checker = FakeChecker()
        st = StatusTable(checker)

        req = Request(Request.JSON, 'GET', 'http://www.bajoo.fr')
        assert not st.reject_request(req)
        req2 = Request(Request.DOWNLOAD, 'GET', 'http://api.bajoo.fr')
        assert not st.reject_request(req2)
Esempio n. 2
0
    def test_start_ping_on_network_error(self):
        checker = FakeChecker()
        st = StatusTable(checker)
        req = Request(Request.JSON, 'GET', 'http://api.bajoo.fr')

        error = NetworkError()
        st.update(req, error)
        for i in checker.check_deferred:
            print(i)
        assert 'http://api.bajoo.fr' in checker.check_deferred
Esempio n. 3
0
    def test_always_allow_ping_requests(self):
        checker = FakeChecker()
        st = StatusTable(checker)

        req = Request(Request.JSON, 'GET', 'http://www.bajoo.fr/path')
        assert not st.reject_request(req)

        error = NetworkError()
        st.update(req, error)

        req = Request(Request.PING, 'GET', 'http://www.bajoo.fr/')
        assert not st.reject_request(req)
Esempio n. 4
0
    def test_start_ping_on_base_url(self):
        checker = FakeChecker()
        st = StatusTable(checker)

        req = Request(Request.JSON, 'GET', 'http://www.bajoo.fr/path')
        error = NetworkError()
        st.update(req, error)
        req = Request(Request.JSON, 'GET', 'http://www.bajoo.fr/alt_path')
        error = NetworkError()
        st.update(req, error)
        assert 'http://www.bajoo.fr' in checker.check_deferred
        assert len(checker.check_deferred) == 1
Esempio n. 5
0
    def test_prevents_requests_when_network_is_down(self):
        checker = FakeChecker()
        st = StatusTable(checker)

        req = Request(Request.JSON, 'GET', 'http://www.bajoo.fr/')

        assert not st.reject_request(req)

        error = NetworkError()
        st.update(req, error)

        req = Request(Request.JSON, 'GET', 'http://www.bajoo.fr/')
        assert st.reject_request(req) == error
Esempio n. 6
0
    def test_general_callbacks(self):
        checker = FakeChecker()
        st = StatusTable(checker)
        context = {'status': None}

        def cb(status):
            context['status'] = status

        st.on_status_change(cb)

        req = Request(Request.JSON, 'GET', 'http://www.bajoo.fr/')
        error = NetworkError()
        st.update(req, error)
        assert context['status'] is False

        st.update(req)
        assert context['status'] is True