Skip to content

Commit

Permalink
Gardening
Browse files Browse the repository at this point in the history
  • Loading branch information
xi committed Jun 19, 2018
1 parent c88ccbf commit 1c001fe
Show file tree
Hide file tree
Showing 28 changed files with 135 additions and 101 deletions.
4 changes: 2 additions & 2 deletions Lagerregal/base_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,8 @@
)

LANGUAGES = (
('de', 'German'),
('en', 'English'),
('de', 'German'),
('en', 'English'),
)

AUTH_USER_MODEL = 'users.Lageruser'
Expand Down
5 changes: 3 additions & 2 deletions Lagerregal/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@
# Uncomment the next two lines to enable the admin:
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _
admin.autodiscover()
import permission; permission.autodiscover()
import permission
from permission.decorators import permission_required
from django.views.decorators.clickjacking import xframe_options_exempt

admin.autodiscover()
permission.autodiscover()

urlpatterns = [
url(r'^$', login_required(Home.as_view()), name="home"),
Expand Down
5 changes: 3 additions & 2 deletions Lagerregal/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import unicode_literals

import uuid
from datetime import date, timedelta

Expand Down Expand Up @@ -42,15 +43,15 @@ def convert_ad_accountexpires(timestamp):
if timestamp is None or timestamp == 0:
return None
epoch_start = date(year=1601, month=1, day=1)
seconds_since_epoch = timestamp/10**7
seconds_since_epoch = timestamp / 10 ** 7
try:
# ad timestamp can be > than date.max, return None (==never expires)
new_date = epoch_start + timedelta(seconds=seconds_since_epoch)
return new_date
except OverflowError:
return None
except Exception:
print('Cannot convert expiration_date "{0}", falling back to None'.format(self.expiration_date))
print('Cannot convert expiration_date "{0}", falling back to None'.format(timestamp))


class DetectableTestRunner(DiscoverRunner):
Expand Down
1 change: 1 addition & 0 deletions api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@ class DeviceApiPicture(generics.RetrieveDestroyAPIView):
queryset = Picture.objects.all()
serializer_class = PictureSerializer


class DeviceApiPictureRotate(generics.RetrieveUpdateAPIView):
model = Picture
queryset = Picture.objects.all()
Expand Down
3 changes: 2 additions & 1 deletion devices/ajax.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

import json
import time
import csv
Expand Down Expand Up @@ -442,7 +443,7 @@ def post(self, request):
return render(request, 'devices/searchresult.html', context)
except ValueError:
context = {
"wrong_id_format" : True
"wrong_id_format": True
}
return render(request, 'devices/searchempty.html', context)
except Device.DoesNotExist:
Expand Down
9 changes: 4 additions & 5 deletions devices/forms.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from __future__ import unicode_literals

import re

from django import forms
Expand Down Expand Up @@ -66,14 +67,14 @@

def get_department_options():
try:
return DEPARTMENT_OPTIONS+list(Department.objects.all().values_list("id", "name"))
return DEPARTMENT_OPTIONS + list(Department.objects.all().values_list("id", "name"))
except OperationalError:
return []


def get_devicegroup_options():
try:
return [('all', _('All Groups')), ]+list(Devicegroup.objects.all().values_list("id", "name"))
return [('all', _('All Groups'))] + list(Devicegroup.objects.all().values_list("id", "name"))
except OperationalError:
return []

Expand Down Expand Up @@ -184,7 +185,7 @@ def __init__(self, pk=None, *args, **kwargs):
super(LendForm, self).__init__(*args, **kwargs)
device = None
try:
device = Device.objects.filter(pk = pk)[0]
device = Device.objects.filter(pk=pk)[0]
except:
pass
if device:
Expand All @@ -194,8 +195,6 @@ def __init__(self, pk=None, *args, **kwargs):
self.fields['device'].initial = device
print(self.fields['device'].initial)



def clean_device(self):
device = self.cleaned_data["device"]
return device
Expand Down
4 changes: 2 additions & 2 deletions devices/management/commands/ldapimport.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def paged_search_ext_s(self, base, scope, filterstr='(objectClass=*)', attrlist=
# Send first search request
msgid = self.search_ext(
*settings.LDAP_USER_SEARCH,
serverctrls=(serverctrls or [])+[req_ctrl]
serverctrls=(serverctrls or []) + [req_ctrl]
)

result_pages = 0
Expand All @@ -49,7 +49,7 @@ def paged_search_ext_s(self, base, scope, filterstr='(objectClass=*)', attrlist=
if pctrls[0].cookie:
# Copy cookie from response control to request control
req_ctrl.cookie = pctrls[0].cookie
msgid = self.search_ext(*settings.LDAP_USER_SEARCH, serverctrls=(serverctrls or [])+[req_ctrl])
msgid = self.search_ext(*settings.LDAP_USER_SEARCH, serverctrls=(serverctrls or []) + [req_ctrl])
else:
break
return result_pages, all_results
Expand Down
8 changes: 5 additions & 3 deletions devices/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def get_as_dict(self):
return dict

def is_overdue(self):
if self.currentlending == None:
if self.currentlending is None:
return False
if self.currentlending.duedate < datetime.date.today():
return True
Expand Down Expand Up @@ -207,10 +207,12 @@ class Meta:
verbose_name_plural = _('Information')


reversion.register(Device, follow=["typeattributevalue_set", ], exclude=
["archived", "currentlending", "inventoried", "bookmarks", "trashed"], ignore_duplicates=True)
reversion.register(Device, follow=["typeattributevalue_set", ], exclude=[
"archived", "currentlending", "inventoried", "bookmarks", "trashed",
], ignore_duplicates=True)
reversion.register(TypeAttributeValue)


@reversion.register(ignore_duplicates=True)
class Lending(models.Model):
owner = models.ForeignKey(Lageruser, verbose_name=_("Lent to"), on_delete=models.SET_NULL, null=True)
Expand Down
8 changes: 5 additions & 3 deletions devices/perms.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from __future__ import unicode_literals

__author__ = 'viirus'
from permission.logics import PermissionLogic
from permission.conf import settings
from django.contrib import auth
from django.core.exceptions import PermissionDenied

from permission.conf import settings
from permission.logics import PermissionLogic

__author__ = 'viirus'


class DevicePermissionLogic(PermissionLogic):
def __init__(self,
Expand Down
6 changes: 4 additions & 2 deletions devices/templatetags/devicetags.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
from __future__ import unicode_literals
import re

import os
import re

import six
from django.template import Library
from django.utils.safestring import mark_safe
from django.forms import CheckboxInput

import six

from devices.models import Bookmark

register = Library()
Expand Down
61 changes: 37 additions & 24 deletions devices/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,22 @@ def setUp(self):
def test_device_creation(self):
'''method for testing the functionality of creating a new device'''
device = mommy.make(Device)
lending_past = mommy.make(Lending, duedate = (datetime.today() - timedelta(days = 1)).date())
lending_future = mommy.make(Lending, duedate = (datetime.today() + timedelta(days = 1)).date())
lending_past = mommy.make(Lending, duedate=(datetime.today() - timedelta(days=1)).date())
lending_future = mommy.make(Lending, duedate=(datetime.today() + timedelta(days=1)).date())
self.assertTrue(isinstance(device, Device))
self.assertEqual(six.text_type(device), device.name)
self.assertEqual(device.get_absolute_url(), reverse('device-detail', kwargs={'pk': device.pk}))
self.assertEqual(device.get_edit_url(), reverse('device-edit', kwargs={'pk': device.pk}))
self.assertEqual(device.get_as_dict(), {"name": device.name, "description": device.description, "manufacturer": device.manufacturer, "devicetype" : device.devicetype, "room" : device.room})
self.assertEqual(device.get_as_dict(), {
"name": device.name,
"description": device.description,
"manufacturer": device.manufacturer,
"devicetype": device.devicetype,
"room": device.room,
})
self.assertFalse(device.is_overdue())
self.assertTrue(mommy.make(Device, currentlending = lending_past).is_overdue())
self.assertFalse(mommy.make(Device, currentlending = lending_future).is_overdue())
self.assertTrue(mommy.make(Device, currentlending=lending_past).is_overdue())
self.assertFalse(mommy.make(Device, currentlending=lending_future).is_overdue())

def test_device_list(self):
mommy.make(Device, _quantity=40)
Expand All @@ -58,7 +64,7 @@ def test_device_detail(self):
self.assertEqual(resp.status_code, 200)

def test_device_add(self):
device = mommy.make(Device, name = "used")
device = mommy.make(Device, name="used")
url = reverse("device-add")
resp = self.client.get(url)
self.assertEqual(resp.status_code, 200)
Expand All @@ -67,7 +73,7 @@ def test_device_add(self):
data['uses'] = device.id
data['name'] = "uses"
resp = self.client.post(url, data)
device = Device.objects.filter(name = 'used')[0]
device = Device.objects.filter(name='used')[0]
self.assertEqual(device.used_in.name, 'uses')

def test_device_edit(self):
Expand Down Expand Up @@ -122,17 +128,17 @@ def test_device_trash(self):

def test_device_trash_sets_child_used_in_to_none(self):
device = mommy.make(Device)
used_device = mommy.make(Device, used_in = device)
used_device = mommy.make(Device, used_in=device)
trashurl = reverse('device-trash', kwargs={'pk': device.pk})
self.client.post(trashurl)
used_device = Device.objects.filter(pk = used_device.pk)[0]
used_device = Device.objects.filter(pk=used_device.pk)[0]
self.assertIsNone(used_device.used_in)

def test_device_trash_sets_self_used_in_to_none(self):
device = mommy.make(Device, _fill_optional=['used_in'])
trashurl = reverse("device-trash", kwargs={'pk' : device.pk})
trashurl = reverse("device-trash", kwargs={'pk': device.pk})
self.client.post(trashurl)
device = Device.objects.filter(pk = device.pk)[0]
device = Device.objects.filter(pk=device.pk)[0]
self.assertIsNone(device.used_in)

def test_device_trash_returns_lending(self):
Expand Down Expand Up @@ -197,13 +203,13 @@ def test_device_ipaddress(self):

def test_device_lending_list(self):
lending = mommy.make(Lending)
device = mommy.make(Device, currentlending = lending)
url = reverse("device-lending-list", kwargs = {"pk": device.pk})
device = mommy.make(Device, currentlending=lending)
url = reverse("device-lending-list", kwargs={"pk": device.pk})
resp = self.client.get(url)
self.assertEqual(resp.status_code, 200)

def test_device_lend(self):
device = mommy.make(Device, archived = None)
device = mommy.make(Device, archived=None)
room = mommy.make(Room)
room.save()
lending = mommy.make(Lending)
Expand All @@ -223,13 +229,13 @@ def test_device_return(self):
device = devices[0]
user = mommy.make(Lageruser)

lending = mommy.make(Lending, owner = user)
url = reverse("device-return", kwargs = {"lending": lending.id})
lending = mommy.make(Lending, owner=user)
url = reverse("device-return", kwargs={"lending": lending.id})
resp = self.client.post(url)
self.assertEqual(resp.status_code, 302)

lending2 = mommy.make(Lending, device = device)
url = reverse("device-return", kwargs = {"lending": lending2.id})
lending2 = mommy.make(Lending, device=device)
url = reverse("device-return", kwargs={"lending": lending2.id})
resp = self.client.post(url)
self.assertEqual(resp.status_code, 302)

Expand Down Expand Up @@ -298,7 +304,7 @@ def setUp(self):
def test_room_creation(self):
room = mommy.make(Room)
building = mommy.make(Building)
room_in_building = mommy.make(Room, building = building)
room_in_building = mommy.make(Room, building=building)
self.assertTrue(isinstance(room, Room))
self.assertEqual(six.text_type(room), room.name)
self.assertTrue(isinstance(room_in_building, Room))
Expand Down Expand Up @@ -413,7 +419,12 @@ def test_template_creation(self):
self.assertTrue(isinstance(template, Template))
self.assertEqual(six.text_type(template), template.templatename)
self.assertEqual(template.get_absolute_url(), reverse('device-list'))
self.assertEqual(template.get_as_dict(), {'name': template.name, 'description': template.description, 'manufacturer' : template.manufacturer, 'devicetype' : template.devicetype })
self.assertEqual(template.get_as_dict(), {
'name': template.name,
'description': template.description,
'manufacturer': template.manufacturer,
'devicetype': template.devicetype,
})

def test_template_list(self):
mommy.make(Template, _quantity=40)
Expand Down Expand Up @@ -459,22 +470,24 @@ def test_note_creation(self):
self.assertTrue(isinstance(note, Note))
self.assertEqual(note.get_absolute_url(), reverse('device-detail', kwargs={'pk': note.device.pk}))


class DeviceInformationTypeTests(TestCase):
def setUp(self):
self.client = Client()
Lageruser.objects.create_superuser('test', '[email protected]', 'test')
self.client.login(username = 'test', password = 'test')
self.client.login(username='test', password='test')

def test_device_information_type_creation(self):
information = mommy.make(DeviceInformationType)
self.assertTrue(isinstance(information, DeviceInformationType))
self.assertEqual(six.text_type(information), information.humanname)


class DeviceInformationTests(TestCase):
def setUp(self):
self.client = Client()
Lageruser.objects.create_superuser('test', '[email protected]', 'test')
self.client.login(username = 'test', password = 'test')
self.client.login(username='test', password='test')

def test_device_information_creation(self):
device_information = mommy.make(DeviceInformation)
Expand All @@ -489,6 +502,6 @@ def setUp(self):

def test_picture_creation(self):
device = mommy.make(Device)
picture = mommy.make(Picture, device = device)
picture = mommy.make(Picture, device=device)
self.assertTrue(isinstance(picture, Picture))
self.assertEqual(picture.get_absolute_url(), reverse('device-detail', kwargs={'pk': picture.device.pk}) )
self.assertEqual(picture.get_absolute_url(), reverse('device-detail', kwargs={'pk': picture.device.pk}))
Loading

0 comments on commit 1c001fe

Please sign in to comment.