django-orchestra-test/orchestra/contrib/orchestration/tests/test_route.py

42 lines
1.6 KiB
Python
Raw Normal View History

2014-05-08 16:59:35 +00:00
from orchestra.utils.tests import BaseTestCase
2015-04-07 15:14:49 +00:00
from .. import backends, Operation
from ..models import Route, Server
2014-05-08 16:59:35 +00:00
class RouterTests(BaseTestCase):
def setUp(self):
self.host = Server.objects.create(name='web.example.com')
self.host1 = Server.objects.create(name='web1.example.com')
self.host2 = Server.objects.create(name='web2.example.com')
def test_list_backends(self):
# TODO count actual, register and compare
2021-02-08 14:31:15 +00:00
choices = list(Route._meta.get_field('backend').choices)
2014-05-08 16:59:35 +00:00
self.assertLess(1, len(choices))
def test_get_instances(self):
2021-02-08 17:47:16 +00:00
class ServiceBackend(backends.ServiceController):
2014-05-08 16:59:35 +00:00
verbose_name = 'Route'
2014-10-04 09:29:18 +00:00
models = ['routes.Route']
def save(self, instance):
pass
2014-05-08 16:59:35 +00:00
choices = backends.ServiceBackend.get_choices()
2021-02-08 14:31:15 +00:00
Route._meta.get_field('backend').choices = choices
2021-02-08 17:47:16 +00:00
backend = ServiceBackend.get_name()
2014-05-08 16:59:35 +00:00
2014-10-04 09:29:18 +00:00
route = Route.objects.create(backend=backend, host=self.host, match='True')
2021-02-08 17:47:16 +00:00
operation = Operation(backend=ServiceBackend, instance=route, action='save')
self.assertEqual(1, len(Route.objects.get_for_operation(operation)))
2014-10-04 09:29:18 +00:00
2014-05-08 16:59:35 +00:00
route = Route.objects.create(backend=backend, host=self.host1,
2021-02-08 17:47:16 +00:00
match='route.backend == "%s"' % ServiceBackend.get_name())
self.assertEqual(2, len(Route.objects.get_for_operation(operation)))
2014-05-08 16:59:35 +00:00
route = Route.objects.create(backend=backend, host=self.host2,
2014-10-04 09:29:18 +00:00
match='route.backend == "something else"')
self.assertEqual(2, len(Route.objects.get_for_operation(operation)))