forked from noahpresler/semesterly
-
Notifications
You must be signed in to change notification settings - Fork 55
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 #1040 from jhuopensource/feature/error-handling
Error fallback and report
- Loading branch information
Showing
17 changed files
with
263 additions
and
18 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
55 changes: 55 additions & 0 deletions
55
analytics/migrations/0022_uierrorlog_squashed_0024_alter_uierrorlog_options.py
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,55 @@ | ||
# Generated by Django 3.2.20 on 2023-10-07 01:34 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
replaces = [ | ||
("analytics", "0022_uierrorlog"), | ||
("analytics", "0023_alter_uierrorlog_user"), | ||
("analytics", "0024_alter_uierrorlog_options"), | ||
] | ||
|
||
dependencies = [ | ||
("analytics", "0021_auto_20230203_1230"), | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
("student", "0046_delete_registrationtoken"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="UIErrorLog", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("time_occurred", models.DateTimeField(auto_now_add=True)), | ||
("message", models.CharField(max_length=1000)), | ||
("name", models.CharField(max_length=100)), | ||
("stack", models.TextField()), | ||
("componentStack", models.TextField()), | ||
( | ||
"user", | ||
models.ForeignKey( | ||
blank=True, | ||
null=True, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to=settings.AUTH_USER_MODEL, | ||
), | ||
), | ||
], | ||
options={ | ||
"ordering": ["-time_occurred"], | ||
"abstract": False, | ||
}, | ||
), | ||
] |
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,21 @@ | ||
from rest_framework import serializers | ||
from .models import UIErrorLog | ||
|
||
|
||
class CurrentUserDefault(object): | ||
def set_context(self, serializer_field): | ||
self.user = serializer_field.context["request"].user | ||
|
||
def __call__(self): | ||
return self.user if self.user.is_authenticated else None | ||
|
||
def __repr__(self): | ||
return "%s()" % self.__class__.__name__ | ||
|
||
|
||
class UIErrorLogSerializer(serializers.ModelSerializer): | ||
user = serializers.HiddenField(default=CurrentUserDefault()) | ||
|
||
class Meta: | ||
model = UIErrorLog | ||
fields = "__all__" |
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 |
---|---|---|
|
@@ -10,7 +10,10 @@ | |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
|
||
from django.contrib.auth.models import User | ||
from rest_framework.test import APITestCase | ||
from helpers.test.test_cases import UrlTestCase | ||
from .models import UIErrorLog | ||
|
||
|
||
class UrlsTest(UrlTestCase): | ||
|
@@ -24,3 +27,43 @@ def test_urls_call_correct_views(self): | |
"/robots.txt", "analytics.views.view_analytics_dashboard" | ||
) | ||
self.assertUrlResolvesToView("/user/log_ical/", "student.views.log_ical_export") | ||
self.assertUrlResolvesToView( | ||
"/ui-error-logs/", "analytics.views.UIErrorLogCreateView" | ||
) | ||
|
||
|
||
class UIErrorLogCreateViewTest(APITestCase): | ||
def setUp(self): | ||
self.request_data = { | ||
"name": "test name", | ||
"message": "test message", | ||
"stack": "test stack", | ||
"componentStack": "test componentStack", | ||
} | ||
self.user = User.objects.create_user( | ||
username="user", email="[email protected]", password="password" | ||
) | ||
|
||
def test_add_new_log(self): | ||
response = self.client.post("/ui-error-logs/", self.request_data, format="json") | ||
self.assertEqual(response.status_code, 201) | ||
|
||
self.assertEqual(1, len(UIErrorLog.objects.all())) | ||
created = UIErrorLog.objects.all()[0] | ||
self.assert_attributes(created, None) | ||
|
||
def test_add_new_log_logged_in(self): | ||
self.client.force_login(self.user) | ||
response = self.client.post("/ui-error-logs/", self.request_data, format="json") | ||
self.assertEqual(response.status_code, 201) | ||
|
||
self.assertEqual(1, len(UIErrorLog.objects.all())) | ||
created = UIErrorLog.objects.all()[0] | ||
self.assert_attributes(created, self.user) | ||
|
||
def assert_attributes(self, created, user): | ||
self.assertEqual(created.name, self.request_data["name"]) | ||
self.assertEqual(created.message, self.request_data["message"]) | ||
self.assertEqual(created.stack, self.request_data["stack"]) | ||
self.assertEqual(created.componentStack, self.request_data["componentStack"]) | ||
self.assertEqual(created.user, user) |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,25 @@ | ||
.fallback-container { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
justify-content: center; | ||
height: 100%; | ||
|
||
h2, | ||
p { | ||
color: #000; | ||
} | ||
|
||
img { | ||
width: 100%; | ||
max-width: 350px; | ||
} | ||
} | ||
|
||
@media (max-width: 768px) { | ||
.fallback-container { | ||
img { | ||
max-width: 200px; | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Oops, something went wrong.