Reformat all the things

Python code is now formatted to PEP8

All other files are defined in .editorconfig as far as possible.
This commit is contained in:
Tom Price
2016-08-09 19:42:39 +01:00
parent 024f08562b
commit 567f899a39
75 changed files with 3606 additions and 2667 deletions

View File

@@ -1,9 +1,11 @@
from datetime import date, timedelta, datetime, time
from decimal import *
import pytz
from django.conf import settings
from django.test import TestCase
from RIGS import models
from datetime import date, timedelta, datetime, time
from decimal import *
class ProfileTestCase(TestCase):
@@ -16,8 +18,10 @@ class ProfileTestCase(TestCase):
class VatRateTestCase(TestCase):
def setUp(self):
models.VatRate.objects.create(start_at='2014-03-01', rate=0.20, comment='test1')
models.VatRate.objects.create(start_at='2016-03-01', rate=0.15, comment='test2')
models.VatRate.objects.create(
start_at='2014-03-01', rate=0.20, comment='test1')
models.VatRate.objects.create(
start_at='2016-03-01', rate=0.15, comment='test2')
def test_find_correct(self):
r = models.VatRate.objects.find_rate('2015-03-01')
@@ -34,18 +38,27 @@ class EventTestCase(TestCase):
def setUp(self):
self.all_events = set(range(1, 18))
self.current_events = (1, 2, 3, 6, 7, 8, 10, 11, 12, 14, 15, 16, 18)
self.not_current_events = set(self.all_events) - set(self.current_events)
self.not_current_events = set(
self.all_events) - set(self.current_events)
self.vatrate = models.VatRate.objects.create(start_at='2014-03-05', rate=0.20, comment='test1')
self.profile = models.Profile.objects.create(username="testuser1", email="1@test.com")
self.vatrate = models.VatRate.objects.create(
start_at='2014-03-05', rate=0.20, comment='test1')
self.profile = models.Profile.objects.create(
username="testuser1", email="1@test.com")
# produce 7 normal events - 5 current
models.Event.objects.create(name="TE E1", start_date=date.today() + timedelta(days=6),
description="start future no end")
models.Event.objects.create(name="TE E2", start_date=date.today(), description="start today no end")
models.Event.objects.create(
name="TE E2",
start_date=date.today(),
description="start today no end")
models.Event.objects.create(name="TE E3", start_date=date.today(), end_date=date.today(),
description="start today with end today")
models.Event.objects.create(name="TE E4", start_date='2014-03-20', description="start past no end")
models.Event.objects.create(
name="TE E4",
start_date='2014-03-20',
description="start past no end")
models.Event.objects.create(name="TE E5", start_date='2014-03-20', end_date='2014-03-21',
description="start past with end past")
models.Event.objects.create(name="TE E6", start_date=date.today() - timedelta(days=2),
@@ -62,7 +75,11 @@ class EventTestCase(TestCase):
description="cancelled and started")
# 5 dry hire - 3 current
models.Event.objects.create(name="TE E10", start_date=date.today(), dry_hire=True, description="dryhire today")
models.Event.objects.create(
name="TE E10",
start_date=date.today(),
dry_hire=True,
description="dryhire today")
models.Event.objects.create(name="TE E11", start_date=date.today(), dry_hire=True, checked_in_by=self.profile,
description="dryhire today, checked in")
models.Event.objects.create(name="TE E12", start_date=date.today() - timedelta(days=1), dry_hire=True,
@@ -73,7 +90,11 @@ class EventTestCase(TestCase):
status=models.Event.CANCELLED, description="dryhire today cancelled")
# 4 non rig - 3 current
models.Event.objects.create(name="TE E15", start_date=date.today(), is_rig=False, description="non rig today")
models.Event.objects.create(
name="TE E15",
start_date=date.today(),
is_rig=False,
description="non rig today")
models.Event.objects.create(name="TE E16", start_date=date.today() + timedelta(days=1), is_rig=False,
description="non rig tomorrow")
models.Event.objects.create(name="TE E17", start_date=date.today() - timedelta(days=1), is_rig=False,
@@ -83,7 +104,8 @@ class EventTestCase(TestCase):
def test_count(self):
# Santiy check we have the expected events created
self.assertEqual(models.Event.objects.count(), 18, "Incorrect number of events, check setup")
self.assertEqual(models.Event.objects.count(), 18,
"Incorrect number of events, check setup")
def test_rig_count(self):
# by my count this is 7
@@ -93,10 +115,16 @@ class EventTestCase(TestCase):
current_events = models.Event.objects.current_events()
self.assertEqual(len(current_events), len(self.current_events))
for eid in self.current_events:
self.assertIn(models.Event.objects.get(name="TE E%d" % eid), current_events)
self.assertIn(
models.Event.objects.get(
name="TE E%d" %
eid), current_events)
for eid in self.not_current_events:
self.assertNotIn(models.Event.objects.get(name="TE E%d" % eid), current_events)
self.assertNotIn(
models.Event.objects.get(
name="TE E%d" %
eid), current_events)
def test_related_venue(self):
v1 = models.Venue.objects.create(name="TE V1")
@@ -204,29 +232,43 @@ class EventTestCase(TestCase):
event.save()
def test_earliest_time(self):
event = models.Event(name="TE ET", start_date=date(2016, 01, 01))
event = models.Event(name="TE ET", start_date=date(2016, 0o1, 0o1))
# Just a start date
self.assertEqual(event.earliest_time, date(2016, 01, 01))
self.assertEqual(event.earliest_time, date(2016, 0o1, 0o1))
# With start time
event.start_time = time(9, 00)
self.assertEqual(event.earliest_time, self.create_datetime(2016, 1, 1, 9, 00))
self.assertEqual(
event.earliest_time,
self.create_datetime(
2016,
1,
1,
9,
00))
# With access time
event.access_at = self.create_datetime(2015, 12, 03, 9, 57)
event.access_at = self.create_datetime(2015, 12, 0o3, 9, 57)
self.assertEqual(event.earliest_time, event.access_at)
# With meet time
event.meet_at = self.create_datetime(2015, 12, 03, 9, 55)
event.meet_at = self.create_datetime(2015, 12, 0o3, 9, 55)
self.assertEqual(event.earliest_time, event.meet_at)
# Check order isn't important
event.start_date = date(2015, 12, 03)
self.assertEqual(event.earliest_time, self.create_datetime(2015, 12, 03, 9, 00))
event.start_date = date(2015, 12, 0o3)
self.assertEqual(
event.earliest_time,
self.create_datetime(
2015,
12,
0o3,
9,
00))
def test_latest_time(self):
event = models.Event(name="TE LT", start_date=date(2016, 01, 01))
event = models.Event(name="TE LT", start_date=date(2016, 0o1, 0o1))
# Just start date
self.assertEqual(event.latest_time, event.start_date)
@@ -237,25 +279,48 @@ class EventTestCase(TestCase):
# With end time
event.end_time = time(23, 00)
self.assertEqual(event.latest_time, self.create_datetime(2016, 1, 2, 23, 00))
self.assertEqual(
event.latest_time, self.create_datetime(
2016, 1, 2, 23, 00))
def test_in_bounds(self):
manager = models.Event.objects
events = [
manager.create(name="TE IB0", start_date='2016-01-02'), # yes no
manager.create(name="TE IB1", start_date='2015-12-31', end_date='2016-01-04'),
manager.create(
name="TE IB1",
start_date='2015-12-31',
end_date='2016-01-04'),
# basic checks
manager.create(name='TE IB2', start_date='2016-01-02', end_date='2016-01-04'),
manager.create(name='TE IB3', start_date='2015-12-31', end_date='2016-01-03'),
manager.create(name='TE IB4', start_date='2016-01-04', access_at='2016-01-03'),
manager.create(name='TE IB5', start_date='2016-01-04', meet_at='2016-01-02'),
manager.create(
name='TE IB2',
start_date='2016-01-02',
end_date='2016-01-04'),
manager.create(
name='TE IB3',
start_date='2015-12-31',
end_date='2016-01-03'),
manager.create(
name='TE IB4',
start_date='2016-01-04',
access_at='2016-01-03'),
manager.create(
name='TE IB5',
start_date='2016-01-04',
meet_at='2016-01-02'),
# negative check
manager.create(name='TE IB6', start_date='2015-12-31', end_date='2016-01-01'),
manager.create(
name='TE IB6',
start_date='2015-12-31',
end_date='2016-01-01'),
]
in_bounds = manager.events_in_bounds(datetime(2016, 1, 2), datetime(2016, 1, 3))
in_bounds = manager.events_in_bounds(
datetime(
2016, 1, 2), datetime(
2016, 1, 3))
self.assertIn(events[0], in_bounds)
self.assertIn(events[1], in_bounds)
self.assertIn(events[2], in_bounds)
@@ -272,11 +337,14 @@ class EventTestCase(TestCase):
class EventItemTestCase(TestCase):
def setUp(self):
self.e1 = models.Event.objects.create(name="TI E1", start_date=date.today())
self.e2 = models.Event.objects.create(name="TI E2", start_date=date.today())
self.e1 = models.Event.objects.create(
name="TI E1", start_date=date.today())
self.e2 = models.Event.objects.create(
name="TI E2", start_date=date.today())
def test_item_cost(self):
item = models.EventItem.objects.create(event=self.e1, name="TI I1", quantity=1, cost=1.00, order=1)
item = models.EventItem.objects.create(
event=self.e1, name="TI I1", quantity=1, cost=1.00, order=1)
self.assertEqual(item.total_cost, 1.00)
item.cost = 2.50
@@ -289,8 +357,10 @@ class EventItemTestCase(TestCase):
item.delete()
def test_item_order(self):
i1 = models.EventItem.objects.create(event=self.e1, name="TI I1", quantity=1, cost=1.00, order=1)
i2 = models.EventItem.objects.create(event=self.e1, name="TI I2", quantity=1, cost=1.00, order=2)
i1 = models.EventItem.objects.create(
event=self.e1, name="TI I1", quantity=1, cost=1.00, order=1)
i2 = models.EventItem.objects.create(
event=self.e1, name="TI I2", quantity=1, cost=1.00, order=2)
items = self.e1.items.all()
self.assertListEqual([i1, i2], list(items))
@@ -298,17 +368,29 @@ class EventItemTestCase(TestCase):
class EventPricingTestCase(TestCase):
def setUp(self):
models.VatRate.objects.create(rate=0.20, comment="TP V1", start_at='2013-01-01')
models.VatRate.objects.create(rate=0.10, comment="TP V2", start_at=date.today() - timedelta(days=1))
self.e1 = models.Event.objects.create(name="TP E1", start_date=date.today() - timedelta(days=2))
self.e2 = models.Event.objects.create(name="TP E2", start_date=date.today())
models.VatRate.objects.create(
rate=0.20, comment="TP V1", start_at='2013-01-01')
models.VatRate.objects.create(
rate=0.10,
comment="TP V2",
start_at=date.today() -
timedelta(
days=1))
self.e1 = models.Event.objects.create(
name="TP E1", start_date=date.today() - timedelta(days=2))
self.e2 = models.Event.objects.create(
name="TP E2", start_date=date.today())
# Create some items E1, total 70.40
# Create some items E2, total 381.20
self.i1 = models.EventItem.objects.create(event=self.e1, name="TP I1", quantity=1, cost=50.00, order=1)
self.i2 = models.EventItem.objects.create(event=self.e1, name="TP I2", quantity=2, cost=3.20, order=2)
self.i3 = models.EventItem.objects.create(event=self.e1, name="TP I3", quantity=7, cost=2.00, order=3)
self.i4 = models.EventItem.objects.create(event=self.e2, name="TP I4", quantity=2, cost=190.60, order=1)
self.i1 = models.EventItem.objects.create(
event=self.e1, name="TP I1", quantity=1, cost=50.00, order=1)
self.i2 = models.EventItem.objects.create(
event=self.e1, name="TP I2", quantity=2, cost=3.20, order=2)
self.i3 = models.EventItem.objects.create(
event=self.e1, name="TP I3", quantity=7, cost=2.00, order=3)
self.i4 = models.EventItem.objects.create(
event=self.e2, name="TP I4", quantity=2, cost=190.60, order=1)
# Decimal type is needed here as that is what is returned from the model.
# Using anything else results in a failure due to floating point arritmetic