ããã«ã¡ã¯ã ä¸ä¼.comã®éçºåºç¤ãæ å½ãã¦ãã¾ããakasakasã§ãã
ä»åã¯ãTavern ã¨ãã API Test ã©ã¤ãã©ãª ãç´¹ä»ãããã¨æãã¾ãã
- ä¸ä¼ã§API Test ãå¿ è¦ã«ãªã£ãèæ¯
- API Test ãå°å ¥ããä¸ã§èãããã¤ã³ã
- Tavernã®ãç´¹ä»
- Tavern ã®ããã¨ãã
- Tavern ã®å®éç¨ã«ã¾ã¤ããç´°ãã話
- ã¾ã¨ã
- åè
ä¸ä¼ã§API Test ãå¿ è¦ã«ãªã£ãèæ¯
ååã®ããã°ã§ãå°ã触ãã¾ããããAPIã®ãã¹ããç¡çããSeleniumã使ã£ã¦ãã¹ããç¶ããçµæãE2Eãç ´ç¶»ãã¾ããã
é©åãªã¬ã¤ã¤ã¼ã§é©åãªãã¹ãããããã¨ãããã¨ã§ãAPIã«é¢ãã¦ã¯ã¡ãã㨠API Test ã©ã¤ãã©ãª ã®å°å ¥ã決ãã¾ããã
API Test ãå°å ¥ããä¸ã§èãããã¤ã³ã
API Test ãå°å ¥ããä¸ã§èãããã¤ã³ãã¯ä»¥ä¸ã®ç¹ã§ãã
- éçºè ãã¬ã³ããªã¼
- CIé£æº
éçºè ãã¬ã³ããªã¼
ååã®ããã°ã§ãæ¸ãã¾ããããä¸ä¼ã§ã¯QAã»ãã¹ãã¨ã³ã¸ãã¢ã®ãããªãã¸ã·ã§ã³ã¯ããªãã®ã§ãéçºè ããã¹ããä¿®æ£ããããã«ãªã£ã¦ã¾ãã
éçºè ãæ°è»½ã«ãã¹ãã追å ã»ä¿®æ£ãããã¨ãã§ãããã㪠API Test ã©ã¤ãã©ãªãå¿ è¦ã ã¨èãã¾ããã
CIé£æº
ä¸ä¼ã§æ±ã£ã¦ããAPIã¯å¤é¨ã®ææºå ã«æä¾ãã¦ããAPIãå¤ãã§ãã
ãããªãªã¼ã¹å¾ãAPIã§é害ãçºçããå ´åãå¤é¨ã®ææºå ã«ãå½±é¿ãåã³ã¾ãã
ãªãªã¼ã¹åã®é害äºåæ¤ç¥ã®ãããæ¤è¨¼ç°å¢ã§å®æçã«API Testãæµãã¦ããªãªã¼ã¹å¾ã®é害ãé²ãããã§ãã
ãã®çºã«ã¯ãAPI Test ã CIã§åããããã«ããå¿ è¦ãããã¾ããã
Tavernã®ãç´¹ä»
ä¸è¨ã®è¦ä»¶ãæºãããAPI Test ã©ã¤ãã©ãªãæ¤è¨ããçµæãTavernã¨åºä¼ãã¾ããã
Tavern ã¯API Test ã«ç¹åãã PyTest ã®ãã©ã°ã¤ã³ã§ãã
ãã¹ãã¯YAMLã§è¨è¿°ã§ããã®ã§ãã·ã³ãã«ã§ãããããããã¡ã³ããã³ã¹ãç°¡åã§ãã®ã§ãéçºè ãã¬ã³ããªã¼ã§ããã¨æãã¾ããã
ã¾ããPyTestã®ãã©ã°ã¤ã³ã§ã³ãã³ãã©ã¤ã³ã§ãã¹ãã®å®è¡ãã§ããã®ã§ãCIé£æºãããããã§ãã
API Testã®ãã¼ã«ã§ããã¨ãPostmanãInsomniaãããã¾ãããGUIã¨ãã¦ä½¿ãã®ãä¸è¬çã§ãCIé£æºãé£ããã£ãã§ãï¼Postmanã®CLIã§Newmanã¨ããã®ãããã¾ããããã¹ãã®è¨è¿°ãTavernãããé£ããã¨æããã®ã§ãNewmanã®å°å ¥ãè¦éãã¾ããï¼ã
Tavern ã®ããã¨ãã
Tavern ã®ããã¨ããã¨ãã¦ã¯ä»¥ä¸ã®3ç¹ãããã¨æãã¾ãã
- YAMLã§ãã¹ããè¨è¿°ã§ãã
- åã®ãã¹ãã®çµæãä¿åã§ããã»æ¬¡ã®ãã¹ãã«ä½¿ãã
- CIé£æº
YAML ã§ãã¹ããè¨è¿°ã§ãã
Github API ãä¾ã«ã㦠Tavern ã使ã£ã¦ãAPI Test ããã¦ã¿ã¾ãããã
Tavern 㧠issue ãä½ãããã¨ã確èªãã¾ãã
https://developer.github.com/v3/issues/#create-an-issue
å ã«ãã¹ããããè¦ããã¾ã
test_name: Github API Test includes: - !include common.yaml stages: - name: Create Issue request: url: https://api.github.com/repos/{service.owner:s}/{service.repo:s}/issues headers: Authorization: "token {service.token:s}" method: POST json: title: "Issue From Tavern Test" body: "ä¸ä¼.comããå©ç¨é ããèª ã«ãããã¨ããããã¾ãã" response: status_code: 201 body: title: "{tavern.request_vars.json.title}" body: "{tavern.request_vars.json.body}" state: "open"
YAMLã§æ¸ããã¦ããã®ã§ãã©ããªãã¨ããã¦ããã®ãããªãã®ãã¹ãããã¦ããã®ããã¤ã¡ã¼ã¸ããããã¨æãã¾ãã
- request
- url ã§ãã¹ã対象ã®ã¨ã³ããã¤ã³ããæå®
- header 㧠Authorization Header ãè¨å®
- jsonã§ãã¹ããããã¼ã¿ãæå® etc
- reponse
- 201 ãè¿å´ããããã¨
- body ã®å 容ãrequestã®å 容ã¨ä¸è´ãã¦ãããã¨
ãªã©ãè¨è¿°ãã¦ãããã¨ããããã¾ãã
å ±éã®ãã¼ã¿ã¯ common.yaml ã§è¨è¿°ãã¦ãã¾ãã
common.yaml ã®å 容ã¨ãã¦ã¯ä»¥ä¸ã®ãããªã¤ã¡ã¼ã¸ã§ãã
description: used for github api testing name: test includes variables: service: token: "token" owner: "ãªãã¸ããªãªã¼ãã¼" repo: "ãªãã¸ããª"
ãã¹ãã®å®è¡ã¯
tavern-ci test_github.tavern.yaml
ã§ç¢ºèªã§ãã¾ãã
Tavern ã®ãä½æ³ã¨ãã¦ããã¹ããã¡ã¤ã«ã®yaml㯠test_*.tavern.yaml
ã¨ããå½¢ã§çµ±ä¸ãã¦ããããã§ãã
ãã¹ããéãã¾ããã
$ tavern-ci test_github.tavern.yaml ================================================== test session starts ================================================== platform darwin -- Python 3.6.1, pytest-4.3.0, py-1.8.0, pluggy-0.9.0 plugins: tavern-0.22.1 collected 1 item test_github.tavern.yaml . [100%] =============================================== 1 passed in 1.66 seconds ================================================
Tavern 㧠Github API ã使ã£ã¦ãissueãä½æãããã¨ãã§ãã¾ããã
åã®ãã¹ãã®çµæãä¿åã§ããã»æ¬¡ã®ãã¹ãã«ä½¿ãã
Tavern ã®ä¾¿å©ãªã¨ããã¨ãã¦ãåã®ãã¹ãã®çµæãä¿åãã¦ãããã次ã®ãã¹ãã«ä½¿ããã¨ãã§ããã¨ããã®ãããã¾ãã
Github API ã使ã£ã¦
- Issue ãä½æ
- Issue ã®çªå·ãåå¾
- ãã®çªå·ã®issueãç·¨éãã
ã¨ãããã¨ããã£ã¦ã¿ã¾ãããã
å ã«ãã¹ããããè¦ããã¾ã
test_name: Github API Test includes: - !include common.yaml stages: - name: Create Issue request: url: https://api.github.com/repos/{service.owner:s}/{service.repo:s}/issues headers: Authorization: "token {service.token:s}" method: POST json: title: "Issue From Tavern Test" body: "ä¸ä¼.comããå©ç¨é ããèª ã«ãããã¨ããããã¾ãã" response: status_code: 201 save: body: issue_id: number - name: Edit Issue request: url: https://api.github.com/repos/{service.owner:s}/{service.repo:s}/issues/{issue_id} headers: Authorization: "token {service.token:s}" method: PATCH json: title: "Edit Issue From Tavern" body: "ä¸ä¼ã¬ã¹ãã©ã³ããå©ç¨é ããèª ã«ãããã¨ããããã¾ãã" response: status_code: 200 body: state: "open"
- Create issue ã®response body 㧠issue_id ã save
- Edit Issue ã® request url 㧠issue_id ã使ã£ã¦ããã¹ã
ã¨ãããã¨ããã£ã¦ãã¾ãã
Tavern 㧠Github API ã使ã£ã¦ãissueã®ä½æã¨ç·¨éããããã¨ãã§ãã¾ããã
CIé£æº
tavern ã®ã¤ã³ã¹ãã¼ã«èªä½ã¯ã pip install tavern
ã®ã¿ã§æ¸ã¿ã¾ããã
ãã¹ãã®å®è¡èªä½ã tavern-ci test_*.tavern.yaml
ã§æ¸ãã®ã§ãCIé£æºã容æã§ãã
Tavern ã®å®éç¨ã«ã¾ã¤ããç´°ãã話
Tavern ã®å®éç¨ã«ã¾ã¤ããç´°ãã話ã¨ãã¦ã¯
- ç°å¢å¥ã®ãã¹ããã¼ã¿ã®è¨å®
ãæ°ã«ãªãã¨ãããªã®ããªã¨æãã¾ãã
ããã«é¢ãã¦ã¯ã
https://tavern.readthedocs.io/en/latest/basics.html?#multiple-global-configuration-files
ã«æ¸ãã¦ããã¾ãããåç°å¢å¥ã§ä½¿ãYAML ãç¨æãã¾ãã
ã¾ã¨ã
ä»åã¯ã Tavern ã使ã£ãAPI Test ã«ã¤ãã¦ç´¹ä»ãã¾ããã
ãAPI Test ã©ã¤ãã©ãªã¨ããã°ãã³ã¬ã ï¼ãã¨ãããã®ããªãå°è±¡ã§ãããã
- ãã¹ãã YAML ã§è¨è¿°ã§ãã¦ãã¤ã¡ã¼ã¸ãããã
- CIé£æºã®å®¹æ
ã¨ããç¹ã§ã Tavern ã¯é¸æè¢ã®ä¸ã¤ã¨ãã¦ã¢ãªãªã®ããªã¨æãã¾ããã