jharmn / api-bdd-tests Goto Github PK
View Code? Open in Web Editor NEWAn example of performing BDD-based testing on APIs
An example of performing BDD-based testing on APIs
$ lettuce
Feature: Bitly link shortener # features/link-shortener.feature:1
@Positive @Oauth @Bitly @User # features/link-shortener.feature:3
@Positive @Oauth @Bitly @User
Scenario: Get access token # features/link-shortener.feature:4
Given I use the bitly host # features/steps/steps_requests.py:6
When I access the resource url "/oauth/access_token" # features/steps/steps_requests.py:11
And I provide authentication credentials # features/steps/steps_requests.py:15
And I post to the url # features/steps/steps_requests.py:40
Then the status code should be 200 # features/steps/steps_requests.py:44
And the results should be saved as "access_token" for later # features/steps/steps_values.py:20
@Positive @User @Bitly
Scenario: Get user info # features/link-shortener.feature:13
Given i use the bitly host # features/steps/steps_requests.py:6
When I access the resource url "/v3/user/info" # features/steps/steps_requests.py:11
And I provide parameter "access_token" as the value "access_token" # features/steps/steps_requests.py:27
And I retrieve the JSON results # features/steps/steps_requests.py:31
Then the status code should be 200 # features/steps/steps_requests.py:44
And it should have the field "status_code" containing the value 200 # features/steps/steps_values.py:16
Feature: Geonames nearby place name # features/nearby-place-declarative.feature:1
@Get @Positive @Nearby @Declarative # features/nearby-place-declarative.feature:3
@Get @Positive @Nearby @Declarative
Scenario: Get nearby place name# features/nearby-place-declarative.feature:4
Given I use the geonames host # features/steps/steps_requests.py:6
When I use the "Find Nearby Place by JSON" endpoint # features/steps/steps_declarative.py:4
And I identify my "geonames" user credentials # features/steps/steps_declarative.py:8
And I provide coordinates 30.4754724, -98.1564068 # features/steps/steps_declarative.py:12
And I retrieve the JSON results # features/steps/steps_requests.py:31
Then it should have at least 1 valid "geonames" item # features/steps/steps_declarative.py:17
Traceback (most recent call last):
File "/Users/julianpistorius/.venvs/api-bdd-tests/lib/python2.7/site-packages/lettuce/core.py", line 143, in __call__
ret = self.function(self.step, *args, **kw)
File "/Users/julianpistorius/git/api-bdd-tests/features/steps/steps_declarative.py", line 18, in then_it_should_have_at_least_valid_result
step.then('it should have a list "%s"' % (name))
File "/Users/julianpistorius/.venvs/api-bdd-tests/lib/python2.7/site-packages/lettuce/core.py", line 368, in then
return self.behave_as(string)
File "/Users/julianpistorius/.venvs/api-bdd-tests/lib/python2.7/site-packages/lettuce/core.py", line 402, in behave_as
assert not steps_failed, steps_failed[0].why.exception
AssertionError
Feature: Geonames nearby place name # features/nearby-place-imperative.feature:1
@Positive @Get @Nearby # features/nearby-place-imperative.feature:3
@Positive @Get @Nearby
Scenario Outline: Get nearby place name # features/nearby-place-imperative.feature:4
Given I use the geonames host # features/steps/steps_requests.py:6
When I access the resource url "/findNearbyPlaceNameJSON" # features/steps/steps_requests.py:11
And I provide parameter "username" as "jharmon" # features/steps/steps_requests.py:23
And I provide parameter "lat" as "<lat>" # features/steps/steps_requests.py:23
And I provide parameter "lng" as "<long>" # features/steps/steps_requests.py:23
And I retrieve the JSON results # features/steps/steps_requests.py:31
Then the status code should be 200 # features/steps/steps_requests.py:44
And it should have a list "geonames" # features/steps/steps_lists.py:6
And the list should have at least 1 item # features/steps/steps_lists.py:11
And the list should have the field "countryId" containing the value "<countryId>" # features/steps/steps_lists.py:16
And the list should have the field "toponymName" containing the value "<toponymName>" # features/steps/steps_lists.py:16
Examples:
| lat | long | countryId | toponymName |
| 30.4754724 | -98.1564068 | 6252001 | Spicewood |
| 34.134103 | -118.321694 | 6252001 | Universal City |
| 48.85815 | 2.29452 | 3017382 | Invalides |
Traceback (most recent call last):
File "/Users/julianpistorius/.venvs/api-bdd-tests/lib/python2.7/site-packages/lettuce/core.py", line 143, in __call__
ret = self.function(self.step, *args, **kw)
File "/Users/julianpistorius/git/api-bdd-tests/features/steps/steps_lists.py", line 17, in the_list_should_have_the_field_containing_the_value
eq_(world.list[0][field], value)
File "/Users/julianpistorius/.venvs/api-bdd-tests/lib/python2.7/site-packages/nose/tools/trivial.py", line 29, in eq_
raise AssertionError(msg or "%r != %r" % (a, b))
AssertionError: u'Paris 10 Ancien - Quartier Invalides' != u'Invalides'
@Negative @Get @User
Scenario: Invalid username does not work # features/nearby-place-imperative.feature:23
Given I use the geonames host # features/steps/steps_requests.py:6
When I access the resource url "/findNearbyPlaceNameJSON" # features/steps/steps_requests.py:11
And I provide parameter "username" as "fdafdafdfdafda" # features/steps/steps_requests.py:23
And I provide parameter "lat" as "30.4754724" # features/steps/steps_requests.py:23
And I provide parameter "long" as "-98.1564068" # features/steps/steps_requests.py:23
And I retrieve the JSON results # features/steps/steps_requests.py:31
Then the status code should be 200 # features/steps/steps_requests.py:44
Traceback (most recent call last):
File "/Users/julianpistorius/.venvs/api-bdd-tests/lib/python2.7/site-packages/lettuce/core.py", line 143, in __call__
ret = self.function(self.step, *args, **kw)
File "/Users/julianpistorius/git/api-bdd-tests/features/steps/steps_requests.py", line 46, in status_code_should_be
assert world.results.status_code == status, "Status invalid: %s, Results: %s" % (world.results.status_code, world.results)
AssertionError: Status invalid: 401, Results: <Response [401]>
And it should have the error "status" containing the value "user does not exist." # features/steps/steps_values.py:7
3 features (1 passed)
7 scenarios (4 passed)
59 steps (3 failed, 1 skipped, 55 passed)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.