-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Save extra summary information submitted by shifters [Closes #209]
- Loading branch information
Showing
15 changed files
with
397 additions
and
88 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
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,14 +1,30 @@ | ||
from .settings import * | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': 'database', | ||
if os.environ.get("GITHUB_WORKFLOW"): | ||
DATABASES = { | ||
"default": { | ||
"ENGINE": "django.db.backends.postgresql", | ||
"NAME": "github_actions", | ||
"USER": "postgres", | ||
"PASSWORD": "postgres", | ||
"HOST": "127.0.0.1", | ||
"PORT": "5432", | ||
} | ||
} | ||
else: | ||
DATABASES = { | ||
"default": { | ||
"ENGINE": "django.db.backends.postgresql", | ||
"NAME": "postgres-local", | ||
"USER": "postgres", | ||
"PASSWORD": "postgres", | ||
"PORT": "5432" | ||
# 'HOST': 'localhost' | ||
} | ||
} | ||
} | ||
|
||
DYNAMIC_PREFERENCES = { | ||
'ENABLE_CACHE': False, | ||
"ENABLE_CACHE": False, | ||
} | ||
|
||
EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend' | ||
EMAIL_BACKEND = "django.core.mail.backends.locmem.EmailBackend" |
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,5 @@ | ||
from django.contrib import admin | ||
from summary.models import SummaryInfo | ||
|
||
# Register your models here. | ||
admin.site.register(SummaryInfo) |
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,8 @@ | ||
from django import forms | ||
from summary.models import SummaryInfo | ||
|
||
|
||
class SummaryExtraInfoForm(forms.ModelForm): | ||
class Meta: | ||
model = SummaryInfo | ||
fields = ["links_prompt_feedback", "special_comment"] |
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,24 @@ | ||
# Generated by Django 4.0.6 on 2022-08-26 13:09 | ||
|
||
import django.contrib.postgres.fields | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='SummaryInfo', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('runs', django.contrib.postgres.fields.ArrayField(base_field=models.IntegerField(), help_text='Unique summary for list of runs', size=None, unique=True)), | ||
('links_prompt_feedback', models.TextField(help_text='tinyurl links to plots on cmsweb.cern.ch')), | ||
('special_comment', models.TextField(blank=True, help_text='Special comment by shifter for this summary')), | ||
], | ||
), | ||
] |
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,31 @@ | ||
from django.db import models | ||
from django.contrib.postgres.fields import ArrayField | ||
from summary.validators import validate_list_length | ||
|
||
# Create your models here. | ||
|
||
class SummaryInfo(models.Model): | ||
""" | ||
Information regarding a summary/Elog. | ||
A summary is identified by the list of runs it is composed of | ||
""" | ||
|
||
runs = ArrayField( | ||
base_field=models.IntegerField(null=False), | ||
help_text="Unique summary for list of runs", | ||
unique=True, | ||
) | ||
links_prompt_feedback = models.TextField( | ||
help_text="tinyurl links to plots on cmsweb.cern.ch" | ||
) | ||
special_comment = models.TextField( | ||
help_text="Special comment by shifter for this summary", blank=True | ||
) | ||
|
||
def save(self, *args, **kwargs): | ||
# ArrayField does not seem to use a validators argument | ||
validate_list_length(self.runs) | ||
super().save(*args, **kwargs) | ||
|
||
def __str__(self): | ||
return f"{self.__class__.__name__} {self.runs}" |
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,21 +1,95 @@ | ||
import pytest | ||
import json | ||
from django.test import RequestFactory | ||
from mixer.backend.django import mixer | ||
|
||
from django.urls import reverse | ||
from django.contrib.auth.models import AnonymousUser | ||
from django.contrib.auth import get_user_model | ||
from summary.views import * | ||
from users.models import User | ||
from summary.views import SummaryView | ||
from summary.forms import SummaryExtraInfoForm | ||
from oms.models import OmsRun | ||
from certifier.models import TrackerCertification | ||
|
||
pytestmark = pytest.mark.django_db | ||
|
||
|
||
def test_view_requires_login(): | ||
req = RequestFactory().get("summary/") | ||
def test_view_requires_shifter_rights(): | ||
# | ||
req = RequestFactory().get(reverse("summary:summary")) | ||
req.user = AnonymousUser() | ||
resp = summaryView(req) | ||
resp = SummaryView.as_view()(req) | ||
assert resp.status_code == 302 | ||
|
||
req.user = mixer.blend(get_user_model()) | ||
resp = summaryView(req) | ||
req.user = mixer.blend(User, user_privilege=User.SHIFTER) | ||
|
||
resp = SummaryView.as_view()(req) | ||
assert resp.status_code == 200 | ||
|
||
|
||
def test_get_success(): | ||
|
||
user = mixer.blend(User, user_privilege=User.SHIFTER) | ||
certs = [ | ||
mixer.blend( | ||
TrackerCertification, runreconstruction__run__run_number=355555, user=user | ||
), | ||
mixer.blend( | ||
TrackerCertification, runreconstruction__run__run_number=299929, user=user | ||
), | ||
] | ||
runs_list = [cert.runreconstruction.run.run_number for cert in certs] | ||
|
||
req = RequestFactory().get(reverse("summary:summary")) | ||
|
||
req.user = user | ||
|
||
resp = SummaryView.as_view()(req) | ||
assert resp.status_code == 200 | ||
assert ( | ||
TrackerCertification.objects.filter( | ||
runreconstruction__run__run_number__in=[355555, 299929] | ||
).count() | ||
== 2 | ||
) | ||
|
||
|
||
def test_post_success(): | ||
runs = [ | ||
mixer.blend(OmsRun, run_number=355555), | ||
mixer.blend(OmsRun, run_number=299929), | ||
] | ||
|
||
runs_list = [run.run_number for run in runs] | ||
form = SummaryExtraInfoForm( | ||
data={"runs_list": str(runs_list), "links_prompt_feedback": "link1, link2"} | ||
) | ||
assert form.is_valid() | ||
|
||
req = RequestFactory().post(reverse("summary:summary"), data=form.data) | ||
|
||
req.user = mixer.blend(User, user_privilege=User.SHIFTER) | ||
|
||
resp = SummaryView.as_view()(req) | ||
assert resp.status_code == 200 | ||
result = json.loads(resp.content) | ||
assert result["success"] == True | ||
|
||
|
||
def test_post_failure(): | ||
|
||
form = SummaryExtraInfoForm( | ||
data={ | ||
"runs_list": str([]), | ||
} | ||
) | ||
assert form.is_valid() == False | ||
|
||
req = RequestFactory().post(reverse("summary:summary"), data=form.data) | ||
|
||
req.user = mixer.blend(User, user_privilege=User.SHIFTER) | ||
|
||
resp = SummaryView.as_view()(req) | ||
assert resp.status_code == 200 | ||
result = json.loads(resp.content) | ||
assert result["success"] == False |
Oops, something went wrong.