847
847
Generating the webservice
848
848
=========================
853
Before we can continue, we must define a web service configuration
854
object. Each web service needs to have one of these registered
855
utilities providing basic information about the web service. This one
858
>>> from lazr.restful.testing.helpers import TestWebServiceConfiguration
859
>>> from zope.component import provideUtility
860
>>> from lazr.restful.interfaces import IWebServiceConfiguration
861
>>> class MyWebServiceConfiguration(TestWebServiceConfiguration):
862
... active_versions = ["beta", "1.0", "2.0", "3.0"]
863
... last_version_with_mutator_named_operations = "1.0"
864
... first_version_with_total_size_link = "2.0"
865
... code_revision = "1.0b"
866
... default_batch_size = 50
867
>>> provideUtility(MyWebServiceConfiguration(), IWebServiceConfiguration)
869
We must also set up the ability to create versioned requests. This web
870
service has four versions: 'beta', '1.0', '2.0', and '3.0'. We'll
871
need a marker interface for every version, registered as a utility
872
under the name of the version.
874
Each version interface subclasses the previous version's
875
interface. This lets a request use a resource definition for the
876
previous version if it hasn't changed since then.
878
>>> from zope.component import getSiteManager
879
>>> from lazr.restful.interfaces import IWebServiceVersion
880
>>> class ITestServiceRequestBeta(IWebServiceVersion):
882
>>> class ITestServiceRequest10(ITestServiceRequestBeta):
884
>>> class ITestServiceRequest20(ITestServiceRequest10):
886
>>> class ITestServiceRequest30(ITestServiceRequest20):
888
>>> sm = getSiteManager()
889
>>> for marker, name in [(ITestServiceRequestBeta, 'beta'),
890
... (ITestServiceRequest10, '1.0'),
891
... (ITestServiceRequest20, '2.0'),
892
... (ITestServiceRequest30, '3.0')]:
893
... sm.registerUtility(marker, IWebServiceVersion, name=name)
895
>>> from lazr.restful.testing.webservice import FakeRequest
896
>>> request = FakeRequest(version='beta')
968
1017
... self.base_price = base_price
969
1018
... self.inventory_number = inventory_number
971
Before we can continue, we must define a web service configuration
972
object. Each web service needs to have one of these registered
973
utilities providing basic information about the web service. This one
976
>>> from lazr.restful.testing.helpers import TestWebServiceConfiguration
977
>>> from zope.component import provideUtility
978
>>> from lazr.restful.interfaces import IWebServiceConfiguration
979
>>> class MyWebServiceConfiguration(TestWebServiceConfiguration):
980
... active_versions = ["beta", "1.0", "2.0", "3.0"]
981
... last_version_with_mutator_named_operations = "1.0"
982
... first_version_with_total_size_link = "2.0"
983
... code_revision = "1.0b"
984
... default_batch_size = 50
985
>>> provideUtility(MyWebServiceConfiguration(), IWebServiceConfiguration)
987
We must also set up the ability to create versioned requests. This web
988
service has four versions: 'beta', '1.0', '2.0', and '3.0'. We'll
989
need a marker interface for every version, registered as a utility
990
under the name of the version.
992
Each version interface subclasses the previous version's
993
interface. This lets a request use a resource definition for the
994
previous version if it hasn't changed since then.
996
>>> from zope.component import getSiteManager
997
>>> from lazr.restful.interfaces import IWebServiceVersion
998
>>> class ITestServiceRequestBeta(IWebServiceVersion):
1000
>>> class ITestServiceRequest10(ITestServiceRequestBeta):
1002
>>> class ITestServiceRequest20(ITestServiceRequest10):
1004
>>> class ITestServiceRequest30(ITestServiceRequest20):
1006
>>> sm = getSiteManager()
1007
>>> for marker, name in [(ITestServiceRequestBeta, 'beta'),
1008
... (ITestServiceRequest10, '1.0'),
1009
... (ITestServiceRequest20, '2.0'),
1010
... (ITestServiceRequest30, '3.0')]:
1011
... sm.registerUtility(marker, IWebServiceVersion, name=name)
1013
>>> from lazr.restful.testing.webservice import FakeRequest
1014
>>> request = FakeRequest(version='beta')
1016
1020
Now we can turn a Book object into something that implements