From b7c4d286ffa618be0e95b15f3883e2f6920a3fb1 Mon Sep 17 00:00:00 2001 From: Parker Berberian Date: Tue, 20 Nov 2018 11:19:55 -0500 Subject: Fix all flake8 errors The flake8 command in test.sh finds no longer finds any errors. This may form a basis of a jenkins verify job as a sort of 'weak compile-time checks' The flake8 command will not complain about line length, and will not complain about django's manage.py file Change-Id: Ic47cb4fc7ada55e64485661ab6881aef475018ff Signed-off-by: Parker Berberian --- src/booking/admin.py | 2 +- src/booking/models.py | 7 ++--- src/booking/stats.py | 10 ++++--- src/booking/tests/test_models.py | 63 ++++++++++++++++++++++++---------------- src/booking/urls.py | 9 +++++- src/booking/views.py | 28 +++++++++--------- 6 files changed, 69 insertions(+), 50 deletions(-) (limited to 'src/booking') diff --git a/src/booking/admin.py b/src/booking/admin.py index 2beb05b..162777e 100644 --- a/src/booking/admin.py +++ b/src/booking/admin.py @@ -11,6 +11,6 @@ from django.contrib import admin -from booking.models import * +from booking.models import Booking admin.site.register(Booking) diff --git a/src/booking/models.py b/src/booking/models.py index adfc28d..d0c77b4 100644 --- a/src/booking/models.py +++ b/src/booking/models.py @@ -11,11 +11,8 @@ from resource_inventory.models import ResourceBundle, ConfigBundle from account.models import Lab -from django.conf import settings from django.contrib.auth.models import User from django.db import models -from jira import JIRA -from jira import JIRAError import resource_inventory.resource_manager @@ -47,7 +44,7 @@ class Opsys(models.Model): class Booking(models.Model): id = models.AutoField(primary_key=True) - owner = models.ForeignKey(User, models.CASCADE, related_name='owner') # delete if user is deleted + owner = models.ForeignKey(User, models.CASCADE, related_name='owner') collaborators = models.ManyToManyField(User, related_name='collaborators') start = models.DateTimeField() end = models.DateTimeField() @@ -56,7 +53,7 @@ class Booking(models.Model): jira_issue_status = models.CharField(max_length=50, blank=True) purpose = models.CharField(max_length=300, blank=False) ext_count = models.IntegerField(default=2) - resource = models.ForeignKey(ResourceBundle, on_delete=models.SET_NULL, null=True) #need to decide behavior here on delete + resource = models.ForeignKey(ResourceBundle, on_delete=models.SET_NULL, null=True) config_bundle = models.ForeignKey(ConfigBundle, on_delete=models.SET_NULL, null=True) project = models.CharField(max_length=100, default="", blank=True, null=True) lab = models.ForeignKey(Lab, null=True, on_delete=models.SET_NULL) diff --git a/src/booking/stats.py b/src/booking/stats.py index 31f7ef1..b706577 100644 --- a/src/booking/stats.py +++ b/src/booking/stats.py @@ -19,9 +19,11 @@ class StatisticsManager(object): Will return a dictionary of names and 2-D array of x and y data points. e.g. {"plot1": [["x1", "x2", "x3"],["y1", "y2", "y3]]} x values will be dates in string - every change (booking start / end) will be reflected, instead of one data point per day - y values are the integer number of bookings/users active at some point in the given date - span is the number of days to plot. The last x value will always be the current time + every change (booking start / end) will be reflected, + instead of one data point per day + y values are the integer number of bookings/users active at + some point in the given date span is the number of days to plot. + The last x value will always be the current time """ x_set = set() x = [] @@ -29,7 +31,7 @@ class StatisticsManager(object): users = [] now = datetime.datetime.now(pytz.utc) delta = datetime.timedelta(days=span) - end = now-delta + end = now - delta bookings = Booking.objects.filter(start__lte=now, end__gte=end) for booking in bookings: x_set.add(booking.start) diff --git a/src/booking/tests/test_models.py b/src/booking/tests/test_models.py index a83f817..c7fb25d 100644 --- a/src/booking/tests/test_models.py +++ b/src/booking/tests/test_models.py @@ -11,25 +11,33 @@ from datetime import timedelta -from django.contrib.auth.models import Permission +from django.contrib.auth.models import Permission, User from django.test import TestCase from django.utils import timezone -from booking.models import * +# from booking.models import * +from booking.models import Booking from resource_inventory.models import ResourceBundle, GenericResourceBundle, ConfigBundle + class BookingModelTestCase(TestCase): + count = 0 + def setUp(self): self.owner = User.objects.create(username='owner') self.res1 = ResourceBundle.objects.create( - template=GenericResourceBundle.objects.create(name="gbundle" + str(self.count)) - ) + template=GenericResourceBundle.objects.create( + name="gbundle" + str(self.count) + ) + ) self.count += 1 self.res2 = ResourceBundle.objects.create( - template=GenericResourceBundle.objects.create(name="gbundle2" + str(self.count)) - ) + template=GenericResourceBundle.objects.create( + name="gbundle2" + str(self.count) + ) + ) self.count += 1 self.user1 = User.objects.create(username='user1') @@ -37,12 +45,15 @@ class BookingModelTestCase(TestCase): self.user1.user_permissions.add(self.add_booking_perm) self.user1 = User.objects.get(pk=self.user1.id) - self.config_bundle = ConfigBundle.objects.create(owner=self.user1, name="test config") + self.config_bundle = ConfigBundle.objects.create( + owner=self.user1, + name="test config" + ) def test_start_end(self): """ - if the start of a booking is greater or equal then the end, saving should raise a - ValueException + if the start of a booking is greater or equal then the end, + saving should raise a ValueException """ start = timezone.now() end = start - timedelta(weeks=1) @@ -54,7 +65,7 @@ class BookingModelTestCase(TestCase): resource=self.res1, owner=self.user1, config_bundle=self.config_bundle - ) + ) end = start self.assertRaises( ValueError, @@ -64,11 +75,12 @@ class BookingModelTestCase(TestCase): resource=self.res1, owner=self.user1, config_bundle=self.config_bundle - ) + ) def test_conflicts(self): """ - saving an overlapping booking on the same resource should raise a ValueException + saving an overlapping booking on the same resource + should raise a ValueException saving for different resources should succeed """ start = timezone.now() @@ -80,8 +92,8 @@ class BookingModelTestCase(TestCase): owner=self.user1, resource=self.res1, config_bundle=self.config_bundle - ) ) + ) self.assertRaises( ValueError, @@ -91,7 +103,8 @@ class BookingModelTestCase(TestCase): resource=self.res1, owner=self.user1, config_bundle=self.config_bundle - ) + ) + self.assertRaises( ValueError, Booking.objects.create, @@ -100,7 +113,7 @@ class BookingModelTestCase(TestCase): resource=self.res1, owner=self.user1, config_bundle=self.config_bundle - ) + ) self.assertRaises( ValueError, @@ -110,7 +123,7 @@ class BookingModelTestCase(TestCase): resource=self.res1, owner=self.user1, config_bundle=self.config_bundle - ) + ) self.assertRaises( ValueError, @@ -120,7 +133,7 @@ class BookingModelTestCase(TestCase): resource=self.res1, owner=self.user1, config_bundle=self.config_bundle - ) + ) self.assertRaises( ValueError, @@ -130,7 +143,7 @@ class BookingModelTestCase(TestCase): resource=self.res1, owner=self.user1, config_bundle=self.config_bundle - ) + ) self.assertRaises( ValueError, @@ -140,7 +153,7 @@ class BookingModelTestCase(TestCase): resource=self.res1, owner=self.user1, config_bundle=self.config_bundle - ) + ) self.assertTrue( Booking.objects.create( @@ -149,8 +162,9 @@ class BookingModelTestCase(TestCase): owner=self.user1, resource=self.res1, config_bundle=self.config_bundle - ) ) + ) + self.assertTrue( Booking.objects.create( start=end, @@ -158,8 +172,8 @@ class BookingModelTestCase(TestCase): owner=self.user1, resource=self.res1, config_bundle=self.config_bundle - ) ) + ) self.assertTrue( Booking.objects.create( @@ -168,8 +182,8 @@ class BookingModelTestCase(TestCase): owner=self.user1, resource=self.res1, config_bundle=self.config_bundle - ) ) + ) self.assertTrue( Booking.objects.create( @@ -178,8 +192,8 @@ class BookingModelTestCase(TestCase): owner=self.user1, resource=self.res1, config_bundle=self.config_bundle - ) ) + ) self.assertTrue( Booking.objects.create( @@ -188,8 +202,8 @@ class BookingModelTestCase(TestCase): owner=self.user1, resource=self.res2, config_bundle=self.config_bundle - ) ) + ) def test_extensions(self): """ @@ -223,4 +237,3 @@ class BookingModelTestCase(TestCase): self.assertTrue(booking.save()) except Exception: self.fail("save() threw an exception") - diff --git a/src/booking/urls.py b/src/booking/urls.py index 88fbb0a..4d00b7f 100644 --- a/src/booking/urls.py +++ b/src/booking/urls.py @@ -26,7 +26,14 @@ Including another URLconf """ from django.conf.urls import url -from booking.views import * +from booking.views import ( + booking_detail_view, + BookingDeleteView, + bookingDelete, + BookingListView, + booking_stats_view, + booking_stats_json +) app_name = "booking" urlpatterns = [ diff --git a/src/booking/views.py b/src/booking/views.py index a0ea31d..ab43519 100644 --- a/src/booking/views.py +++ b/src/booking/views.py @@ -11,10 +11,8 @@ from django.contrib import messages from django.shortcuts import get_object_or_404 from django.http import JsonResponse -from django.urls import reverse from django.utils import timezone from django.views import View -from django.views.generic import FormView from django.views.generic import TemplateView from django.shortcuts import redirect, render import json @@ -107,22 +105,24 @@ def booking_detail_view(request, booking_id): allowed_users.add(booking.owner) if user not in allowed_users: return render(request, "dashboard/login.html", {'title': 'This page is private'}) - return render(request, "booking/booking_detail.html", { - 'title': 'Booking Details', - 'booking': booking, - 'pdf': ResourceManager().makePDF(booking.resource), - 'user_id': user.id}) + + return render( + request, + "booking/booking_detail.html", + { + 'title': 'Booking Details', + 'booking': booking, + 'pdf': ResourceManager().makePDF(booking.resource), + 'user_id': user.id + }) def booking_stats_view(request): return render( - request, - "booking/stats.html", - context={ - "data": StatisticsManager.getContinuousBookingTimeSeries(), - "title": "Booking Statistics" - } - ) + request, + "booking/stats.html", + context={"data": StatisticsManager.getContinuousBookingTimeSeries(), "title": "Booking Statistics"} + ) def booking_stats_json(request): -- cgit 1.2.3-korg