Closed akakou closed 4 years ago
本来はrailsのtestを使ってほしい感じはあるけど、 pythonのrequestsを利用してもよろし。
流れとしては、以下の流れでよろしく
コードと、結果(コメント)で、ここのissueに貼り付けてほしいわん
出力
$ python apitest.py
========= create a new user test =========
name = makino
email: makino@example.com
phone: 0123456789
password: password
ok. 200
{'status': 'success', 'data': {'id': 1, 'provider': 'email', 'uid': 'makino@example.com', 'allow_password_change': False, 'name': 'makino', 'bio': None, 'phone': '0123456789', 'email': 'makino@example.com', 'icon': None, 'created_at': '2019-11-22T23:49:46.000Z', 'updated_at': '2019-11-22T23:49:46.000Z'}}
name = akama
email: akama@example.com
phone: 9876543210
password: password
ok. 200
{'status': 'success', 'data': {'id': 2, 'provider': 'email', 'uid': 'akama@example.com', 'allow_password_change': False, 'name': 'akama', 'bio': None, 'phone': '9876543210', 'email': 'akama@example.com', 'icon': None, 'created_at': '2019-11-22T23:49:47.000Z', 'updated_at': '2019-11-22T23:49:47.000Z'}}
========= users index test =========
users index
ok. 200
[{'id': 1, 'name': 'makino', 'bio': None, 'icon': None, 'evaluation': 1.0}, {'id': 2, 'name': 'akama', 'bio': None, 'icon': None, 'evaluation': 1.0}]
========= a user test =========
id = 1: ok. 200
{'id': 1, 'name': 'makino', 'bio': None, 'icon': None, 'evaluation': 1.0}
========= new follow test =========
follow from 1 to 2: ok. 201
{'id': 1, 'from_id': 1, 'to_id': 2, 'url': 'http://localhost:3000/followings/1.json'}
follow from 2 to 1: ok. 201
{'id': 2, 'from_id': 2, 'to_id': 1, 'url': 'http://localhost:3000/followings/2.json'}
========= duplicated follow test =========
follow from 1 to 2: refused. 400
{'id': 1, 'from_id': 1, 'to_id': 2, 'url': 'http://localhost:3000/followings/1.json'}
========= followings test =========
followers of user 1: ok. 200
[{'id': 2, 'name': 'akama', 'bio': None, 'icon': None, 'evaluation': 1.0}]
followees of user 1: ok. 200
[{'id': 2, 'name': 'akama', 'bio': None, 'icon': None, 'evaluation': 1.0}]
========= create a new post test =========
content=hogehoge: ok. 201
{'id': 1, 'user_id': 1, 'content': 'hogehoge', 'source_id': None, 'created_at': '2019-11-22T23:49:51.000Z', 'updated_at': '2019-11-22T23:49:51.000Z', 'evaluation': 1.0, 'url': 'http://localhost:3000/posts/1.json'}
content=fugafuga: ok. 201
{'id': 2, 'user_id': 1, 'content': 'fugafuga', 'source_id': None, 'created_at': '2019-11-22T23:49:52.000Z', 'updated_at': '2019-11-22T23:49:52.000Z', 'evaluation': 1.0, 'url': 'http://localhost:3000/posts/2.json'}
~~ this is reply ~~
content=@makino @akama fugifugi: ok. 201
{'id': 3, 'user_id': 1, 'content': '@makino @akama fugifugi', 'source_id': None, 'created_at': '2019-11-22T23:49:52.000Z', 'updated_at': '2019-11-22T23:49:52.000Z', 'evaluation': 1.0, 'url': 'http://localhost:3000/posts/3.json'}
========= create a new retweet =========
source id=1: ok. 201
{'id': 4, 'user_id': 1, 'content': '', 'source_id': 1, 'created_at': '2019-11-22T23:49:53.000Z', 'updated_at': '2019-11-22T23:49:53.000Z', 'evaluation': 1.0, 'url': 'http://localhost:3000/posts/4.json'}
========= posts index test =========
index: ok. 200
[{'id': 4, 'user_id': 1, 'content': '', 'source_id': 1, 'created_at': '2019-11-22T23:49:53.000Z', 'updated_at': '2019-11-22T23:49:53.000Z', 'evaluation': 1.0}, {'id': 3, 'user_id': 1, 'content': '@makino @akama fugifugi', 'source_id': None, 'created_at': '2019-11-22T23:49:52.000Z', 'updated_at': '2019-11-22T23:49:52.000Z', 'evaluation': 1.0}, {'id': 2, 'user_id': 1, 'content': 'fugafuga', 'source_id': None, 'created_at': '2019-11-22T23:49:52.000Z', 'updated_at': '2019-11-22T23:49:52.000Z', 'evaluation': 1.0}, {'id': 1, 'user_id': 1, 'content': 'hogehoge', 'source_id': None, 'created_at': '2019-11-22T23:49:51.000Z', 'updated_at': '2019-11-22T23:49:51.000Z', 'evaluation': 1.0}]
index(numbers = 2): ok. 200
[{'id': 4, 'user_id': 1, 'content': '', 'source_id': 1, 'created_at': '2019-11-22T23:49:53.000Z', 'updated_at': '2019-11-22T23:49:53.000Z', 'evaluation': 1.0}, {'id': 3, 'user_id': 1, 'content': '@makino @akama fugifugi', 'source_id': None, 'created_at': '2019-11-22T23:49:52.000Z', 'updated_at': '2019-11-22T23:49:52.000Z', 'evaluation': 1.0}]
========= a post test =========
id = 1: ok. 200
{'id': 1, 'user_id': 1, 'content': 'hogehoge', 'source_id': None, 'created_at': '2019-11-22T23:49:51.000Z', 'updated_at': '2019-11-22T23:49:51.000Z', 'evaluation': 1.0, 'url': 'http://localhost:3000/posts/1.json'}
========= create new evaluation test =========
evaluate post 1: ok. 201
{'id': 1, 'user_id': 1, 'post_id': 1, 'is_positive': True, 'created_at': '2019-11-22T23:49:55.000Z', 'updated_at': '2019-11-22T23:49:55.000Z', 'url': 'http://localhost:3000/evaluations/1.json'}
evaluate post 2: ok. 201
{'id': 2, 'user_id': 1, 'post_id': 2, 'is_positive': False, 'created_at': '2019-11-22T23:49:56.000Z', 'updated_at': '2019-11-22T23:49:56.000Z', 'url': 'http://localhost:3000/evaluations/2.json'}
========= duplicated evaluation test =========
evaluate post 1: 400
{'id': 1, 'user_id': 1, 'post_id': 1, 'is_positive': True, 'created_at': '2019-11-22T23:49:55.000Z', 'updated_at': '2019-11-22T23:49:55.000Z', 'url': 'http://localhost:3000/evaluations/1.json'}
========= notifications test =========
ok. 200
[{'id': 4, 'type': 'retweeted', 'updated_at': '2019-11-22T23:49:53.000Z', 'post': {'id': 4, 'user_id': 1, 'content': '', 'evaluation': 1.0}}, {'id': 3, 'type': 'replied', 'updated_at': '2019-11-22T23:49:52.000Z', 'post': {'id': 3, 'user_id': 1, 'content': '@makino @akama fugifugi', 'evaluation': 1.0}}, {'id': 2, 'type': 'followed', 'updated_at': '2019-11-22T23:49:49.000Z', 'user': {'id': 2, 'name': 'akama', 'bio': None, 'icon': None, 'evaluation': 1.0}}]
========= --- finished --- =========
secceeded: 20
failed: 0
バックエンド側のテストを書く。 方法は問わないが、再現性があること保証してほしい。