How to use the kobo.hub.models.Worker function in kobo

To help you get started, we’ve selected a few kobo examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github release-engineering / kobo / tests / test_forms.py View on Github external
def setUp(self):
        self._fixture_teardown()
        user = User.objects.create(username='testuser')
        user2 = User.objects.create(username='anothertestuser')
        arch = Arch.objects.create(name='testarch')
        channel = Channel.objects.create(name='testchannel')

        w = Worker.objects.create(
            worker_key='testworker',
            name='testworker',
        )

        w.arches.add(arch)
        w.channels.add(channel)
        w.save()

        self._arch = arch
        self._channel = channel
        self._user = user
        self._user2 = user2
        self._worker = w
github release-engineering / kobo / tests / test_xmlrpc_auth.py View on Github external
def test_login_worker_key_valid_worker_and_user(self):
        def login(request, user):
            request.session.session_key = '1234567890'
            return user

        Worker.objects.create(worker_key='key', name='name')

        req = Mock(spec=['session'], session=Mock())
        user = Mock()
        krb_mock = Mock(spec=['authenticate'], authenticate=Mock(return_value=user))

        with patch('kobo.hub.xmlrpc.auth.Krb5RemoteUserBackend', return_value=krb_mock):
            with patch.object(auth.django.contrib.auth, 'login', side_effect=login) as login_mock:
                session_key = auth.login_worker_key(req, 'key')

                login_mock.assert_called_once_with(req, user)
        if django_version_ge('1.11.0'):
            krb_mock.authenticate.assert_called_once_with(None, 'worker/name')
        else:
            krb_mock.authenticate.assert_called_once_with('worker/name')
        self.assertEquals(session_key, '1234567890')
github release-engineering / kobo / tests / test_xmlrpc_client.py View on Github external
def test_shutdown_worker(self):
        w = Worker.objects.create(
            worker_key='worker',
            name='worker',
            enabled=True,
        )

        task_id = client.shutdown_worker(_make_request(), w.name)
        self.assertTrue(task_id > 0)

        task = Task.objects.get(id=task_id)
        self.assertTrue(task.exclusive)
        self.assertTrue('kill' in task.args)
        self.assertFalse(task.args['kill'])
        self.assertEqual(task.method, 'ShutdownWorker')
github release-engineering / kobo / tests / test_xmlrpc_worker.py View on Github external
def setUp(self):
        self._fixture_teardown()
        super(TestXmlRpcWorker, self).setUp()

        user = User.objects.create(username='testuser')
        arch = Arch.objects.create(name='testarch')
        channel = Channel.objects.create(name='testchannel')

        w = Worker.objects.create(
            worker_key='testworker',
            name='testworker',
        )

        w.arches.add(arch)
        w.channels.add(channel)
        w.save()

        self._arch = arch
        self._channel = channel
        self._user = user
        self._worker = w
github release-engineering / kobo / tests / test_models.py View on Github external
def test_export(self):
        worker = Worker.objects.create(worker_key='worker', name='Worker')
        data = worker.export()

        self.assertTrue(data['id'] > 0)
        self.assertEquals(data['name'], 'Worker')
        self.assertEquals(data['arches'], [])
        self.assertEquals(data['channels'], [])
        self.assertEquals(data['enabled'], True)
        self.assertEquals(data['max_load'], 1)
        self.assertEquals(data['ready'], True)
        self.assertEquals(data['task_count'], 0)
        self.assertEquals(data['current_load'], 0)
        self.assertEquals(data['version'], '1.0.0')
github release-engineering / kobo / tests / test_xmlrpc_worker.py View on Github external
def test_get_task_cant_get_task_from_other_worker(self):
        w = Worker.objects.create(
            worker_key='other-worker',
            name='other-worker',
        )

        t = Task.objects.create(
            worker=w,
            arch=self._arch,
            channel=self._channel,
            owner=self._user,
            state=TASK_STATES['FREE'],
        )

        req = _make_request(self._worker)

        with self.assertRaises(Task.DoesNotExist):
            worker.get_task(req, t.id)
github release-engineering / kobo / kobo / hub / urls / worker.py View on Github external
# -*- coding: utf-8 -*-


from django.conf.urls import url
from django.utils.translation import ugettext_lazy as _
from kobo.django.views.generic import ExtraListView, ExtraDetailView
from kobo.hub.models import Worker


urlpatterns = [
    url(r"^$", ExtraListView.as_view(
        queryset=Worker.objects.order_by("name"),
        template_name="worker/list.html",
        context_object_name="worker_list",
        title = _("Workers"),
    ), name="worker/list"),
    url(r"^(?P\d+)/$", ExtraDetailView.as_view(
        queryset=Worker.objects.select_related(),
        template_name="worker/detail.html",
        context_object_name="worker",
        title=_("Worker detail"),
    ), name="worker/detail"),
]
github release-engineering / kobo / kobo / hub / admin.py View on Github external
class TaskAdmin(admin.ModelAdmin):
    list_display = ("id", "method", "label", "state", "owner", "dt_created", "dt_finished", "time", "arch", "channel")
    list_filter = ("method", "state", "priority", "arch")
    search_fields = ("id", "method", "label", "owner__username", "dt_created", "dt_finished")
    raw_id_fields = ("parent", "owner", "resubmitted_by", "resubmitted_from")

class WorkerAdmin(admin.ModelAdmin):
    list_display = ("name", "enabled", "ready", "max_load", "current_load", "task_count","min_priority")
    list_filter = ("enabled", "ready")
    search_fields = ("name",)

admin.site.register(Arch, ArchAdmin)
admin.site.register(Channel, ChannelAdmin)
admin.site.register(Task, TaskAdmin)
admin.site.register(Worker, WorkerAdmin)