File: test_server.py

package info (click to toggle)
flask-openapi3 4.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,976 kB
  • sloc: python: 4,754; sh: 17; makefile: 15; javascript: 5
file content (43 lines) | stat: -rw-r--r-- 1,056 bytes parent folder | download
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
# -*- coding: utf-8 -*-
# @Author  : llc
# @Time    : 2024/11/10 12:17
from pydantic import ValidationError

from flask_openapi3 import Server, ServerVariable


def test_server_variable():
    Server(
        url="http://127.0.0.1:5000",
        variables=None
    )
    try:
        variables = {"one": ServerVariable(default="one", enum=[])}
        Server(
            url="http://127.0.0.1:5000",
            variables=variables
        )
        error = 0
    except ValidationError:
        error = 1
    assert error == 1
    try:
        variables = {"one": ServerVariable(default="one")}
        Server(
            url="http://127.0.0.1:5000",
            variables=variables
        )
        error = 0
    except ValidationError:
        error = 1
    assert error == 0
    try:
        variables = {"one": ServerVariable(default="one", enum=["one", "two"])}
        Server(
            url="http://127.0.0.1:5000",
            variables=variables
        )
        error = 0
    except ValidationError:
        error = 1
    assert error == 0