Package: schul-cloud-resources-server-tests
This repository is a test and reference implementation for the Schul-Cloud-ResourcesAPI.
The purpose is tohave a reference to verify theAPIspecification is actually workingfind uncertainties in theAPIspecificationprovide tests to speed up an implementation of the API on other servers such asschulcloud-contenthave people contribute tests as a means of communication between applications: one test, X server-implementationshave an easy-to-setup server for crawler implementations and testsThis repository containsa server to test scrapers againsttests to test the serverThe package works under Python 2 and 3.You can view the live docker instance athttp://scrst.quelltext.eu/InstallationUsingpip, you can install all dependencies like this:pipinstall--userschul_cloud_resources_server_testsWhen you are done, you can import the package.importschul_cloud_resources_server_testsInstallation for DevelopmentIf you want to work on the module, you need to install it differently.
If you set it up for development, you can add new tests and features.First, you need to have git installed. Then, clone the repository:gitclonehttps://github.com/schul-cloud/schul_cloud_resources_server_tests.gitcdschul_cloud_resources_server_testsIf you havepipinstalled, you can now install the packages:pipinstall--user-rrequirements.txtpip-tools==1.6.5Now, as long as you are in theschul_cloud_resources_server_testsfolder, you can run the commands as mentioned below.
Additionally, you can use git to create pull-requests with your edited code.UsageThis 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_resources_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_resources_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_resources_server_tests.tests-mstep1python-mschul_cloud_resources_server_tests.tests-mstep2python-mschul_cloud_resources_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_resources_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_resources_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_resources_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_resources_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.Usage in CrawlerTheurl-crawleruses the test server to test synchronization.Use the server in pytestYou can use the sever in Python tests.
There are fixtures available that start and stop the server.fromschul_cloud_resources_server_tests.tests.fixturesimport*deftest_pytest(resources_server):"""pytest using the server"""The following attributes are available:resources_server.urlThe url of the server.resources_server.apiAschul_cloud_resources_api_v1.ResourcesApiobject connected to the server.resources_server.get_resources()A function to return a list of resources on the server.For more information, see the moduleschul_cloud_resources_server_tests.tests.fixtures.
You can add support for more test frameworks.DockerYou can build the this image with the following docker command:dockerbuild-tschulcloud/schul_cloud_resources_server_tests.Or you can pull the docker container and run it.dockerrunschulcloud/schul_cloud_resources_server_testsThis starts the server at the port 8080 as in the examples above.Docker-ComposeThere is adocker-compose.ymlfile, so you can use thedocker-composecommand.
The server will be available athttp://localhost:80/v1It uses a memory limit of 60MB.You can edit this documenton Githuband check it withthis editor.