From b887f00b1f75ba9f34118a86dd25fe3a022c9a95 Mon Sep 17 00:00:00 2001 From: Maxim Pak Date: Sat, 26 Nov 2016 23:14:33 +1100 Subject: [PATCH] Refactored tests to use sqlite --- .gitignore | 1 + README.md | 4 +- container-app/Dockerfile | 3 +- container-app/requirements.txt | 2 + parker/old_tests.py | 523 ------------------ parker/settings/__init__.py | 0 .../default.py} | 22 +- parker/settings/test.py | 153 +++++ parker/tests/__init__.py | 0 parker/{tests.py => tests/test_scripts.py} | 50 -- 10 files changed, 171 insertions(+), 587 deletions(-) delete mode 100644 parker/old_tests.py create mode 100644 parker/settings/__init__.py rename parker/{settings.default.py => settings/default.py} (94%) create mode 100644 parker/settings/test.py create mode 100644 parker/tests/__init__.py rename parker/{tests.py => tests/test_scripts.py} (60%) diff --git a/.gitignore b/.gitignore index b656e06..f60ce65 100644 --- a/.gitignore +++ b/.gitignore @@ -59,4 +59,5 @@ __history/ #settings file parker/settings.py +parker/tmp.txt static/admin diff --git a/README.md b/README.md index 5bcbf8e..7fee4c5 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Copy the contents from _parker/settings.default.py_ into the new file. Alternatively, on Unix/Linux systems you can simply create a symlink by running. ``` -ln -s parker/settings.default.py parker/settings.py +ln -s parker/settings/default.py parker/settings.py ``` Start docker containers @@ -56,7 +56,7 @@ The main test drill function is **test_main_drill()**. If working in TDD manner, To execute test run: ``` -python3 manage.py test +python3 manage.py test --settings parker.settings.test ``` ### Backing up database diff --git a/container-app/Dockerfile b/container-app/Dockerfile index 478f11f..2174d6e 100644 --- a/container-app/Dockerfile +++ b/container-app/Dockerfile @@ -20,7 +20,8 @@ RUN apt-get update && apt-get install -y \ mysql-client \ netcat \ fontconfig \ - curl + curl \ + sqlite3 # Install SASS RUN gem install sass diff --git a/container-app/requirements.txt b/container-app/requirements.txt index 6e1c8ff..508d86a 100644 --- a/container-app/requirements.txt +++ b/container-app/requirements.txt @@ -7,3 +7,5 @@ mysqlclient selenium sqlparse uWSGI +coverage +django-nose \ No newline at end of file diff --git a/parker/old_tests.py b/parker/old_tests.py deleted file mode 100644 index fa30ea3..0000000 --- a/parker/old_tests.py +++ /dev/null @@ -1,523 +0,0 @@ - def no_test_main_drill(self): - self.maxDiff = None - - print("Testing carparkID = 1") - self._get_prices_information_park_id_1() - - print("Testing carparkID = 2") - self._get_prices_information_park_id_2() - - print("Testing carparkID = 3") - self._get_prices_information_park_id_3() - - print("Testing carparkID = 4") - self._get_prices_information_park_id_4() - - print("Testing carparkID = 5") - self._get_prices_information_park_id_5() - - print("Testing carparkID = 6") - self._get_prices_information_park_id_6() - - print("Testing carparkID = 7") - self._get_prices_information_park_id_7() - - print("Testing carparkID = 8") - self._get_prices_information_park_id_8() - - print("Testing carparkID = 9") - self._get_prices_information_park_id_9() - - # print("Testing carparkID = 10") - # self._get_prices_information_park_id_10() - - def _get_prices_information_park_id_1(self): - url = "http://wilsonparking.com.au/park/2036_Queen-Victoria-Building-Car-Park_111-York-Street-Sydney" - - carpark = Parking.objects.create(parkingID=1, label="Queen Victoria Building Car Park", - address="111 York Street, Sydney", - lat=-33.871109, long=151.206243, parking_type="Wilson", uri=url) - - expected_result = {'Casual': {'days': '', - 'entry_start': '00:00', - 'exit_end': '23:59', - 'notes': ['Mon - Fri', - 'Overnight Fee: $12.00 fee applies for cars ' - 'left in the car park past closing', - 'Valet Service : $10.00 surcharge applies', - 'Public Holidays: Weekend Rates Apply'], - 'prices': {30: '7.00', - 60: '24.00', - 90: '38.00', - 120: '46.00', - 150: '56.00', - 180: '56.00', - 1440: '64.00'}, - 'rate_type': 'hourly'}, - 'Early Bird': {'days': [1, 2, 3, 4, 5], - 'entry_end': '09:30', - 'entry_start': '08:00', - 'exit_end': '19:30', - 'exit_start': '15:00', - 'prices': '24.00', - 'notes': ["Proceed to Level 7 and validate ticket in " - 'morning, park on Level 7'], - 'rate_type': 'flat'}, - 'Super Early Bird': {'days': [1, 2, 3, 4, 5], - 'entry_end': '08:00', - 'entry_start': '06:00', - 'exit_end': '19:30', - 'exit_start': '15:00', - 'prices': '19.00', - 'notes': ["Proceed to Level 7 and validate ticket in " - 'morning, park on Level 7'], - 'rate_type': 'flat'}, - 'Night': {'rates': {0: {'days': [1, 2, 3, 7], - 'entry_start': '17:00', - 'exit_end': '23:59', - 'prices': '12.00', - 'rate_type': 'flat'}, - 1: {'days': [4, 5, 6], - 'entry_start': '17:00', - 'exit_end': '23:59', - 'prices': '15.00', - 'rate_type': 'flat'}}}, - 'Weekend': {'days': [6, 7], - 'entry_start': '00:00', - 'exit_end': '23:59', - 'notes': ['Sat - Sun', 'Per exit, per day'], - 'prices': {30: '7.00', - 60: '7.00', - 90: '16.00', - 120: '16.00', - 150: '21.00', - 180: '21.00', - 1440: '25.00'}, - 'rate_type': 'hourly'}} - - rates, html = self._get_rates(carpark) - - # Check rates returned - self.assertDictEqual(expected_result, rates) - - self._update_rates(carpark, html) - - self._assert_saved_rates(carpark, expected_result) - - def _get_prices_information_park_id_2(self): - url = "https://www.wilsonparking.com.au/park/2135_St-Martins-Tower-Car-Park_190-202-Clarence-Street-Sydney" - - carpark = Parking.objects.create(parkingID=2, label="St Martins Tower Car Park", - address="190-202 Clarence Street, Sydney", - lat=-33.871420, long=151.203594, parking_type="Wilson", uri=url) - - rates, html = self._get_rates(carpark) - expected_result = {'Casual': {'days': '', - 'entry_start': '00:00', - 'exit_end': '23:59', - 'notes': ['Public Holidays: Weekend Rates Apply'], - 'prices': {30: '9.00', - 60: '29.00', - 90: '54.00', - 120: '54.00', - 150: '65.00', - 180: '65.00', - 1440: '78.00'}, - 'rate_type': 'hourly'}, - 'Early Bird': {'days': [1, 2, 3, 4, 5], - 'entry_end': '09:30', - 'entry_start': '08:00', - 'exit_end': '19:00', - 'exit_start': '15:30', - 'prices': '26.00', - 'rate_type': 'flat'}, - 'Night': {'rates': {0: {'days': [1, 2, 3], - 'entry_start': '17:00', - 'exit_end': '23:59', - 'prices': '10.00', - 'rate_type': 'flat'}, - 1: {'days': [4, 5], - 'entry_start': '17:00', - 'exit_end': '23:59', - 'prices': '12.00', - 'rate_type': 'flat'} - } - }, - 'Super Early Bird': {'days': [1, 2, 3, 4, 5], - 'entry_end': '08:00', - 'entry_start': '07:00', - 'exit_end': '19:00', - 'exit_start': '15:30', - 'prices': '24.00', - 'rate_type': 'flat'}, - 'Weekend': {'days': [6, 7], - 'entry_start': '00:00', - 'exit_end': '23:59', - 'rate_type': 'flat', - 'notes': ['Flate rate per exit, per day'], - 'prices': '15.00'}} - - # Check rates returned - self.assertDictEqual(expected_result, rates) - - self._update_rates(carpark, html) - - self._assert_saved_rates(carpark, expected_result) - - def _get_prices_information_park_id_3(self): - url = "https://www.wilsonparking.com.au/park/2047_Harbourside-Car-Park_100-Murray-Street-Pyrmont" - - carpark = Parking.objects.create(parkingID=3, label="Carpark 3", - address="Whatever", - lat=-33.871109, long=151.206243, parking_type="Wilson", uri=url) - - rates, html = self._get_rates(carpark) - expected_result = {'Casual': {'days': '', - 'entry_start': '00:00', - 'exit_end': '23:59', - 'notes': ['Motorcycle', - '$14.00', - 'Rates are calculated from 6:00am daily', - 'Public Holidays: Casual Rates Apply', - 'Motorcycle parkers to park in yellow ' - 'designated areas on Level 4 and contact ' - 'Attendant in Office prior to departure'], - 'prices': {30: '6.00', - 60: '16.00', - 90: '26.00', - 120: '26.00', - 150: '30.00', - 180: '30.00', - 1440: '38.00'}, - 'rate_type': 'hourly'}, - 'Early Bird': {'days': [1, 2, 3, 4, 5], - 'entry_end': '09:30', - 'entry_start': '06:00', - 'exit_end': '19:00', - 'exit_start': '15:00', - 'notes': ['Have ticket validated by machine on ' - 'Level 3 in the morning, proceed to ' - 'Level 1 or 2 for parking'], - 'prices': '15.00', - 'rate_type': 'flat'}, - 'Night': {'rates': {0: {'days': [1, 2, 3, 4], - 'entry_start': '18:00', - 'exit_end': '04:00', - 'prices': '15.00', - 'rate_type': 'flat'}, - 1: {'days': [5], - 'entry_start': '18:00', - 'exit_end': '04:00', - 'prices': '25.00', - 'rate_type': 'flat'}, - 2: {'days': [6], - 'entry_start': '18:00', - 'exit_end': '04:00', - 'prices': '25.00', - 'rate_type': 'flat'}, - 3: {'days': [7], - 'entry_start': '18:00', - 'exit_end': '04:00', - 'prices': '15.00', - 'rate_type': 'flat'}}} - } - - self.assertDictEqual(expected_result, rates) - - self._update_rates(carpark, html) - - self._assert_saved_rates(carpark, expected_result) - - def _get_prices_information_park_id_4(self): - url = "https://www.wilsonparking.com.au/park/2024_175-Liverpool-St-Car-Park_26-Nithsdale-Street-Sydney" - - carpark = Parking.objects.create(parkingID=4, label="Carpark 4", - address="Whatever", - lat=-33.871109, long=151.206243, parking_type="Wilson", uri=url) - - rates, html = self._get_rates(carpark) - expected_result = {'Casual': {'days': '', - 'entry_start': '00:00', - 'exit_end': '23:59', - 'notes': ['Overnight Rate $30 Monday - Friday', - 'Motorbike Rate $5.00', - 'Public Holidays: Weekend Rates Apply'], - 'prices': {30: '10.00', - 60: '10.00', - 90: '24.00', - 120: '24.00', - 150: '36.00', - 180: '36.00', - 210: '42.00', - 240: '42.00', - 1440: '48.00'}, - 'rate_type': 'hourly'}, - 'Early Bird': {'days': [1, 2, 3, 4, 5], - 'entry_end': '10:00', - 'entry_start': '08:00', - 'exit_end': '19:00', - 'exit_start': '15:00', - 'notes': ['Proceed to Level B4 for parking and ' - 'validation of ticket'], - 'prices': '18.00', - 'rate_type': 'flat'}, - 'Night': {'rates': {0: {'days': [1, 2, 3, 4, 5], - 'entry_start': '17:00', - 'exit_end': '23:59', - 'prices': '9.00', - 'rate_type': 'flat'}}}, - 'Super Early Bird': {'days': [1, 2, 3, 4, 5], - 'entry_end': '08:00', - 'entry_start': '07:00', - 'exit_end': '19:00', - 'exit_start': '15:00', - 'notes': ['Proceed to Level B4 for parking ' - 'and validation of ticket'], - 'prices': '16.00', - 'rate_type': 'flat'}, - 'Weekend': {'days': [6, 7], - 'entry_start': '00:00', - 'exit_end': '23:59', - 'notes': ['Flat rate per exit, per day'], - 'prices': '9.00', - 'rate_type': 'flat' - }} - - self.assertDictEqual(expected_result, rates) - - self._update_rates(carpark, html) - - self._assert_saved_rates(carpark, expected_result) - - def _get_prices_information_park_id_5(self): - expected_result = {'Casual': {'days': '', - 'entry_start': '00:00', - 'exit_end': '23:59', - 'notes': ['Public Holidays: Casual Rates Apply', - 'Car Park Closed: Fri-25 Dec & Fri-01 Jan' - ], - 'prices': {30: "0.00", - 60: "0.00", - 90: "0.00", - 120: "0.00", - 150: "5.00", - 180: "8.00", - 210: "12.00", - 240: "16.00", - 1440: "18.00"}, - 'rate_type': 'hourly'}, - } - url = "https://www.wilsonparking.com.au/park/2260_East-Village-Car-Park_4-Defries-Avenue-Zetland" - carpark = Parking.objects.create(parkingID=5, label="East Village Car Park", - address="4 Defries Avenue, Zetland", - lat=-33.905890, long=151.210313, parking_type="Wilson", uri=url) - - rates, html = self._get_rates(carpark) - - self.assertDictEqual(expected_result, rates) - - self._update_rates(carpark, html) - - self._assert_saved_rates(carpark, expected_result) - - def _get_prices_information_park_id_6(self): - expected_result = {'Casual': {'days': '', - 'entry_start': '00:00', - 'exit_end': '23:59', - 'notes': ['Lost ticket $45.00.', - 'Public Holidays: Casual Rates Apply' - ], - 'prices': {30: "0.00", - 60: "0.00", - 90: "0.00", - 120: "0.00", - 150: "0.00", - 180: "0.00", - 210: "6.00", - 240: "9.00", - 270: "13.00", - 300: "16.00", - 330: "20.00", - 360: "25.00", - 390: "30.00", - 420: "40.00", - 1440: "45.00"}, - 'rate_type': 'hourly'}, - } - url = "https://www.wilsonparking.com.au/park/2219_Macquarie-Shopping-Centre-Car-Park_Cnr-Herring--Waterloo-Roads-North-Ryde-" - carpark = Parking.objects.create(parkingID=6, label="Macquarie Shopping Centre Car Park", - address="Cnr Herring & Waterloo Roads, North Ryde", - lat=-33.776880, long=151.118162, parking_type="Wilson", uri=url) - - rates, html = self._get_rates(carpark) - - self.assertDictEqual(expected_result, rates) - - self._update_rates(carpark, html) - - self._assert_saved_rates(carpark, expected_result) - - def _get_prices_information_park_id_7(self): - expected_result = {'Casual': {'days': '', - 'entry_start': '00:00', - 'exit_end': '23:59', - 'notes': ['Public Holidays: Weekend Rates Apply', - 'Student Rate: $20.00 per exit per day.\nMust validate ticket at UTS or Ultimo TAFE', - ], - 'prices': { - 30: "6.00", - 60: "15.00", - 90: "26.00", - 120: "26.00", - 150: "31.00", - 180: "31.00", - 210: "35.00", - 240: "35.00", - 1440: "40.00"}, - 'rate_type': 'hourly'}, - 'Night': {'notes': ['Special Events: $28.00'], - 'rates': {0: {'days': [1, 2, 3, 4, 5, 6, 7], - 'entry_start': '16:00', - 'exit_end': '04:00', - 'prices': '12.00', - 'rate_type': 'flat' - }, - }}, - 'Weekend': {'days': [6, 7], - 'notes': ['Per exit, per day'], - 'entry_start': '00:00', - 'exit_end': '23:59', - 'prices': {30: '7.00', - 60: '10.00', - 1440: '20.00'}, - 'rate_type': 'hourly'} - } - url = "https://www.wilsonparking.com.au/park/2108_169-179-Thomas-Street-Car-Park_169-179-Thomas-Street-Haymarket" - carpark = Parking.objects.create(parkingID=7, label="169-179 Thomas Street Car Park", - address="169-179 Thomas Street Car Park", - lat=-33.881828, long=151.2005398, parking_type="Wilson", uri=url) - - rates, html = self._get_rates(carpark) - - self.assertDictEqual(expected_result, rates) - - self._update_rates(carpark, html) - - self._assert_saved_rates(carpark, expected_result) - - def _get_prices_information_park_id_8(self): - expected_result = {'Casual': {'days': '', - 'entry_start': '00:00', - 'exit_end': '23:59', - 'notes': ['First 15 minutes free in open air car park (P9)', - 'Rates are based on a 24 hour period', - 'Each additional 24 hour period, or part thereof: $59.50 ' - 'per day'], - 'prices': { - 30: "8.00", - 60: "17.00", - 90: "25.00", - 120: "25.00", - 150: "33.00", - 180: "33.00", - 1440: "59.50", - 2880: "119.00", - 4320: "178.50"}, - 'rate_type': 'hourly'} - } - url = "https://www.wilsonparking.com.au/park/2099_Sydney-Airport-International-Car-Park_Sydney-International-Airport-Station-Mascot" - carpark = Parking.objects.create(parkingID=8, label="169-179 Thomas Street Car Park", - address="169-179 Thomas Street Car Park", - lat=-33.881828, long=151.2005398, parking_type="Wilson", uri=url) - - rates, html = self._get_rates(carpark) - - self.assertDictEqual(expected_result, rates) - - self._update_rates(carpark, html) - - self._assert_saved_rates(carpark, expected_result) - - def _get_prices_information_park_id_9(self): - url = "https://www.wilsonparking.com.au/park/4062_Eagle-Street-Pier-Car-Park_45-Eagle-Street-Brisbane" - - carpark = Parking.objects.create(parkingID=9, label="Carpark 9", - address="Whatever", - lat=-27.468988, long=153.028419, parking_type="Wilson", uri=url) - - rates, html = self._get_rates(carpark) - expected_result = {'Casual': {'days': '', - 'entry_start': '00:00', - 'exit_end': '23:59', - 'prices': {30: '10.00', - 60: '23.00', - 90: '46.00', - 120: '46.00', - 150: '69.00', - 180: '69.00', - 210: '74.00', - 240: '74.00', - 270: '79.00', - 300: '79.00', - 330: '84.00', - 360: '84.00', - 1440: '89.00'}, - 'rate_type': 'hourly'}, - 'Night': {'rates': {0: {'days': [1, 2, 3, 4, 5], - 'entry_start': '17:00', - 'exit_end': '06:00', - 'prices': '15.00', - 'rate_type': 'flat'}}}, - 'Weekend': {'days': [6, 7], - 'entry_start': '00:00', - 'exit_end': '23:59', - 'notes': ['RIVERFIRE 24/09/2016', - '$20.00', - 'Flat rate per exit, per day.'], - 'prices': '15.00', - 'rate_type': 'flat' - }} - - self.assertDictEqual(expected_result, rates) - - self._update_rates(carpark, html) - - self._assert_saved_rates(carpark, expected_result) - - def _get_prices_information_park_id_10(self): - url = "https://www.wilsonparking.com.au/park/3296_425-Collins-Street_425-Collins-Street" - - carpark = Parking.objects.create(parkingID=10, label="Carpark 10", - address="Whatever", - lat=-37.817492, long=144.958452, parking_type="Wilson", uri=url) - - rates, html = self._get_rates(carpark) - expected_result = {'Casual': {'days': '', - 'entry_start': '00:00', - 'exit_end': '23:59', - 'prices': {30: '20.00', - 60: '20.00', - 90: '42.00', - 120: '42.00', - 150: '62.00', - 180: '62.00', - 210: '65.00', - 240: '65.00', - 270: '70.00', - 300: '70.00' - }, - 'rate_type': 'hourly'}, - 'Early Bird': {'days': [1, 2, 3, 4, 5], - 'entry_end': '10:00', - 'entry_start': '06:00', - 'exit_end': '19:00', - 'exit_start': '10:00', - 'prices': '27.00', - 'rate_type': 'flat'} - } - - self.assertDictEqual(expected_result, rates) - - self._update_rates(carpark, html) - - self._assert_saved_rates(carpark, expected_result) \ No newline at end of file diff --git a/parker/settings/__init__.py b/parker/settings/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/parker/settings.default.py b/parker/settings/default.py similarity index 94% rename from parker/settings.default.py rename to parker/settings/default.py index af90843..c9b3ee8 100644 --- a/parker/settings.default.py +++ b/parker/settings/default.py @@ -139,14 +139,14 @@ HTML_FILE_SUFFIX_LENGTH = 5 # .html # Reloading uwsgi when script file is modified -try: - import uwsgi - from uwsgidecorators import timer - from django.utils import autoreload - - @timer(3) - def change_code_gracefull_reload(sig): - if autoreload.code_changed(): - uwsgi.reload() -except ImportError: - placeholder = '' +#try: +import uwsgi +from uwsgidecorators import timer +from django.utils import autoreload + +@timer(3) +def change_code_gracefull_reload(sig): + if autoreload.code_changed(): + uwsgi.reload() +# except ImportError: +# placeholder = '' diff --git a/parker/settings/test.py b/parker/settings/test.py new file mode 100644 index 0000000..19a5157 --- /dev/null +++ b/parker/settings/test.py @@ -0,0 +1,153 @@ +""" +Django settings for parker project. + +For more information on this file, see +https://docs.djangoproject.com/en/1.7/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/1.7/ref/settings/ +""" + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +import os + +BASE_DIR = "/carparker" + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/1.7/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '+56vp3(=hfhqu-l5c$jn!308lv*)#^5#q)i7i37l8_o!t$jxmf' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = False +TEMPLATE_DEBUG = False + +ALLOWED_HOSTS = ["ubuntu-linux.shared", "localhost"] + +# Application definition + +INSTALLED_APPS = ( + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + 'debug_toolbar', + 'parker', + 'rest_framework', + 'static_precompiler', + 'django_nose' +) + +# Use nose to run all tests +TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' + +# Tell nose to measure coverage on the 'foo' and 'bar' apps +NOSE_ARGS = [ + '--with-coverage', + '--cover-package=parker', +] + + +""" +MIDDLEWARE = ( + 'debug_toolbar.middleware.DebugToolbarMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', +) +""" + +# Speed up password encryption +PASSWORD_HASHERS = ( + 'django.contrib.auth.hashers.MD5PasswordHasher', +) + +INTERNAL_IPS = ( + '127.0.0.1', + '172.18.0.1', # Max macOS + '172.19.0.1', # Max Ubuntu +) + +ROOT_URLCONF = 'parker.urls' + +WSGI_APPLICATION = 'parker.wsgi.application' + +# Database +# https://docs.djangoproject.com/en/1.7/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'mysql', 'sqlite3' or 'oracle'. + } +} + +# Internationalization +# https://docs.djangoproject.com/en/1.7/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'Australia/Sydney' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/1.7/howto/static-files/ + +STATIC_ROOT = os.path.join(BASE_DIR, "static/") +STATIC_URL = '/extras/' + +STATICFILES_FINDERS = ( + 'django.contrib.staticfiles.finders.FileSystemFinder', + 'django.contrib.staticfiles.finders.AppDirectoriesFinder', + 'static_precompiler.finders.StaticPrecompilerFinder', +) + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, 'templates')], + 'APP_DIRS': True, + 'OPTIONS': { + 'debug': DEBUG, + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +REST_FRAMEWORK = { + # Use Django's standard `django.contrib.auth` permissions, + # or allow read-only access for unauthenticated users. + 'DEFAULT_PERMISSION_CLASSES': [ + 'rest_framework.permissions.DjangoModelPermissionsOrAnonReadOnly' + ] +} + +STATIC_PRECOMPILER_OUTPUT_DIR = "compiled" +STATIC_PRECOMPILER_COMPILERS = ( + ('static_precompiler.compilers.SCSS', { + "executable": "/usr/local/bin/sass", + "sourcemap_enabled": True, + "compass_enabled": True, + "load_paths": ["/path"] + }), +) + +HTML_CACHE_DIRECTORY = os.path.join(BASE_DIR, "scripts/carparks_rates_html") +HTML_FILE_PREFIX_LENGTH = 10 # carparkID_ +HTML_FILE_SUFFIX_LENGTH = 5 # .html diff --git a/parker/tests/__init__.py b/parker/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/parker/tests.py b/parker/tests/test_scripts.py similarity index 60% rename from parker/tests.py rename to parker/tests/test_scripts.py index 91ec2ec..011e808 100644 --- a/parker/tests.py +++ b/parker/tests/test_scripts.py @@ -1,6 +1,4 @@ -__author__ = 'mpak' import os -from decimal import * from django.test import TestCase from django.conf import settings @@ -92,51 +90,3 @@ def _get_rates(self, carpark: Parking): parser = RatesRetriever() rates = parser.get_rates(rates_html) return rates, rates_html - - def _update_rates(selfs, carpark, html): - mod = __import__("parker.classes.custom.wilson.rates_retriever", - fromlist=['RatesRetriever']) - - RatesRetriever = getattr(mod, 'RatesRetriever') - parser = RatesRetriever() - parser.update_rates(carpark, html) - - def _get_stored_prices(self, carpark, rate_label, rate_type, day_of_week=-1): - # rates are QuerySets - rates = RateType.objects.filter(parkingID=carpark, label=rate_label, rate_type=rate_type) - - if day_of_week > -1: - rates = rates.filter(day_of_week=day_of_week) - - prices = [] - for rate in rates: - prices.append(RatePrice.objects.filter(rateID=rate).order_by('duration')) - - return prices - - def _assert_saved_rates(self, carpark, expected_result): - # Check casual rates stored in DB - casual_prices = self._get_stored_prices(carpark, "Casual", "hourly", 0) - - for price in casual_prices[0]: - self.assertEquals(price.price, Decimal(expected_result['Casual']['prices'][price.duration])) - - # Check early bird rates stored in DB - early_bird_prices = self._get_stored_prices(carpark, "Early Bird", "flat") - for single_day_price in early_bird_prices: - self.assertEquals(single_day_price[0].price, Decimal(expected_result['Early Bird']['prices'])) - - # Check super early bird rates stored in DB - super_early_bird_prices = self._get_stored_prices(carpark, "Super Early Bird", "flat") - for single_day_price in super_early_bird_prices: - self.assertEquals(single_day_price[0].price, Decimal(expected_result['Super Early Bird']['prices'])) - - # Check super early bird rates stored in DB - # night_prices = self._get_stored_prices(carpark, "Night", "flat") - # for single_day_price in night_prices: - # self.assertEquals(single_day_price[0].price, Decimal(expected_result['Night']['rates']['prices'][0])) - - # Check weekend rates stored in DB - weekend_prices = self._get_stored_prices(carpark, "Weekend", "flat") - for single_day_price in weekend_prices: - self.assertEquals(single_day_price[0].price, Decimal(expected_result['Weekend']['prices']))