def test_handler_without_resource_uri(self): # generate_api_docs() raises an exception if a handler does not have a # resource_uri attribute. resource = OperationsResource(BaseHandler) docs = generate_api_docs([resource]) error = self.assertRaises(AssertionError, list, docs) self.assertEqual( "Missing resource_uri in %s" % type(resource.handler).__name__, str(error))
def make_resource(): """ Return a new `OperationsResource` with a `BaseHandler` subclass handler, with a fabricated name and a `resource_uri` class-method. """ name = factory.make_name("handler") resource_uri = lambda cls: factory.make_name("resource-uri") namespace = {"resource_uri": classmethod(resource_uri)} handler = type(name, (BaseHandler,), namespace) return OperationsResource(handler)
def test_describe_resource_authenticated_resource(self): # When the resource requires authentication, but has no fallback # anonymous handler, the first is described. The resource name comes # from this handler. resource = OperationsResource(ExampleHandler, sentinel.auth) expected = { "anon": None, "auth": describe_handler(ExampleHandler), "name": "ExampleHandler", } self.assertEqual(expected, describe_resource(resource))
def test_describe_resource_authenticated_resource_with_fallback(self): # When the resource requires authentication, but has a fallback # anonymous handler, both are described. The resource name is taken # from the authenticated handler. self.patch(ExampleHandler, "anonymous", ExampleFallbackHandler) resource = OperationsResource(ExampleHandler, sentinel.auth) expected = { "anon": describe_handler(ExampleFallbackHandler), "auth": describe_handler(ExampleHandler), "name": "ExampleHandler", } self.assertEqual(expected, describe_resource(resource))
def test_describe_resource_anonymous_resource(self): # When the resource does not require authentication, any configured # fallback is ignored, and only the resource's handler is described. # The resource name comes from this handler. self.patch(ExampleHandler, "anonymous", ExampleFallbackHandler) resource = OperationsResource(ExampleHandler) expected = { "anon": describe_handler(ExampleHandler), "auth": None, "name": "ExampleHandler", } self.assertEqual(expected, describe_resource(resource))
def test_authenticated_is_True_when_authentication_is_provided(self): resource = OperationsResource( StubHandler, authentication=sentinel.authentication ) self.assertThat(resource.is_authentication_attempted, Is(True))
def test_authenticated_is_False_when_authentication_is_NoAuthn(self): resource = OperationsResource( StubHandler, authentication=NoAuthentication() ) self.assertThat(resource.is_authentication_attempted, Is(False))
def test_authenticated_is_False_when_no_authentication_provided(self): resource = OperationsResource(StubHandler) self.assertThat(resource.is_authentication_attempted, Is(False))
AnonMetaDataHandler, CommissioningScriptsHandler, CurtinUserDataHandler, EnlistMetaDataHandler, EnlistUserDataHandler, EnlistVersionIndexHandler, IndexHandler, MAASScriptsHandler, MetaDataHandler, StatusHandler, UserDataHandler, VersionIndexHandler, ) # Handlers for nodes requesting their own metadata. meta_data_handler = OperationsResource(MetaDataHandler, authentication=api_auth) user_data_handler = OperationsResource(UserDataHandler, authentication=api_auth) curtin_user_data_handler = OperationsResource(CurtinUserDataHandler, authentication=api_auth) version_index_handler = OperationsResource(VersionIndexHandler, authentication=api_auth) index_handler = OperationsResource(IndexHandler, authentication=api_auth) maas_scripts_handler = OperationsResource(MAASScriptsHandler, authentication=api_auth) commissioning_scripts_handler = OperationsResource(CommissioningScriptsHandler, authentication=api_auth) # Handlers for status reporting status_handler = OperationsResource(StatusHandler, authentication=api_auth)
authentication=api_auth) bcache_cache_set_handler = RestrictedResource(BcacheCacheSetHandler, authentication=api_auth) bcache_cache_sets_handler = RestrictedResource(BcacheCacheSetsHandler, authentication=api_auth) vmfs_datastore_handler = RestrictedResource(VmfsDatastoreHandler, authentication=api_auth) vmfs_datastores_handler = RestrictedResource(VmfsDatastoresHandler, authentication=api_auth) interface_handler = RestrictedResource(InterfaceHandler, authentication=api_auth) interfaces_handler = RestrictedResource(InterfacesHandler, authentication=api_auth) tag_handler = RestrictedResource(TagHandler, authentication=api_auth) tags_handler = RestrictedResource(TagsHandler, authentication=api_auth) version_handler = OperationsResource(VersionHandler) # Allow anon. node_results_handler = RestrictedResource(NodeResultsHandler, authentication=api_auth) sshkey_handler = RestrictedResource(SSHKeyHandler, authentication=api_auth) sshkeys_handler = RestrictedResource(SSHKeysHandler, authentication=api_auth) sslkey_handler = RestrictedResource(SSLKeyHandler, authentication=api_auth) sslkeys_handler = RestrictedResource(SSLKeysHandler, authentication=api_auth) user_handler = RestrictedResource(UserHandler, authentication=api_auth) users_handler = RestrictedResource(UsersHandler, authentication=api_auth) zone_handler = RestrictedResource(ZoneHandler, authentication=api_auth) zones_handler = RestrictedResource(ZonesHandler, authentication=api_auth) fabric_handler = RestrictedResource(FabricHandler, authentication=api_auth) fabrics_handler = RestrictedResource(FabricsHandler, authentication=api_auth) fannetwork_handler = RestrictedResource(FanNetworkHandler, authentication=api_auth) fannetworks_handler = RestrictedResource(FanNetworksHandler,