kopia lustrzana https://github.com/OpenDroneMap/WebODM
Moar unit tests
rodzic
a709c8fdf6
commit
c7ff74a526
|
@ -184,6 +184,7 @@ class TaskViewSet(viewsets.ViewSet):
|
|||
if task.images_count < 1:
|
||||
raise exceptions.ValidationError(detail=_("You need to upload at least 1 file before commit"))
|
||||
|
||||
task.update_size()
|
||||
task.save()
|
||||
worker_tasks.process_task.delay(task.id)
|
||||
|
||||
|
|
|
@ -13,6 +13,8 @@
|
|||
<![endif]-->
|
||||
|
||||
{% if no_processingnodes %}
|
||||
{% include "quota.html" %}
|
||||
|
||||
<h3>{% trans 'Welcome!' %} ☺</h3>
|
||||
{% trans 'Add a Processing Node' as add_processing_node %}
|
||||
{% with nodeodm_link='<a href="https://github.com/OpenDroneMap/NodeODM" target="_blank">NodeODM</a>' api_link='<a href="https://github.com/OpenDroneMap/NodeODM/blob/master/docs/index.adoc" target="_blank">API</a>' %}
|
||||
|
@ -39,15 +41,8 @@
|
|||
</ul>
|
||||
</p>
|
||||
{% endif %}
|
||||
|
||||
{% if user.profile.has_exceeded_quota_cached %}
|
||||
{% with total=user.profile.quota|disk_size used=user.profile.used_quota_cached|disk_size %}
|
||||
{% quota_exceeded_grace_period as when %}
|
||||
<div class="alert alert-warning alert-dismissible">
|
||||
<i class="fas fa-info-circle"></i> {% blocktrans %}The disk quota is being exceeded ({{ used }} of {{ total }} used). The most recent tasks will be automatically deleted {{ when }}, until usage falls below {{ total }}.{% endblocktrans %}
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
||||
|
||||
{% include "quota.html" %}
|
||||
|
||||
<div id="dashboard-app" data-dashboard></div>
|
||||
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
</li>
|
||||
{% if user.profile.has_quota %}
|
||||
<li class="divider"></li>
|
||||
|
||||
|
||||
{% with tot_quota=user.profile.quota used_quota=user.profile.used_quota_cached %}
|
||||
{% percentage used_quota tot_quota as perc_quota %}
|
||||
{% percentage used_quota tot_quota 100 as bar_width %}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
{% load i18n %}
|
||||
{% load settings %}
|
||||
|
||||
{% if user.profile.has_exceeded_quota_cached %}
|
||||
{% with total=user.profile.quota|disk_size used=user.profile.used_quota_cached|disk_size %}
|
||||
{% quota_exceeded_grace_period as when %}
|
||||
<div class="alert alert-warning alert-dismissible">
|
||||
<i class="fas fa-info-circle"></i> {% blocktrans %}The disk quota is being exceeded ({{ used }} of {{ total }} used). The most recent tasks will be automatically deleted {{ when }}, until usage falls below {{ total }}.{% endblocktrans %}
|
||||
</div>
|
||||
{% endwith %}
|
||||
{% endif %}
|
|
@ -46,11 +46,11 @@ def quota_exceeded_grace_period(context):
|
|||
deadline = now + settings.QUOTA_EXCEEDED_GRACE_PERIOD * 60 * 60
|
||||
diff = max(0, deadline - now)
|
||||
if diff >= 60*60*24*2:
|
||||
return _("within %(num)s days") % {"num": math.ceil(diff / (60*60*24))}
|
||||
elif diff >= 60*60:
|
||||
return _("within %(num)s hours") % {"num": math.ceil(diff / (60*60))}
|
||||
return _("in %(num)s days") % {"num": math.floor(diff / (60*60*24))}
|
||||
elif diff >= 60*60*2:
|
||||
return _("in %(num)s hours") % {"num": math.floor(diff / (60*60))}
|
||||
elif diff > 1:
|
||||
return _("within %(num)s minutes") % {"num": math.ceil(diff / 60)}
|
||||
return _("in %(num)s minutes") % {"num": math.floor(diff / 60)}
|
||||
else:
|
||||
return _("very soon")
|
||||
|
||||
|
|
|
@ -246,6 +246,8 @@ class TestApi(BootTestCase):
|
|||
|
||||
# Update quota deadlines
|
||||
|
||||
self.assertTrue(user.profile.get_quota_deadline() is None)
|
||||
|
||||
# Miss parameters
|
||||
res = client.post('/api/admin/profiles/%s/update_quota_deadline/' % user.id)
|
||||
self.assertEqual(res.status_code, status.HTTP_400_BAD_REQUEST)
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
import os
|
||||
from django.test import Client
|
||||
from webodm import settings
|
||||
from .classes import BootTestCase
|
||||
|
||||
class TestLogin(BootTestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_reset_password_render(self):
|
||||
c = Client()
|
||||
c.login(username="testuser", password="test1234")
|
||||
|
||||
settings.RESET_PASSWORD_LINK = ''
|
||||
|
||||
res = c.get('/login/', follow=True)
|
||||
body = res.content.decode("utf-8")
|
||||
|
||||
# The reset password link should show instructions
|
||||
self.assertTrue("You can reset the administrator password" in body)
|
||||
|
||||
settings.RESET_PASSWORD_LINK = 'http://0.0.0.0/reset_test'
|
||||
|
||||
res = c.get('/login/', follow=True)
|
||||
body = res.content.decode("utf-8")
|
||||
|
||||
# The reset password link should show instructions
|
||||
self.assertTrue('<a href="http://0.0.0.0/reset_test' in body)
|
||||
|
||||
|
|
@ -2,6 +2,8 @@ from django.contrib.auth.models import User, Group
|
|||
from rest_framework import status
|
||||
from rest_framework.test import APIClient
|
||||
from app.models import Task, Project
|
||||
from nodeodm.models import ProcessingNode
|
||||
from worker.tasks import check_quotas
|
||||
from .classes import BootTestCase
|
||||
|
||||
class TestQuota(BootTestCase):
|
||||
|
@ -43,7 +45,9 @@ class TestQuota(BootTestCase):
|
|||
# Create a task with size
|
||||
p = Project.objects.create(owner=user, name='Test')
|
||||
p.save()
|
||||
t = Task.objects.create(project=p, name='Test', size=2005)
|
||||
t = Task.objects.create(project=p, name='Test', size=1005)
|
||||
t.save()
|
||||
t = Task.objects.create(project=p, name='Test2', size=1010)
|
||||
t.save()
|
||||
|
||||
# Simulate call to task.update_size which calls clear_used_quota_cache
|
||||
|
@ -55,4 +59,30 @@ class TestQuota(BootTestCase):
|
|||
res = c.get('/dashboard/', follow=True)
|
||||
body = res.content.decode("utf-8")
|
||||
|
||||
# self.assertTrue("disk quota is being exceeded" in body)
|
||||
self.assertTrue("disk quota is being exceeded" in body)
|
||||
self.assertTrue("in 8 hours" in body)
|
||||
|
||||
# Running the workers check_quota function will not remove tasks
|
||||
check_quotas()
|
||||
self.assertEqual(len(Task.objects.filter(project__owner=user)), 2)
|
||||
|
||||
# Update grace period
|
||||
def check_quota_warning(hours, text):
|
||||
user.profile.set_quota_deadline(hours)
|
||||
res = c.get('/dashboard/', follow=True)
|
||||
body = res.content.decode("utf-8")
|
||||
self.assertTrue(text in body)
|
||||
|
||||
check_quota_warning(73, "in 3 days")
|
||||
check_quota_warning(71, "in 2 days")
|
||||
check_quota_warning(47.9, "in 47 hours")
|
||||
check_quota_warning(3.1, "in 3 hours")
|
||||
check_quota_warning(1.51, "in 90 minutes")
|
||||
check_quota_warning(0.99, "in 59 minutes")
|
||||
check_quota_warning(0, "very soon")
|
||||
|
||||
# Running the check_quotas function should remove the last task only
|
||||
check_quotas()
|
||||
tasks = Task.objects.filter(project__owner=user)
|
||||
self.assertEqual(len(tasks), 1)
|
||||
self.assertEqual(tasks[0].name, "Test")
|
Ładowanie…
Reference in New Issue