Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,5 @@ ENV/

**/.DS_Store
backend-exemplar-2018.code-workspace

.pytest_cache/
10 changes: 7 additions & 3 deletions DOCKERFILE.api.development
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
FROM python:3.6.5-stretch
MAINTAINER Brian H. Grant <brian@hackoregon.org> & "M. Edward (Ed) Borasky <znmeb@znmeb.net>
MAINTAINER Brian H. Grant <brian@hackoregon.org> & "M. Edward (Ed) Borasky <znmeb@znmeb.net>"
ENV PYTHONUNBUFFERED 1

# add required Debian packages
# https://docs.djangoproject.com/en/2.0/ref/contrib/gis/install/geolibs/
RUN apt-get update \
&& apt-get install -qqy --no-install-recommends \
&& apt-get install -qy --no-install-recommends \
apt-utils \
&& apt-get install -qy --no-install-recommends \
binutils \
gdal-bin \
libproj-dev \
Expand All @@ -17,8 +19,10 @@ RUN mkdir /code
WORKDIR /code

COPY /requirements/* /code/
RUN pip install -r development.txt

# upgrade pip to latest
RUN pip install --upgrade pip
RUN pip install -r development.txt
RUN pip install -r geodjango.txt

RUN python
Expand Down
10 changes: 7 additions & 3 deletions DOCKERFILE.api.production
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
FROM python:3.6.5-stretch
MAINTAINER Brian H. Grant <brian@hackoregon.org> & "M. Edward (Ed) Borasky <znmeb@znmeb.net>
MAINTAINER Brian H. Grant <brian@hackoregon.org> & "M. Edward (Ed) Borasky <znmeb@znmeb.net>"
ENV PYTHONUNBUFFERED 1

# add required Debian packages
# https://docs.djangoproject.com/en/2.0/ref/contrib/gis/install/geolibs/
RUN apt-get update \
&& apt-get install -qqy --no-install-recommends \
&& apt-get install -qy --no-install-recommends \
apt-utils \
&& apt-get install -qy --no-install-recommends \
binutils \
gdal-bin \
libproj-dev \
Expand All @@ -16,8 +18,10 @@ RUN mkdir /code
WORKDIR /code

COPY /requirements/* /code/
RUN pip install -r production.txt

# upgrade pip
RUN pip install --upgrade pip
RUN pip install -r production.txt
RUN pip install -r geodjango.txt

RUN python
Expand Down
7 changes: 4 additions & 3 deletions DOCKERFILE.db.development
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ LABEL maintainer="M. Edward (Ed) Borasky <znmeb@znmeb.net>"

# Install apt packages
RUN apt-get update \
&& apt-get install -qqy --no-install-recommends \
&& apt-get install -qy --no-install-recommends \
apt-utils \
&& apt-get install -qy --no-install-recommends \
postgis \
postgresql-9.6-postgis-2.4 \
postgresql-9.6-postgis-2.4-scripts \
postgresql-9.6-postgis-scripts \
postgresql-9.6-pgrouting \
postgresql-9.6-pgrouting \
&& apt-get clean

# set up automatic restores
Expand Down
12 changes: 0 additions & 12 deletions api/tests.py

This file was deleted.

Empty file added api/tests/__init__.py
Empty file.
90 changes: 90 additions & 0 deletions api/tests/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
from django.test import TestCase, SimpleTestCase, TransactionTestCase
from rest_framework.test import APIClient
from rest_framework import status

# Django, Writing and Running Unit Tests: https://docs.djangoproject.com/en/2.0/topics/testing/overview/
# Django, Automated Unit Testing Tutorial: https://docs.djangoproject.com/en/2.0/intro/tutorial05/

# class RootEndpointTestCase(TestCase):
# def setUp(self):
# self.client = APIClient()
# def test_list_response(self):
# response = self.client.get('/')
# assert response.status_code == status.HTTP_200_OK

class APIRootEndpointTestCase(TestCase):
def setUp(self):
self.client = APIClient()
def test_response(self):
response = self.client.get('/api/')
assert response.status_code == status.HTTP_200_OK

class SchemaRootEndpointTestCase(TestCase):
def setUp(self):
self.client = APIClient()
def test_response(self):
response = self.client.get('/schema/')
assert response.status_code == status.HTTP_200_OK

class DocsEndpointTestCase(TestCase):
def setUp(self):
self.client = APIClient()
def test_response(self):
response = self.client.get('/docs/')
assert response.status_code == status.HTTP_200_OK

# class SandboxAPIEndpointsTestCase(TestCase):
# def setUp(self):
# self.client = APIClient()
# self.datasets = ['foundations/censusresponse','foundations/landslide/','foundations/liquefaction','foundations/shaking','slides/poi/']
# def test_list_responses(self):
# for endpoint in self.datasets:
# response = self.client.get('/disaster-resilience/sandbox/'+endpoint+'/')
# assert response.status_code == status.HTTP_200_OK
# def test_detail_responses(self):
# for endpoint in self.datasets:
# response = self.client.get('/disaster-resilience/sandbox/'+endpoint+"/1/")
# assert response.status_code == status.HTTP_200_OK

class APIEndpointsTestCase(TestCase):
def setUp(self):
self.client = APIClient()
self.datasets = ['songs',]
def test_list_responses(self):
for endpoint in self.datasets:
response = self.client.get('/api/'+endpoint+'/')
assert response.status_code == status.HTTP_200_OK
def test_detail_responses(self):
for endpoint in self.datasets:
response = self.client.get('/api/'+endpoint+'/1/')
assert response.status_code == status.HTTP_200_OK

# class QuakeLossViewEndpointTestCase(TestCase):
# def setUp(self):
# self.client = APIClient()
# def test_list_response(self):
# response = self.client.get('/disaster-resilience/api/QuakeLossView/')
# assert response.status_code == status.HTTP_200_OK
# def test_detail_response(self):
# response = self.client.get('/disaster-resilience/api/QuakeLossView/2525/')
# assert response.status_code == status.HTTP_200_OK

# class DisasterNeighborhoodGridEndpointTestCase(TestCase):
# def setUp(self):
# self.client = APIClient()
# def test_CENTRL_office_response(self):
# response = self.client.get('/disaster-resilience/api/DisasterNeighborhoodGrid/?lat=45.523628&long=-122.656646')
# assert response.status_code == status.HTTP_200_OK
# def test_rounding_response(self):
# response = self.client.get('/disaster-resilience/api/DisasterNeighborhoodGrid/?lat=45.592&long=-122.835')
# assert response.status_code == status.HTTP_200_OK

# class POIEndpointTestCase(TestCase):
# def setUp(self):
# self.client = APIClient()
# def test_list_response(self):
# response = self.client.get('/disaster-resilience/api/POI/')
# assert response.status_code == status.HTTP_200_OK
# def test_detail_response(self):
# response = self.client.get('/disaster-resilience/api/POI/BEECN1/')
# assert response.status_code == status.HTTP_200_OK
6 changes: 4 additions & 2 deletions bin/test-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ export PATH=$PATH:~/.local/bin
set -e

# Collect static files
echo "Collect static files"
python -Wall manage.py collectstatic --noinput

python -Wall manage.py test --nomigrations --noinput --keepdb #--parallel
# apply any migrations
python -Wall manage.py migrate --noinput

pytest -n 4
7 changes: 6 additions & 1 deletion dead_songs/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@
from django.contrib import admin
from django.conf.urls import url, include
from django.urls import path
from rest_framework.documentation import include_docs_urls

swagger_docs_title = 'Backend Exemplar API'

urlpatterns = [
path('admin/', admin.site.urls),
# disable admin interface
#path('admin/', admin.site.urls),
path('docs/', include_docs_urls(title=swagger_docs_title)),
url(r'^', include('api.urls')),
]
4 changes: 4 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[pytest]
DJANGO_SETTINGS_MODULE = dead_songs.settings
python_files = tests.py test_*.py *_tests.py
addopts = --reuse-db
4 changes: 2 additions & 2 deletions requirements/common.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ django-rest-swagger

# Testing
coverage==4.4.2
django-nose==1.4.5
nose==1.3.7
pytest-django
pytest-xdist
django-test-without-migrations==0.6
# tblib required for viewing tracebacks from the unit test runner
tblib==1.3.2