File: test_app.py

package info (click to toggle)
flask-jwt-simple 0.0.3-14
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 288 kB
  • sloc: python: 772; makefile: 194; sh: 6
file content (40 lines) | stat: -rw-r--r-- 888 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import pytest

from flask import Flask, jsonify, request
from flask_jwt_simple import (
    JWTManager, jwt_required, create_jwt, get_jwt_identity
)

app = Flask(__name__)

app.config['JWT_SECRET_KEY'] = 'super-secret'
jwt = JWTManager(app)


@app.route('/unprotected', methods=['GET'])
def unprotected():
    return 'ok', 200


@app.route('/protected', methods=['GET'])
@jwt_required
def protected():
    return jsonify({'msg': 'ok'}), 200

@pytest.fixture
def client():
    app.config['TESTING'] = True
    with app.test_client() as client:
        yield client

def test_unprotected(client):
    resp = client.get('/unprotected')
    assert b'ok' in resp.data
    assert 200 == resp.status_code


def test_protected_without_authorization(client):
    resp = client.get('/protected')
    assert b'{"msg":"Missing Authorization Header"}' in resp.data
    assert 401 == resp.status_code