Commit 9383e9b0 authored by Michael R Lundquist's avatar Michael R Lundquist Committed by Zac Wood

58/mike/testing

parent 3671af83
......@@ -28,12 +28,10 @@ before_script:
- python manage.py makemigrations
- python manage.py makemigrations api
- python manage.py migrate
- echo "from django.contrib.auth import get_user_model; User =
get_user_model(); User.objects.create_superuser('root',
'root@srct.gmu.edu', 'root') " | python manage.py shell
- echo "from django.contrib.auth.models import User; User.objects.filter(username='$WOPEN_SUPERUSER$WOPEN_EMAIL_DOMAIN').delete(); User.objects.create_superuser('$WOPEN_SUPERUSER$WOPEN_EMAIL_DOMAIN', '$WOPEN_SUPERUSER', 'admin')" | python manage.py shell
- python3 manage.py loaddata --format json categoriesFixture locationFixture openTimeFixture scheduleFixture settingsFixture
whats-open-py3.7:
image: library/python:3.7
type: test
script:
- echo "Done 😄"
- python3 manage.py test --verbosity 2 --keepdb --noinput api.tests.APIClientTests
from rest_framework.test import APITestCase, APITransactionTestCase, APIClient
from django.contrib.auth.models import User # AnonymousUser,
from os import environ as env
# https://stackoverflow.com/questions/44450533/difference-between-testcase-and-transactiontestcase-classes-in-django-test
# ^APITestCase vs APITransactionTestCase
# https://www.django-rest-framework.org/api-guide/testing/
# ^DRF testing guide
# https://django-testing-docs.readthedocs.io/en/latest/fixtures.html
# ^testing with fixtures
# https://stackoverflow.com/questions/5875111/running-a-specific-test-case-in-django-when-your-app-has-a-tests-directory
# ^running the tests
client = APIClient()
user = User.objects.get(username=env["WOPEN_SUPERUSER"] + env["WOPEN_EMAIL_DOMAIN"])
client.force_authenticate(user=user)
class AlertsTests(APITestCase):
def test_read(self):
response = client.get('/api/alerts/')
assert response.status_code == 200
def test_ordering(self):
response = client.get('/api/alerts/?ordering=urgency_tag')
assert response.status_code == 200
def test_search(self):
response = client.get('/api/alerts/?search=srct&format=json')
assert response.status_code == 200
def test_filtering(self):
response = client.get('/api/alerts/?urgency_tag=major&format=json')
assert response.status_code == 200
class CategoriesTests(APITestCase):
def test_read(self):
response = client.get('/api/categories/')
assert response.status_code == 200
def test_ordering(self):
response = client.get('/api/categories/?ordering=name')
assert response.status_code == 200
def test_search(self):
response = client.get('/api/categories/?search=din&format=json')
assert response.status_code == 200
def test_filtering(self):
response = client.get('/api/categories/?name=dining&format=json')
assert response.status_code == 200
class facilitiesTests(APITestCase):
def test_read(self):
response = client.get('/api/facilities/')
assert response.status_code == 200
def test_ordering(self):
response = client.get('/api/facilities/?ordering=-facility_classifier')
assert response.status_code == 200
def test_search(self):
response = client.get('/api/facilities/?search=south&format=json')
assert response.status_code == 200
def test_filtering(self):
response = client.get('/api/facilities/?facility_name=Southside')
assert response.status_code == 200
class LocationsTests(APITestCase):
def test_read(self):
response = client.get('/api/locations/')
assert response.status_code == 200
def test_ordering(self):
response = client.get('/api/locations/?ordering=-address')
assert response.status_code == 200
def test_search(self):
response = client.get('/api/locations/?search=johnson&format=json')
assert response.status_code == 200
def test_filtering(self):
response = client.get('/api/locations/?building=Johnson+Center&format=json')
assert response.status_code == 200
class ScheduleTests(APITestCase):
def test_read(self):
response = client.get('/api/schedules/')
assert response.status_code == 200
def test_ordering(self):
response = client.get('/api/schedules/?ordering=name')
assert response.status_code == 200
"""Invalid value south?"""
def test_search(self):
response = client.get('/api/schedules/?search=Southside+[Fall+%2FSpring+Hours]')
#print(dir(response))
assert response.status_code == 200
def test_filtering(self):
response = client.get('/api/schedules/?name=&valid_start=&valid_end=&twenty_four_hours=true')
self.assertTrue(response.status_code == 200)
def test_post(self):
response = client.post('/api/schedules/', {
"name": "hi",
"valid_start": None,
"valid_end": None,
"twenty_four_hours": False
}, format='json')
assert response.status_code == 201
# class OpenTimeTests(APITestCase):
# def test_read(self):
# response = client.get('/api/categories/')
# assert response.status_code == 200
# def test_ordering(self):
# self.assertTrue(True)
# def test_search(self):
# self.assertTrue(True)
# def test_filtering(self):
# self.assertTrue(True)
# def test_post(self):
# client.post('/notes/', {'title': 'new idea'}, format='json')
# self.assertTrue(True)
\ No newline at end of file
......@@ -148,6 +148,12 @@ DATABASES = {
"PASSWORD": environ["WOPEN_DB_PASSWORD"],
"HOST": environ["WOPEN_DB_HOST"],
"PORT": environ["WOPEN_DB_PORT"],
'TEST': {
'NAME': environ["WOPEN_DB_NAME"],
'OPTIONS': {
"init_command": "SET storage_engine=MEMORY",
}
},
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment