<commit_before># -*- coding: utf-8 -*-
"""
    tests.test_jwt
    ~~~~~~~~~~~~~~

    Flask-JWT tests
"""
import os
import time

from flask import Flask, json

import flask_jwt


def assert_error_response(r, code, msg, desc):
    jdata = json.loads(r.data)
    assert r.status_code == code
    assert jdata['status_code'] == code
    assert jdata['error'] == msg
    assert jdata['description'] == desc


def test_initialize():
    app = Flask(__name__)
    app.config['SECRET_KEY'] = 'super-secret'
    jwt = flask_jwt.JWT(app)
    assert isinstance(jwt, flask_jwt.JWT)
    assert len(app.url_map._rules) == 1


def test_adds_auth_endpoint():
    app = Flask(__name__)
    app.config['SECRET_KEY'] = 'super-secret'
    app.config['JWT_AUTH_URL_RULE'] = '/auth'
    app.config['JWT_AUTH_ENDPOINT'] = 'jwt_auth'
    flask_jwt.JWT(app)
    rules = [str(r) for r in app.url_map._rules]
    assert '/auth' in rules


def test_auth_endpoint_with_valid_request(client):
    r = client.post(
        '/auth',
        headers={'content-type': 'application/json'},
        data=json.dumps({
            'username': 'joe',
            'password': '<PASSWORD>'
        }))
    assert r.status_code == 200
    assert 'token' in json.loads(r.data)


def test_auth_endpoint_with_invalid_request(client):
    # Invalid request
    r = client.post(
        '/auth',
        headers={'content-type': 'application/json'},
        data=json.dumps({<commit_msg>Fix initialize test<commit_after># -*- coding: utf-8 -*-
"""
    tests.test_jwt
    ~~~~~~~~~~~~~~

    Flask-JWT tests
"""
import os
import time

from flask import Flask, json

import flask_jwt


def assert_error_response(r, code, msg, desc):
    jdata = json.loads(r.data)
    assert r.status_code == code
    assert jdata['status_code'] == code
    assert jdata['error'] == msg
    assert jdata['description'] == desc


def test_initialize():
    app = Flask(__name__)
    app.config['SECRET_KEY'] = 'super-secret'
    jwt = flask_jwt.JWT(app)
    assert isinstance(jwt, flask_jwt.JWT)
    assert len(app.url_map._rules) == 2


def test_adds_auth_endpoint():
    app = Flask(__name__)
    app.config['SECRET_KEY'] = 'super-secret'
    app.config['JWT_AUTH_URL_RULE'] = '/auth'
    app.config['JWT_AUTH_ENDPOINT'] = 'jwt_auth'
    flask_jwt.JWT(app)
    rules = [str(r) for r in app.url_map._rules]
    assert '/auth' in rules


def test_auth_endpoint_with_valid_request(client):
    r = client.post(
        '/auth',
        headers={'content-type': 'application/json'},
        data=json.dumps({
            'username': 'joe',
            'password': '<PASSWORD>'
        }))
    assert r.status_code == 200
    assert 'token' in json.loads(r.data)


def test_auth_endpoint_with_invalid_request(client):
    # Invalid request
    r = client.post(
        '/auth',
        headers={'content-type': 'application/json'},
        data=json.dumps({
{'fraction_non_alphanumeric': 0.15027700831024932, 'fraction_numerical': 0.0034626038781163434, 'mean_word_length': 3.0632911392405062, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6493580', 'n_tokens_mistral': 1015, 'n_tokens_neox': 992, 'n_words': 201}