-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_index.py
66 lines (55 loc) · 1.73 KB
/
test_index.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from selenium import webdriver
import requests
import pytest
import json
import jsonschema
# 200 status code OK
def test_get_status():
user_id = 2
response = requests.get(f'https://reqres.in/api/users/{user_id}')
assert response.status_code == 200
# 404 status code Not Found
def test_get_user_negative():
user_id = 22134124234
response = requests.get(f'https://reqres.in/api/users/{user_id}')
assert response.status_code == 404
# Validate json schema
def get_user_data(user_id):
response = requests.get(f'https://reqres.in/api/users/{user_id}')
return response.json()['data']
# Validar el esquema de la respuesta JSON
def test_get_user_data_schema():
user_id = 2
user_data = get_user_data(user_id)
schema = {
"type": "object",
"properties": {
"id": {"type": "integer"},
"email": {"type": "string"},
"first_name": {"type": "string"},
"last_name": {"type": "string"},
"avatar": {"type": "string"}
},
"required": ["id", "email", "first_name", "last_name", "avatar"]
}
try:
jsonschema.validate(instance=user_data, schema=schema)
assert True
except jsonschema.ValidationError:
assert False
# Logic on python
def is_balanced(string):
stack = []
mapping = {')': '(', ']': '['}
for char in string:
if char in mapping.values():
stack.append(char)
elif char in mapping.keys():
if not stack or stack[-1] != mapping[char]:
return False
stack.pop()
return not stack
print(is_balanced("(abc")) # False
print(is_balanced(")abc)")) # False
print(is_balanced("(a[b)c]d")) # False
print(is_balanced("(a[b]c)")) # True