Package: schul-cloud-ressources-server-tests
This repository containsa server to test scrapers againsttests to test the serverThe package works under Python 2 and 3.InstallationUsingpip, you can install all dependencies like this:pipinstallschul_cloud_ressources_server_testsWhen you are done, you can import the package.importschul_cloud_ressources_server_testsUsageThis section describes how to use the server and the tests.ServerYou can find theAPIdefinition.
The server serves according to theAPI.
It verifies the input and output for correctness.To start the server, runpython-mschul_cloud_ressources_server_tests.appThe server should appear athttp://localhost:8080/v1.TestsYou always test against the running server.Tests may delete everyting you can reach.If you test the running server, make sure to authenticate in a way that does not destroy the data you want to keep.python-mschul_cloud_ressources_server_tests.tests--url=http://localhost:8080/v1/http://localhost:8080/v1/is the default url.Steps for ImplementationIf you want to implement your server you can follow the TDD steps to implement
one test after the other.python-mschul_cloud_ressources_server_tests.tests-mstep1python-mschul_cloud_ressources_server_tests.tests-mstep2python-mschul_cloud_ressources_server_tests.tests-mstep3...step1runs the first teststep2runs the first and the second teststep3runs the first, second and third test…You can run  a single test withpython-mschul_cloud_ressources_server_tests.tests-mstep3onlyTest AuthenticationThe test server supports api key authentication and basic authentication.
If you test authentication over the internet.
Use https to protect the secrets.
Thus, an example test call to your api could look like this:python-mschul_cloud_ressources_server_tests.tests\--url=https://url.to/your/server\--noauth=false--basic=username:passwordIf you have an api key, you can test that the server works.python-mschul_cloud_ressources_server_tests.tests\--url=http://url.to/your/server\--noauth=false--apikey=apikeyBy default the test server accepts authentication with several credentialsno authenticationbasic:uservalid1@schul-cloud.orgpassword123abcuservalid2@schul-cloud.orgpasswordsupersecureapi key:abcdefghijklmnfor the uservalid1@schul-cloud.org.
The client does not send the user name to the server.To test these, you can add the--basicand--apikeyparameters several times to the tests.
The--noauth=trueparameter is default.
If the api only accepts authenticated requests, set--noauth=false.python-mschul_cloud_ressources_server_tests.tests\--basic=valid1@schul-cloud.org:123abc\--basic=valid2@schul-cloud.org:supersecure\--apikey=valid1@schul-cloud.org:abcdefghijklmn\--noauth=trueAll tests are run with the different authentication options.
If we have several ways to authenticate, the tests test if the user sees the other users’ data.It is assumed, that addinginvalidto the password,
user name and api key will make it invalid.
Tests use the invalid credentials to test the server behavior in rejected cases.Example Travis ConfigurationIf you want to implement a crawler or server, you can use Travis-CI to test
it.
An example travis configuration can be found in thetest-examplebranch.
You can view theoutputThe configuration is generic.
It will run under any other language you configure.Use the server in pytestYou can use the sever in Python tests.
There are fixtures available that start and stop the server.fromschul_cloud_ressources_server_tests.tests.fixturesimport*deftest_pytest(ressources_server):"""pytest using the server"""The following attributes are available:ressources_server.urlThe url of the server.ressources_server.apiAschul_cloud_ressources_api_v1.RessourcesApiobject connected to the server.ressources_server.get_ressources()A function to return a list of ressources on the server.For more information, see the moduleschul_cloud_ressources_server_tests.tests.fixtures.
You can add support for more test frameworks.TODOgenerate a docker container for the servergenerate a docker container for the testsdocument how to embed the tests and the server ina crawlertravis build script of arbitrary languagecreate example crawler with tests