HTTP DSL Test Tool
Project description
Natume is a http dsl test tool help you easily build test for mobile application.
How to install
Firstly download or fetch it form github then run the command in shell:
cd natume # the path to the project
python setup.py install
Development
Fork or download it, then run:
cd natume # the path to the project
python setup.py develop
Compatibility
Built and tested under Python 2.7
How to write your dsl http test
The dsl rule most like ini file format.
comment
The line begins with “#” is a comment line
method section
The line begins with a [ and ends with ] a test method section:
[add friend] # comment > POST /request fid=1233 access_token="Blabla" code: 200 content <- OK
intialize your test instance variables
You can intialize or bind the variables use intialize method:
[intialize] @key = "key" @page = 2
All key begins with “@” will build to testcase instance attributes, like @key is compiled to “self.key”, and intialize method is called in SetUp method.
http send command
The line begins with > is a http request:
> GET /post key="Blabla" page=1 > POST /profile name="Blabla" email="e@e.com"
set request header
Sometimes, the request requires to set headers, you can use “=>” command to set header
referer => https://www.example.com/ Referer => https://www.example.com/ Accept-Encoding => gzip, deflate, sdch Accept_encoding => gzip, deflate, sdch
Assert the response
Currently, supports content regex match assert, json data assert, and response header assert. and supports three assert tokens.
:
“”:”” assert token, it is compiled to assertEqual method, to check a header or response text, or response json data:
code: 200 content_tpye : application/json charset: utf-8
<-
it is compiled to assertIn method in response content test:
content <- OK json <- ['data']['title'] = "Blabla"
=~
it is compiled to to check a regex text in response content test, the regex value must begins and ends with “/”, and can combine with the regex options:
content =~ /OK/ json =~ ['data']['title'] = /Blabla/i
Test response header info
When set code command:
code: 200
it will assert response status code.
When set content_type command:
content_tpye : application/json
it will assert response content_type.
When set charset command:
charset: utf-8
it will assert response charset.
content
when we test the response text, supports the commands as below:
content: OK content <- OK content =~ /Ok/i
json
When we test the response is json data, we can use json key to assert:
json <- ['data']['title'] = 'title' json: ['data']['trackList'][0]['song_id'] = '1772167572' json: ['data']['type_id'] = 1 # date size json ~~ ['data'] = 56
DSLWebTestCase
When you wanna write the dsl test in unittest testcase, please write test method in testcase class doc:
from natume import DSLWebTestCase, WebClient
import unittest
class DSLWebTestCaseTest(DSLWebTestCase):
u"""
[index]
> GET /
content <- 虾米音乐网(xiami.com)
[song api]
> GET /song/playlist/id/1772167572/type/0/cat/json
content_type: application/json
charset: utf-8
json: ['data']['trackList'][0]['title'] = u'再遇见'
json: ['data']['trackList'][0]['song_id'] = '1772167572'
json: ['data']['type_id'] = 1
[search]
> GET /search/collect key='苏打绿'
code: 200
content <- 苏打绿歌曲: 最好听的苏打绿音乐试听
content =~ /Xiami.com/i
[search page 2]
> GET /search/collect/page/2 key=@key order='weight'
code: 200
content <- 苏打绿歌曲: 最好听的苏打绿音乐试听
content =~ /XiaMi.com/i
"""
@classmethod
def setUpClass(self):
self.client = WebClient('http://www.xiami.com')
self.key = '苏打绿'
def test_t(self):
self.t(u"""
> GET /search/collect/page/2 key=@key order='weight'
code: 200
content <- 苏打绿歌曲: 最好听的苏打绿音乐试听
""")
You can also use t method to build request section test.
Run test in terminal
Like unittest, natume can run in terminal also, can test directories and files.
Here are the demos, the test file in project examples directory:
$ python -m natume -u http://www.xiami.com examples/xiami.smoke -d
test_index (__builtin__.XiamiTest) ... ok
test_search (__builtin__.XiamiTest) ... ok
test_search_page_2 (__builtin__.XiamiTest) ... ok
test_song_api (__builtin__.XiamiTest) ... ok
----------------------------------------------------------------------
Ran 4 tests in 0.674s
OK
$ python -m natume -u http://www.xiami.com examples -d
test_index (__builtin__.XiamiTest) ... ok
test_search (__builtin__.XiamiTest) ... ok
test_search_page_2 (__builtin__.XiamiTest) ... ok
test_song_api (__builtin__.XiamiTest) ... ok
----------------------------------------------------------------------
Ran 8 tests in 2.893s
OK
LICENSE
Copyright (C) 2015 Thomas Huang
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2 of the License.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
File details
Details for the file Natume-0.1.0.zip
.
File metadata
- Download URL: Natume-0.1.0.zip
- Upload date:
- Size: 26.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e9446df460c92733250e3041bf32147e555513731c2d07d90867090880adbeb3 |
|
MD5 | 7ed68f0223e7b3024ccf6aa68f5ce201 |
|
BLAKE2b-256 | 10c785fd4434537b9dbca5816474d5b6e7b69c3383dd081744f5dde3f3b874a5 |
File details
Details for the file Natume-0.1.0.tar.gz
.
File metadata
- Download URL: Natume-0.1.0.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cbad3a545e588ebf46e90145ced02999eb4ab1c074c007650088065cc955be30 |
|
MD5 | dce903ecceded8ac766c67bd84a9f5f3 |
|
BLAKE2b-256 | e81850e356da783ab39972e9d5a923e89374775522f880e5dd7a3c73c287a58f |