-
Notifications
You must be signed in to change notification settings - Fork 4
/
test_flask_reggie.py
43 lines (31 loc) · 1.01 KB
/
test_flask_reggie.py
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
41
42
43
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import unittest
import flask
from flask import Flask, request
from flask_reggie import Reggie
def create_app():
if "0.8" in flask.__version__:
return Flask('test_flask_reggie')
return Flask('test-flask-reggie')
class FlaskReggieTestCase(unittest.TestCase):
def setUp(self):
""" Construct our Flask Test App """
self.app = create_app()
reggie = Reggie()
reggie.init_app(self.app)
@self.app.route('/<regex("[abc0-9]{1,3}"):test>')
def index(test):
return "ok"
self.client = self.app.test_client()
def test_valid_pattern(self):
with self.app.test_client() as c:
rv = c.get('/ab1')
assert rv.data == "ok"
assert request.view_args['test'] == "ab1"
def test_invalid_pattern(self):
with self.app.test_client() as c:
rv = c.get('/ad1')
assert rv.status_code == 404
if __name__ == '__main__':
unittest.main()