Skip to content

Commit

Permalink
Merge pull request #34 from observatorycontrolsystem/feature/support_…
Browse files Browse the repository at this point in the history
…deletion

Add id to serialized output, and exact reason to filters, to support …
  • Loading branch information
jnation3406 authored Jul 26, 2024
2 parents 7ca1cc4 + b6df5f4 commit 88a89ca
Show file tree
Hide file tree
Showing 13 changed files with 547 additions and 428 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
python-version: ["3.8", "3.9", "3.10"]
steps:
- name: Check out repository
uses: actions/checkout@v2
Expand All @@ -32,11 +32,21 @@ jobs:
poetry install
poetry run python manage.py collectstatic
- name: Run tests
run: poetry run coverage run manage.py test --settings=test_settings
run: |
poetry run coverage run manage.py test --settings=test_settings
poetry run coverage xml
- name: Coveralls report
run: poetry run coveralls --service=github
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
uses: coverallsapp/github-action@v2
with:
parallel: true
finish:
runs-on: ubuntu-latest
needs: run_tests
steps:
- name: Close parallel build
uses: coverallsapp/github-action@v2
with:
parallel-finished: true

build_and_publish_image:
# Only run this job if the run_tests job has succeeded, and if
Expand Down
2 changes: 1 addition & 1 deletion .python-version
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
3.7.13
3.8.13
3.9.13
3.10.13
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ for things such as maintenance activites or education use on specific telescopes

## Prerequisites

- Python>=3.7
- Python>=3.8
- (Optional) PostgreSQL
- Configuration database to connect to
- (Optional) Observation Portal for Oauth2 authentication
Expand Down
2 changes: 1 addition & 1 deletion downtime/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
'ocs_authentication.backends.OCSTokenAuthentication', # Allows authentication against Oauth Servers api_token
'rest_framework.authentication.SessionAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': ('ocs_authentication.permissions.IsAdminOrReadOnly',),
'DEFAULT_PERMISSION_CLASSES': ('rest_framework.permissions.IsAuthenticatedOrReadOnly',),
'DEFAULT_FILTER_BACKENDS': ('django_filters.rest_framework.DjangoFilterBackend',),
'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.NamespaceVersioning',
'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
Expand Down
11 changes: 5 additions & 6 deletions downtime/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
1. Import the include() function: from django.conf.urls import url, include
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.urls import path
from django.urls import path, re_path, include
from django.contrib import admin
from django.views.generic.base import TemplateView
from rest_framework.routers import DefaultRouter
Expand All @@ -37,10 +36,10 @@
)

urlpatterns = [
url(r'^$', DowntimeListView.as_view(), name='web-downtime-list'),
url(r'^api/', include(router.urls)),
url(r'^admin/', admin.site.urls),
url(r'^authprofile/', include(authprofile_urls)),
re_path(r'^$', DowntimeListView.as_view(), name='web-downtime-list'),
re_path(r'^api/', include(router.urls)),
re_path(r'^admin/', admin.site.urls),
re_path(r'^authprofile/', include(authprofile_urls)),
path('openapi/', schema_view, name='openapi-schema'),
path('redoc/', TemplateView.as_view(
template_name='redoc.html',
Expand Down
892 changes: 496 additions & 396 deletions poetry.lock

Large diffs are not rendered by default.

23 changes: 12 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
[tool.poetry]
name = "downtime"
version = "2.4.1"
version = "2.4.3"
description = "Downtime API"
authors = ["OCS Authors"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.7"
django = ">=3.0,<3.3"
django-extensions = ">=3.1,<4.0"
django-filter = ">=2.2,<2.5"
django-bootstrap4 = ">21.1,<23.1"
django-cors-headers = ">=3.5,<3.8"
djangorestframework = ">=3.12.2,<3.13"
ocs-authentication = "0.1.0"
python = "^3.8"
django = "^4"
django-extensions = "^3.2"
django-filter = "^24"
django-bootstrap4 = "^24"
django-cors-headers = "^4.4"
djangorestframework = "^3.15"
ocs-authentication = "^0.2"
requests = ">=2,<3"
whitenoise = ">=5.2,<6.0"
psycopg2-binary = ">=2.8,<2.9"
psycopg2-binary = ">=2.8,<2.10"
gunicorn = "20.0.4"
pyyaml = "5.4.1"
pyyaml = ">=6.0"
uritemplate = "3.0.1"
setuptools-scm = "6.0.1"
packaging = "^24.1"


[tool.poetry.group.dev.dependencies]
Expand Down
2 changes: 1 addition & 1 deletion schedule/configdb.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import requests
from django.core.cache import caches
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _
from django.conf import settings


Expand Down
1 change: 1 addition & 0 deletions schedule/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class DowntimeFilter(django_filters.FilterSet):
telescope = django_filters.MultipleChoiceFilter(field_name='telescope', choices=sorted(configdb.get_telescope_tuples()), label='Telescope code')
instrument_type = django_filters.MultipleChoiceFilter(field_name='instrument_type', choices=sorted(configdb.get_instrument_type_tuples()), label='Instrument type')
reason = django_filters.CharFilter(field_name='reason', lookup_expr='icontains', label='Reason contains')
reason_exact = django_filters.CharFilter(field_name='reason', lookup_expr='exact', label='Reason exact')
created_after = django_filters.DateTimeFilter(field_name='created', lookup_expr='gte', label='Created After')
created_before = django_filters.DateTimeFilter(field_name='created', lookup_expr='lte', label='Created Before')
modified_after = django_filters.DateTimeFilter(field_name='modified', lookup_expr='gte', label='Modified After')
Expand Down
2 changes: 1 addition & 1 deletion schedule/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from django.db import models
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from schedule.configdb import configdb

Expand Down
4 changes: 2 additions & 2 deletions schedule/serializers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from rest_framework import serializers
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

from schedule.models import Downtime
from schedule.configdb import configdb
Expand All @@ -19,7 +19,7 @@ class DowntimeSerializer(serializers.ModelSerializer):

class Meta:
model = Downtime
fields = ('start', 'end', 'site', 'enclosure', 'telescope', 'instrument_type', 'reason')
fields = ('id', 'start', 'end', 'site', 'enclosure', 'telescope', 'instrument_type', 'reason')

def validate(self, data):
if data['end'] <= data['start']:
Expand Down
13 changes: 10 additions & 3 deletions schedule/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,20 @@ def test_post_downtime_fails_if_not_logged_in(self):
self.client.post(reverse('downtime-list'), downtime)
self.assertEqual(Downtime.objects.count(), 0)

def test_post_downtime_fails_if_not_admin_user(self):
self.client.force_login(self.normal_user)
def test_post_downtime_fails_if_not_authenticated_user(self):
self.client.logout()
downtime = copy.deepcopy(self.base_downtime)
self.assertEqual(Downtime.objects.count(), 0)
response = self.client.post(reverse('downtime-list'), downtime)
self.assertEqual(response.status_code, 403) # check that the request was forbidden
self.assertEqual(response.status_code, 401) # check that the request was unauthorized
self.assertEqual(Downtime.objects.count(), 0)
# Now test for an authenticated normal user
self.client.force_login(self.normal_user)
downtime = copy.deepcopy(self.base_downtime)
self.assertEqual(Downtime.objects.count(), 0)
response = self.client.post(reverse('downtime-list'), downtime)
self.assertEqual(response.status_code, 201) # check that the request worked
self.assertEqual(Downtime.objects.count(), 1)

def test_post_downtime_fails_invalid_site(self):
downtime = copy.deepcopy(self.base_downtime)
Expand Down
1 change: 1 addition & 0 deletions schedule/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class DowntimeViewSet(viewsets.ModelViewSet):
queryset = Downtime.objects.all()
http_method_names = ['get', 'post', 'delete', 'head', 'options']
serializer_class = DowntimeSerializer
filter_class = DowntimeFilter
filter_backends = (
Expand Down

0 comments on commit 88a89ca

Please sign in to comment.