def test_login_logout(self):
        c = TestClient()
        provider_key = 'unit'
        provider = settings.SANCTION_PROVIDERS[provider_key]

        # login redirect to provider
        resp = c.get('/o/login/{}/'.format(provider_key))
        rloc = urlparse(resp._headers['location'][1])
        query = dict(parse_qsl(rloc.query))
        self.assertTrue('state' in query)
        self.assertEquals('{}://{}{}'.format(rloc.scheme, rloc.netloc,
            rloc.path), provider['auth_endpoint'])

        # test login with code
        resp = c.get('/o/login/{}/?code=foo&state={}'.format(provider_key,
            query['state']))
        self.assertEquals(resp.status_code, 302)
        self.assertTrue('sessionid' in resp.cookies)

        # user's already logged in? should be redirected directly to their
        # profile
        resp = c.get('/o/login/{}/'.format(provider_key))
        self.assertEquals(resp.status_code, 302)
        rloc = urlparse(resp._headers['location'][1])
        self.assertEquals(rloc.path, settings.LOGIN_REDIRECT_URL)

        # test logout
        resp = c.get('/o/logout/')
        self.assertEquals(resp.status_code, 302)
        rloc = urlparse(resp._headers['location'][1])
        self.assertEquals(rloc.path, settings.LOGIN_URL)
dataset/ETHPy150Open demianbrecht/django-sanction/django_sanction/tests.py/TestViews.test_login_logout/original