diff --git a/smash/web/api_urls.py b/smash/web/api_urls.py index b6eb174006ab53e076b1e057e6deee497419c46c..098a31aabd9b1032c24cd7a5d8b1ff0530df86b6 100644 --- a/smash/web/api_urls.py +++ b/smash/web/api_urls.py @@ -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'), diff --git a/smash/web/api_views/flying_team.py b/smash/web/api_views/flying_team.py new file mode 100644 index 0000000000000000000000000000000000000000..26b4a166618606fe24e0f57736345126cbbf98eb --- /dev/null +++ b/smash/web/api_views/flying_team.py @@ -0,0 +1,15 @@ +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 + }) diff --git a/smash/web/tests/api_views/test_flying_team.py b/smash/web/tests/api_views/test_flying_team.py new file mode 100644 index 0000000000000000000000000000000000000000..ca1895f2b74b795a382f4a5fc7c844675ecdc9eb --- /dev/null +++ b/smash/web/tests/api_views/test_flying_team.py @@ -0,0 +1,38 @@ +# 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)