Skip to content

Commit

Permalink
Refactored tests to use sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
zucler committed Nov 26, 2016
1 parent da39f27 commit b887f00
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 587 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,5 @@ __history/

#settings file
parker/settings.py
parker/tmp.txt
static/admin
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion container-app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions container-app/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ mysqlclient
selenium
sqlparse
uWSGI
coverage
django-nose
523 changes: 0 additions & 523 deletions parker/old_tests.py

This file was deleted.

Empty file added parker/settings/__init__.py
Empty file.
22 changes: 11 additions & 11 deletions parker/settings.default.py → parker/settings/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = ''
153 changes: 153 additions & 0 deletions parker/settings/test.py
Original file line number Diff line number Diff line change
@@ -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
Empty file added parker/tests/__init__.py
Empty file.
50 changes: 0 additions & 50 deletions parker/tests.py → parker/tests/test_scripts.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
__author__ = 'mpak'
import os
from decimal import *

from django.test import TestCase
from django.conf import settings
Expand Down Expand Up @@ -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']))

0 comments on commit b887f00

Please sign in to comment.