Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_take_task_if_wrong_channel(self):
channel = Channel.objects.create(name='channel_x86')
t = Task.objects.create(
worker=self._worker.worker,
arch=self._arch,
channel=channel,
owner=self._user,
method='DummyForkTask',
state=TASK_STATES['FREE'],
)
self.assertEqual(t.state, TASK_STATES['FREE'])
tm = TaskManager(conf={'worker': self._worker})
task_info = t.export(False)
with patch('kobo.worker.taskmanager.os', fork=Mock(return_value=9999)) as os_mock:
def test_worker_count(self):
channel = Channel.objects.create(name='test')
self.assertEquals(channel.worker_count, 0)
worker = Worker.objects.create(
worker_key='mock-worker',
name='mock-worker',
)
worker.channels.add(channel)
worker.save()
self.assertEquals(channel.worker_count, 1)
def setUp(self):
self._fixture_teardown()
super(TestXmlRpcClient, self).setUp()
user = User.objects.create(username='testuser', is_superuser=True)
arch = Arch.objects.create(name='noarch', pretty_name='noarch')
channel = Channel.objects.create(name='default')
self._arch = arch
self._channel = channel
self._user = user
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
def setUp(self):
super(TestViewLog, self).setUp()
self.cleanDataDirs()
# These objects are required to exist but their attributes are irrelevant
user = User.objects.create()
arch = Arch.objects.create(name='testarch')
channel = Channel.objects.create(name='testchannel')
test_task = Task.objects.create(
pk=TASK_ID, arch=arch, channel=channel, owner=user)
# associate some compressed and decompressed logs with the task.
# (the save and gzip_logs methods here are writing files to disk)
test_task.logs['zipped_tiny.log'] = tiny_log_content()
test_task.logs['zipped_small.log'] = small_log_content()
test_task.logs['zipped_big.log'] = self.big_log_content
test_task.logs.save()
test_task.logs.gzip_logs()
test_task.logs['small.log'] = small_log_content()
test_task.logs['big.log'] = self.big_log_content
test_task.logs['log.html'] = html_content()
test_task.logs.save()
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
def setUp(self):
self._fixture_teardown()
self._arch = Arch.objects.create(name='i386', pretty_name='32 bit')
self._channel = Channel.objects.create(name='test')
self._user = User.objects.create(username='testuser')
def setUp(self):
self._fixture_teardown()
user = User.objects.create(username='testuser')
arch = Arch.objects.create(name='testarch')
channel = Channel.objects.create(name='testchannel')
worker = Worker.objects.create(
worker_key='mock-worker',
name='mock-worker',
)
worker.arches.add(arch)
worker.channels.add(channel)
worker.save()
self.task1 = Task.objects.create(
worker=worker,
arch=arch,
channel=channel,
owner=user,
method='TaskOne',
state=TASK_STATES['FREE'],
class ChannelAdmin(admin.ModelAdmin):
search_fields = ("name",)
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)
"""Model for hub_task table."""
archive = models.BooleanField(default=False, help_text=_("When a task is archived, it disappears from admin interface and cannot be accessed by taskd.<br>Make sure that archived tasks are finished and you won't need them anymore."))
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
worker = models.ForeignKey(Worker, null=True, blank=True, help_text=_("A worker which has this task assigned."), on_delete=models.CASCADE)
parent = models.ForeignKey("self", null=True, blank=True, help_text=_("Parent task."), on_delete=models.CASCADE)
state = models.PositiveIntegerField(default=TASK_STATES["FREE"], choices=TASK_STATES.get_mapping(), help_text=_("Current task state."))
label = models.CharField(max_length=255, blank=True, help_text=_("Label, description or any reason for this task."))
exclusive = models.BooleanField(default=False, help_text=_("Exclusive tasks have highest priority. They are used e.g. when shutting down a worker."))
method = models.CharField(max_length=255, help_text=_("Method name represents appropriate task handler."))
args = kobo.django.fields.JSONField(blank=True, default={}, help_text=_("Method arguments. JSON serialized dictionary."))
result = models.TextField(blank=True, help_text=_("Task result. Do not store a lot of data here (use HubProxy.upload_task_log instead)."))
comment = models.TextField(null=True, blank=True)
arch = models.ForeignKey(Arch, on_delete=models.CASCADE)
channel = models.ForeignKey(Channel, on_delete=models.CASCADE)
timeout = models.PositiveIntegerField(null=True, blank=True, help_text=_("Task timeout. Leave blank for no timeout."))
waiting = models.BooleanField(default=False, help_text=_("Task is waiting until some subtasks finish."))
awaited = models.BooleanField(default=False, help_text=_("Task is awaited by another task."))
dt_created = models.DateTimeField(auto_now_add=True)
dt_started = models.DateTimeField(null=True, blank=True)
dt_finished = models.DateTimeField(null=True, blank=True)
priority = models.PositiveIntegerField(default=10, help_text=_("Priority."))
weight = models.PositiveIntegerField(default=1, help_text=_("Weight determines how many resources is used when processing the task."))
resubmitted_by = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, related_name="resubmitted_by1", on_delete=models.CASCADE)
resubmitted_from = models.ForeignKey("self", null=True, blank=True, related_name="resubmitted_from1", on_delete=models.CASCADE)
subtask_count = models.PositiveIntegerField(default=0, help_text=_("Subtask count.<br>This is a generated field."))