Fixed task model UUID definition, fixed broken has_available_options filter, tests

pull/40/head
Piero Toffanin 2016-10-29 12:09:35 -04:00
rodzic 7a089ada79
commit c43a002caf
4 zmienionych plików z 10 dodań i 5 usunięć

Wyświetl plik

@ -20,7 +20,10 @@ class ProcessingNodeFilter(FilterSet):
has_available_options = django_filters.MethodFilter()
def filter_has_available_options(self, queryset, value):
return queryset.filter(available_options__isnull=(not value.lower() in ['true', '1']))
if value.lower() in ['true', '1']:
return queryset.exclude(available_options=dict())
else:
return queryset.filter(available_options=dict())
class Meta:
model = ProcessingNode

Wyświetl plik

@ -79,7 +79,7 @@ class Task(models.Model):
(50, 'CANCELED')
)
uuid = models.CharField(max_length=255, db_index=True, null=True, blank=True, help_text="Identifier of the task (as returned by OpenDroneMap's REST API)")
uuid = models.CharField(max_length=255, db_index=True, default='', blank=True, help_text="Identifier of the task (as returned by OpenDroneMap's REST API)")
project = models.ForeignKey(Project, on_delete=models.CASCADE, help_text="Project that this task belongs to")
name = models.CharField(max_length=255, null=True, blank=True, help_text="A label for the task")
processing_lock = models.BooleanField(default=False, help_text="A flag indicating whether this task is currently locked for processing. When this flag is turned on, the task is in the middle of a processing step.")

Wyświetl plik

@ -45,7 +45,7 @@ def process_pending_tasks():
# All tasks that have a processing node assigned
# but don't have a UUID
# and that are not locked (being processed by another thread)
tasks = Task.objects.filter(Q(uuid=None) | Q(status=10) | Q(status=20)).exclude(Q(processing_node=None) | Q(processing_lock=True))
tasks = Task.objects.filter(Q(uuid='') | Q(status__in=[10, 20])).exclude(Q(processing_node=None) | Q(processing_lock=True))
for task in tasks:
logger.info("Acquiring lock: {}".format(task))
task.processing_lock = True

Wyświetl plik

@ -154,14 +154,16 @@ class TestApi(BootTestCase):
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertTrue(len(res.data) == 1)
# Can filter online
# Can filter nodes with valid options
res = client.get('/api/processingnodes/?has_available_options=true')
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertTrue(len(res.data) == 0)
res = client.get('/api/processingnodes/?has_available_options=false')
self.assertEqual(res.status_code, status.HTTP_200_OK)
self.assertTrue(len(res.data) == 2)
self.assertTrue(len(res.data) == 1)
self.assertTrue(res.data[0]['hostname'] == 'localhost')
# Can get single processing node as normal user
res = client.get('/api/processingnodes/{}/'.format(pnode.id))