-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_4_p45_test.py
56 lines (41 loc) · 1.31 KB
/
1_4_p45_test.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
"""1つのテストメソッドでは1つの項目のみ確認する
https://rinatz.github.io/python-book/ch08-02-pytest/
"""
def validate(text):
return 0 < len(text) <= 100
import pytest
class TestValidate:
@pytest.mark.parametrize("text", ["a", "a" * 50, "a" * 100])
def test_valid(self, text):
# 検証が正しい場合
assert validate(text)
@pytest.mark.parametrize("text", ["", "a" * 101])
def test_invalid(self, text):
assert not validate(text)
"""テストケースは準備、実行、検証に分割する
"""
class TestSignupAPIView:
@pytest.fixture
def target_api(self):
return "/api/signup"
def test_do_signup(self, target_api, django_app):
# 準備 ---
from account.models import User
params = {
"email": "[email protected]",
"name": "yamadataro",
"password": "xxxxxxxx",
}
# 実行 ---
res = django_app.post_json(target_api, params=params)
# 検証 ---
user = User.objects.all()[0]
expected = {
"status_code": 201,
"user_email": "[email protected]",
}
actual = {
"status_code": res.status_code,
"user_email": user.email,
}
assert expected == actual