Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from uclouvain/api
Api
- Loading branch information
Showing
21 changed files
with
178 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
default_app_config = "history.apps.HistoryConfig" | ||
default_app_config = "osis_history.apps.HistoryConfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from rest_framework.authentication import SessionAuthentication | ||
from rest_framework.generics import ListAPIView | ||
|
||
from .serializers import HistoryEntryListSerializer | ||
from osis_history.models import HistoryEntry | ||
|
||
__all__ = [ | ||
"HistoryEntryListAPIMixin", | ||
] | ||
|
||
|
||
class HistoryEntryListAPIMixin(ListAPIView): | ||
serializer_class = HistoryEntryListSerializer | ||
authentication_classes = [SessionAuthentication] | ||
|
||
def get_queryset(self): | ||
"""Filter the queryset with the object's uuid passed in url""" | ||
return HistoryEntry.objects.filter(object_uuid=self.kwargs["uuid"]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from rest_framework import serializers | ||
|
||
from osis_history.models import HistoryEntry | ||
|
||
__all__ = [ | ||
"HistoryEntryListSerializer", | ||
] | ||
|
||
|
||
class HistoryEntryListSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = HistoryEntry | ||
fields = [ | ||
"message", | ||
"created", | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
This app is for testing purpose only. | ||
|
||
With it, the base test suite from the history app can create `DummyModel` instances, that inherit from HistoryDeleteMixin. | ||
With it, the base test suite from the osis_history app can create `DummyModel` instances, that inherit from HistoryDeleteMixin. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
default_app_config = "history.tests.history_test.apps.HistoryTestConfig" | ||
default_app_config = "osis_history.tests.history_test.apps.HistoryTestConfig" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,4 @@ | |
|
||
|
||
class HistoryTestConfig(AppConfig): | ||
name = "history.tests.history_test" | ||
name = "osis_history.tests.history_test" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# ############################################################################## | ||
# | ||
# OSIS stands for Open Student Information System. It's an application | ||
# designed to manage the core business of higher education institutions, | ||
# such as universities, faculties, institutes and professional schools. | ||
# The core business involves the administration of students, teachers, | ||
# courses, programs and so on. | ||
# | ||
# Copyright (C) 2015-2021 Université catholique de Louvain (http://www.uclouvain.be) | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# A copy of this license - GNU General Public License - is available | ||
# at the root of the source code of this program. If not, | ||
# see http://www.gnu.org/licenses/. | ||
# | ||
# ############################################################################## | ||
from django.urls import path | ||
|
||
from .views import HistoryTestEntryListView | ||
|
||
urlpatterns = [ | ||
path("<uuid:uuid>/", HistoryTestEntryListView.as_view(), name="history-test"), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from osis_history.contrib.mixins import HistoryEntryListAPIMixin | ||
|
||
|
||
class HistoryTestEntryListView(HistoryEntryListAPIMixin): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# ############################################################################## | ||
# | ||
# OSIS stands for Open Student Information System. It's an application | ||
# designed to manage the core business of higher education institutions, | ||
# such as universities, faculties, institutes and professional schools. | ||
# The core business involves the administration of students, teachers, | ||
# courses, programs and so on. | ||
# | ||
# Copyright (C) 2015-2021 Université catholique de Louvain (http://www.uclouvain.be) | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation, either version 3 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# A copy of this license - GNU General Public License - is available | ||
# at the root of the source code of this program. If not, | ||
# see http://www.gnu.org/licenses/. | ||
# | ||
# ############################################################################## | ||
|
||
import uuid | ||
|
||
from django.test import TestCase, override_settings | ||
from django.urls import reverse | ||
from rest_framework.test import APIClient | ||
|
||
from base.tests.factories.user import UserFactory | ||
from osis_history.models import HistoryEntry | ||
from osis_history.tests.history_test.models import DummyModel | ||
|
||
|
||
@override_settings(ROOT_URLCONF='osis_history.tests.history_test.urls') | ||
class HistoryApiTestCase(TestCase): | ||
client_class = APIClient | ||
|
||
@classmethod | ||
def setUpTestData(cls): | ||
cls.user = UserFactory() | ||
cls.dumb_instance = DummyModel.objects.create(uuid=uuid.uuid4()) | ||
cls.dumb_instance_without_history_entries = DummyModel.objects.create( | ||
uuid=uuid.uuid4() | ||
) | ||
cls.history_entry_data = { | ||
"object_uuid": cls.dumb_instance.uuid, | ||
"message": "a test message", | ||
} | ||
# Create 3 history entries related to the same instance | ||
HistoryEntry.objects.create(**cls.history_entry_data) | ||
HistoryEntry.objects.create(**cls.history_entry_data) | ||
HistoryEntry.objects.create(**cls.history_entry_data) | ||
cls.list_url = reverse("history-test", args=[cls.dumb_instance.uuid]) | ||
|
||
def test_list_api_view_returns_related_history_entries(self): | ||
self.client.force_login(self.user) | ||
response = self.client.get(self.list_url) | ||
self.assertEqual(response.status_code, 200) | ||
# We must get back the 3 history entries created in the setup | ||
self.assertEqual(response.data["count"], 3) | ||
self.assertEqual( | ||
response.data["results"][0]["message"], self.history_entry_data["message"] | ||
) | ||
|
||
def test_list_api_view_returns_no_results_if_given_uuid_is_not_found(self): | ||
self.client.force_login(self.user) | ||
list_url = reverse( | ||
"history-test", | ||
args=[self.dumb_instance_without_history_entries.uuid], | ||
) | ||
response = self.client.get(list_url) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(response.data["count"], 0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters