|
import pytest |
|
import json |
|
|
|
from extract import extract |
|
|
|
def test_pure_string(): |
|
inp = 'abc' |
|
token, user, redirect, info = extract(inp) |
|
assert token == inp |
|
assert user is None |
|
assert redirect is None |
|
assert info is None |
|
|
|
def test_json_format_01(): |
|
inp_s = '{"a":"b"}' |
|
token, user, redirect, info = extract(inp_s) |
|
inp = json.loads(inp_s) |
|
assert token == None |
|
assert user == None |
|
assert redirect is None |
|
assert info == inp |
|
|
|
def test_json_format_02(): |
|
inp_s = '{"token":"b"}' |
|
token, user, redirect, info = extract(inp_s) |
|
inp = json.loads(inp_s) |
|
assert token == inp['token'] |
|
assert user == None |
|
assert redirect is None |
|
assert info == inp |
|
|
|
def test_json_format_03(): |
|
inp_s = '{"user":"xb"}' |
|
token, user, redirect, info = extract(inp_s) |
|
inp = json.loads(inp_s) |
|
assert token == None |
|
assert user == inp['user'] |
|
assert redirect is None |
|
assert info == inp |
|
|
|
def test_json_format_04(): |
|
inp_s = '{"user":"t1", "token":"t2"}' |
|
token, user, redirect, info = extract(inp_s) |
|
inp = json.loads(inp_s) |
|
assert token == inp['token'] |
|
assert user == inp['user'] |
|
assert redirect is None |
|
assert info == inp |
|
|
|
def test_json_format_05(): |
|
inp_s = '{"user":"t1", "token":"t2", "redirect":"xx"}' |
|
token, user, redirect, info = extract(inp_s) |
|
inp = json.loads(inp_s) |
|
assert token == inp['token'] |
|
assert user == inp['user'] |
|
assert redirect == inp['redirect'] |
|
assert info == inp |
|
|