def test_authorization_code_unsafe(self):

        user_1 = User(username='Fred')
        user_1.set_password('12345')
        user_1.save()

        client_1 = Client(user=user_1, title='OClient')
        client_1.save()

        redirect_1 = RedirectionEndpoint(client=client_1, uri='http://redirect-test.com')
        redirect_1.save()

        Scope(identifier='scope1').save()

        # Logging the user in.
        self.client.login(username='Fred', password='12345')

        # Valid code request.
        resp = self.client.get(URL_AUTHORIZE, {'response_type': 'code', 'scope': 'scope1',
                                               'client_id': client_1.identifier})
        self.assertEqual(resp.status_code, 200)

        # User confirms auth.
        resp = self.client.post(URL_AUTHORIZE, {'auth_decision': 'is_made', 'confirmed': 'yes'})
        self.assertEqual(resp.status_code, 302)
        params = parse_location_header(resp)
        self.assertIn('code', params)

        # Auth code given.
        code = params['code']

        # Valid token by code request.
        resp = self.client.post(URL_TOKEN, {'grant_type': 'authorization_code', 'scope': 'scope1', 'code': code,
                                            'redirect_uri': redirect_1.uri,
                                            'client_id': client_1.identifier,
                                            'client_secret': client_1.password})

        self.assertEqual(resp.status_code, 200)
        self.assertTrue('access_token' in resp.content_json)
        self.assertTrue('refresh_token' in resp.content_json)
        self.assertTrue('token_type' in resp.content_json)
dataset/ETHPy150Open idlesign/django-oauthost/oauthost/tests.py/GrantsCheck.test_authorization_code_unsafe/original