def test_add_nested_resource(self): def endpoint(self, params): pass def nested_endpoint(self, params): pass resource = BaseResource(name='resource') resource.on_detail = endpoint nested_resource = BaseResource(name='nested_resource') nested_resource.on_detail = nested_endpoint self.dispatcher.add_resource(resource) self.dispatcher.add_resource(nested_resource, resource) rules = list(self.dispatcher.url_map.iter_rules(nested_endpoint)) self.assertEqual(len(rules), 1) self.assertEqual(rules[0].rule, '/resource/<int:resource_id>/nested_resource/<int:nested_resource_id>')
def test_add_nested_resource_without_details(self): def endpoint(self, params): pass def nested_endpoint(self, params): pass resource = BaseResource(name='resource') resource.on_list = endpoint nested_resource = BaseResource(name='nested_resource') nested_resource.on_detail = nested_endpoint self.dispatcher.add_resource(resource) with self.assertRaises(AttributeError): self.dispatcher.add_resource(nested_resource, resource)