def test_get_default_instance(self): result = rolerouter.rolerouter_factory(self.loader, self.global_conf, **self.local_conf) self.assertTrue(isinstance(result, rolerouter.RoleRouter)) self.assertEqual(len(result.routes), 3) self.assertTrue(all(k in result.routes.keys() for k in ["default", "cat", "dog"])) self.assertEqual(len(result.roles), 3) self.assertTrue(all(k in result.roles.keys() for k in ["domestic", "outdoor", "mutt"]))
def test_call_to_mutt_role(self): context = mock.Mock() context.roles = ["mutt"] req = mock.Mock() req.environ = {"nova.context": context} rr = rolerouter.rolerouter_factory(self.loader, self.global_conf, **self.local_conf) result = rr(req) self.assertEqual(result, "dog_filter")
def test_create_instance_with_key(self): result = rolerouter.rolerouter_factory(self.loader, self.global_conf, **self.key_conf) self.assertTrue(isinstance(result, rolerouter.RoleRouter)) self.assertEqual(len(result.routes), 3) self.assertTrue(all(k in result.routes.keys() for k in ["default", "cat", "dog"])) self.assertEqual(len(result.roles), 3) self.assertTrue(all(k in result.roles.keys() for k in ["domestic", "outdoor", "mutt"])) self.assertEqual('animal.context', result.context_key)
def test_ordering_of_roles_does_not_matter(self): context = mock.Mock() context.roles = ["mutt", "outdoor"] req = mock.Mock() req.environ = {"nova.context": context} rr = rolerouter.rolerouter_factory(self.loader, self.global_conf, **self.local_conf) result = rr(req) self.assertEqual(result, "cat_filter")
def test_ordering_multiple_roles_different_route_returns_cat_filter(self): context = mock.Mock() context.roles = ["domestic", "mutt"] req = mock.Mock() req.environ = {"nova.context": context} rr = rolerouter.rolerouter_factory(self.loader, self.global_conf, **self.local_conf) result = rr(req) self.assertEqual(result, "cat_filter")
def test_multiple_roles_from_same_route(self): context = mock.Mock() context.roles = ["domestic", "outdoor"] req = mock.Mock() req.environ = {"nova.context": context} rr = rolerouter.rolerouter_factory(self.loader, self.global_conf, **self.local_conf) result = rr(req) self.assertEqual(result, "cat_filter")
def test_call_to_untracked_role(self): context = mock.Mock() context.roles = ["blah"] req = mock.Mock() req.environ = {"nova.context": context} rr = rolerouter.rolerouter_factory(self.loader, self.global_conf, **self.local_conf) result = rr(req) # NOTE(jmeridth/roaet): this needs to be called explicitly because # it doesn't get called in the filter chain self.assertEqual(result(), "appx")