Skip to content
Snippets Groups Projects
Commit 08cc68ec authored by Piotr Gawron's avatar Piotr Gawron
Browse files

api for obtaining flying teams

parent da855430
No related branches found
No related tags found
1 merge request!106Resolve "Subjects without visit list"
......@@ -16,7 +16,7 @@ Including another URLconf
from django.conf.urls import url
from web.api_views import worker, location, subject, appointment_type, appointment, configuration, daily_planning, \
redcap
redcap, flying_team
urlpatterns = [
# appointments
......@@ -41,6 +41,9 @@ urlpatterns = [
# locations
url(r'^locations$', location.locations, name='web.api.locations'),
# flying_teams
url(r'^flying_teams$', flying_team.flying_teams, name='web.api.flying_teams'),
# worker data
url(r'^specializations$', worker.specializations, name='web.api.specializations'),
url(r'^units$', worker.units, name='web.api.units'),
......
from django.contrib.auth.decorators import login_required
from django.http import JsonResponse
from web.models import FlyingTeam
@login_required
def flying_teams(request):
all_flying_teams = FlyingTeam.objects.all()
data = []
for flying_team in all_flying_teams:
data.append({"id": flying_team.id, "name": flying_team.place})
return JsonResponse({
"flying_teams": data
})
# coding=utf-8
import json
from django.contrib.auth.models import User
from django.test import Client
from django.test import TestCase
from django.urls import reverse
from web.tests.functions import create_worker, create_flying_team
class TestFlyingTeamApi(TestCase):
def setUp(self):
self.client = Client()
username = 'piotr'
password = 'top_secret'
self.user = User.objects.create_user(
username=username, email='jacob@bla', password=password)
self.worker = create_worker(self.user)
self.client.login(username=username, password=password)
def test_flying_teams(self):
flying_team_name = "some flying_team"
response = self.client.get(reverse('web.api.flying_teams'))
self.assertEqual(response.status_code, 200)
create_flying_team(flying_team_name)
response = self.client.get(reverse('web.api.flying_teams'))
flying_teams = json.loads(response.content)['flying_teams']
found = False
for flying_team in flying_teams:
if flying_team['name'] == flying_team_name:
found = True
self.assertTrue(found)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment