Diff for "TestingWebServices"

Not logged in - Log In / Register

Differences between revisions 1 and 13 (spanning 12 versions)
Revision 1 as of 2010-04-12 16:25:18
Size: 710
Editor: adiroiban
Comment:
Revision 13 as of 2020-07-17 15:34:39
Size: 2925
Comment: Fix unfortunate typo
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
Webservice data can be retrieved using ''webservice.get(URL).jsonBody()'' ||<tablestyle="width: 100%;" colspan=3 style="background: #2a2929; font-weight: bold; color: #f6bc05;">This page is an introduction to writing and running web service (API) test. ||

||<tablestyle="float:right; font-size: 0.9em; width:30%; background:#F1F1ED; margin: 0 0 1em 1em;" style="padding:0.5em;"><<TableOfContents>>||

= Writing web service tests =

Webservices are tests using doctests.

They are more like integration tests, than unit tests.

Unit tests should we added in the model.

= Testing with launchpadlib =

This is the recommended way of testing webservices.
Documentation can be found at '''canonical/launchpad/pagetests/webservice/launchpadlib.txt'''

= Testing the webservices using the ''raw'' access =

In case some functionality can not be tested using launchpadlib, you can use the helpers described in this section.

== GET ==
Default get method data can be retrieved using ''webservice.get(URL).jsonBody()''
Line 13: Line 35:
There are a couple of already configured webservice handlers: Custom get methods:

{{{
    >>> permissions = user_webservice.named_get(
    ... URL, METHODNAME, PARAMETER1=VALUE1,...).jsonBody()
}}}

== POST ==

For post we have ''webservice.post'' and ''webservice.named_post''

{{{
  >>> print webservice.named_post(
  ... URL, METHODNAME, PARAMETER1=VALUE1,...)
  HTTP/1.1 201 Created
  ...
}}}

== PATCH ==

{{{
  >>> patch = {u'milestone_link': webservice.getAbsoluteUrl(
  ... '/debian/+milestone/3.1')}
  >>> print webservice.patch(bugtask_path, 'application/json', dumps(patch))
  HTTP/1.1 209 Content Returned...
}}}

== Delete ==

{{{
    >>> response = webservice.delete('/~eric/fooix/feature-branch')
    >>> print response
    HTTP/1.1 200 Ok
    ...
}}}

= Testing from withing a web browser =

* You can access the API from a web browser using your current cookie authentication by using '''https://launchpad.test/api/devel/''' instead of ''' https://api.launchpad.test/devel/'''

* For anonymous access you can try '''curl http://launchpad.test/api/devel/+languages'''

= Security checks =

If the permissions are already checked in the Browser code, there is no need to test them again in the Webservices.

Add only specific Webservices security checks.


= Available callers =

There are a couple of already configured webservice callers:
Line 20: Line 93:
--
----

This page is an introduction to writing and running web service (API) test.

Writing web service tests

Webservices are tests using doctests.

They are more like integration tests, than unit tests.

Unit tests should we added in the model.

Testing with launchpadlib

This is the recommended way of testing webservices. Documentation can be found at canonical/launchpad/pagetests/webservice/launchpadlib.txt

Testing the webservices using the ''raw'' access

In case some functionality can not be tested using launchpadlib, you can use the helpers described in this section.

GET

Default get method data can be retrieved using webservice.get(URL).jsonBody()

    >>> es = anon_webservice.get('/+languages/es').jsonBody()
    >>> es['resource_type_link']
    u'http.../#language'
    >>> print es['text_direction']
    Left to Right
    >>> print es['code']
    es

Custom get methods:

    >>> permissions = user_webservice.named_get(
    ...     URL, METHODNAME, PARAMETER1=VALUE1,...).jsonBody()

POST

For post we have webservice.post and webservice.named_post

  >>> print webservice.named_post(
  ...     URL, METHODNAME, PARAMETER1=VALUE1,...)
  HTTP/1.1 201 Created
  ...

PATCH

  >>> patch = {u'milestone_link': webservice.getAbsoluteUrl(
  ...                                 '/debian/+milestone/3.1')}
  >>> print webservice.patch(bugtask_path, 'application/json', dumps(patch))
  HTTP/1.1 209 Content Returned...

Delete

    >>> response = webservice.delete('/~eric/fooix/feature-branch')
    >>> print response
    HTTP/1.1 200 Ok
    ...

Testing from withing a web browser

* You can access the API from a web browser using your current cookie authentication by using https://launchpad.test/api/devel/ instead of https://api.launchpad.test/devel/

* For anonymous access you can try curl http://launchpad.test/api/devel/+languages

Security checks

If the permissions are already checked in the Browser code, there is no need to test them again in the Webservices.

Add only specific Webservices security checks.

Available callers

There are a couple of already configured webservice callers:

  • webservice - Read access to everything. write access to all writable attributes. Logged in user salgado.

  • public_webservice - salgado-read-nonprivate ?!?!?

  • user_webservice - nopriv-read-noprivate ?!?!?!

  • anon_webservice - read access to all data available for anonymous users.


CategoryTesting

TestingWebServices (last edited 2020-07-17 15:34:39 by doismellburning)