def test_replicated_middleware_force_state_by_header(client):
    response = client.get('/', **{settings.REPLICATED_FORCE_STATE_HEADER: 'master'})

    assert response.status_code == 302
    assert routers.state() == 'master'

    response = client.post('/', **{settings.REPLICATED_FORCE_STATE_HEADER: 'slave'})

    assert response.status_code == 302
    assert routers.state() == 'slave'
Ejemplo n.º 2
0
def test_replicated_middleware_force_state_by_header(client):
    response = client.get('/',
                          **{settings.REPLICATED_FORCE_STATE_HEADER: 'master'})

    assert response.status_code == 302
    assert routers.state() == 'master'

    response = client.post('/',
                           **{settings.REPLICATED_FORCE_STATE_HEADER: 'slave'})

    assert response.status_code == 302
    assert routers.state() == 'slave'
Ejemplo n.º 3
0
def test_replicated_middleware_master_state(client):
    client.post('/')

    assert routers.state() == 'master'

    assert client.cookies[
        settings.REPLICATED_FORCE_MASTER_COOKIE_NAME].value == 'true'
def test_replicated_middleware_master_state(client):
    response = client.post('/')
    assert response['Router-Used'] == 'master'

    assert routers.state() == 'master'

    assert client.cookies[settings.REPLICATED_FORCE_MASTER_COOKIE_NAME].value == 'true'
def test_replicated_middleware_view_overrides(client, settings, url, view_id):
    routers.init('slave')

    settings.REPLICATED_VIEWS_OVERRIDES = {view_id: 'master'}

    response = client.get(url)

    assert response.status_code == 302
    assert routers.state() == 'master'
Ejemplo n.º 6
0
def test_replicated_middleware_view_overrides(client, settings, url, view_id):
    routers.init('slave')

    settings.REPLICATED_VIEWS_OVERRIDES = {view_id: 'master'}

    response = client.get(url)

    assert response.status_code == 302
    assert routers.state() == 'master'
def test_user_state_decorator():
    factory = RequestFactory()
    request = factory.get('/')

    def _view(request):
        return HttpResponse()

    use_state('master')(_view)(request)

    assert routers.state() == 'master'
Ejemplo n.º 8
0
    def handle_redirect_after_write(self, request, response):
        '''
        Sets a flag using cookies to redirect requests happening after
        successful write operations to ensure that corresponding read
        request will use master database. This avoids situation when
        replicas lagging behind on updates a little.

        (AirOne)
        The original deletes the cookie on the second GET request.
        Changed to retain cookies as replication may be delayed.
        Also, I changed to set a cookie after connecting to MasterDB
        even if it is not a redirect. After the number of seconds specified
        by MAX_AGE has elapsed, it will be deleted on the browser side.
        '''

        if routers.state() == 'master':
            log.debug('set force master cookie for %s', request.path)
            self.set_force_master_cookie(response)
Ejemplo n.º 9
0
def test_replicated_middleware_slave_state(client, method):
    response = client.generic(method, '/')
    assert response['Router-Used'] == 'slave'

    # Router state is reset to 'master' after request is processed
    assert routers.state() == 'master'
Ejemplo n.º 10
0
def get_response():
    response = HttpResponseRedirect('/')
    response['Router-Used'] = routers.state()
    response['DB-Used'] = routers.db_for_read()
    return response
Ejemplo n.º 11
0
def test_replicated_middleware_slave_state(client, method):
    client.generic(method, '/')

    assert routers.state() == 'slave'
Ejemplo n.º 12
0
def test_replicated_middleware_slave_state(client, method):
    client.generic(method, '/')

    assert routers.state() == 'slave'
Ejemplo n.º 13
0
def use_master_simple_context_manager():
    with use_master_simple:
        return routers.state()
Ejemplo n.º 14
0
def use_master_simple_decorator():
    return routers.state()
Ejemplo n.º 15
0
def use_slave_simple_decorator():
    return routers.state()
Ejemplo n.º 16
0
def get_response():
    response = HttpResponseRedirect('/')
    response['Router-Used'] = routers.state()
    response['DB-Used'] = routers.db_for_read()
    return response
def test_replicated_middleware_slave_state(client, method):
    response = client.generic(method, '/')
    assert response['Router-Used'] == 'slave'

    # Router state is reset to 'master' after request is processed
    assert routers.state() == 'master'