def test_token_by_user_credentials(self):

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

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

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

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

        # Missing params.
        resp = self.client.post(URL_TOKEN, {'grant_type': 'password', 'scope': 'scope1'},
                                Authorization='Basic T0NsaWVudDpjbDAxMjM0NQ==')
        self.assertEqual(resp.status_code, 400)
        self.assertEqual(resp.content_json['error'], 'invalid_request')

        # Invalid params.
        resp = self.client.post(
            URL_TOKEN, {
                'grant_type': 'password', 'scope': 'scope1', 'username': 'FalseUser', 'password': 'FalsePassword'
            },
            Authorization='Basic T0NsaWVudDpjbDAxMjM0NQ==')
        self.assertEqual(resp.status_code, 400)
        self.assertEqual(resp.content_json['error'], 'invalid_grant')

        # Valid token by password request.
        resp = self.client.post(
            URL_TOKEN, {'grant_type': 'password', 'scope': 'scope1', 'username': 'Fred', 'password': '12345'},
            Authorization='Basic T0NsaWVudDpjbDAxMjM0NQ==')

        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)
        self.assertFalse('expires_in' in resp.content_json)
dataset/ETHPy150Open idlesign/django-oauthost/oauthost/tests.py/GrantsCheck.test_token_by_user_credentials/original