New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bug-1809726: update to django 4.2 #6538
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -110,7 +110,7 @@ def test_base_classes_raise_not_found(self): | |
def test_option_CORS(self): | ||
"""OPTIONS request for model_wrapper returns CORS headers""" | ||
url = reverse("api:model_wrapper", args=("NoOp",)) | ||
response = self.client.options(url, HTTP_ORIGIN="http://example.com") | ||
response = self.client.options(url, headers={"origin": "http://example.com"}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The Django test client takes a |
||
assert response.status_code == 200 | ||
assert response["Access-Control-Allow-Origin"] == "*" | ||
|
||
|
@@ -158,14 +158,14 @@ def test_hit_or_not_hit_ratelimit(self): | |
# https://bugzilla.mozilla.org/show_bug.cgi?id=1148470 | ||
for _ in range(current_limit * 2): | ||
response = self.client.get( | ||
url, {"product": "good"}, HTTP_X_REAL_IP="12.12.12.12" | ||
url, {"product": "good"}, headers={"x-real-ip": "12.12.12.12"} | ||
) | ||
assert response.status_code == 429 | ||
|
||
# But it'll work if you use a different X-Real-IP | ||
# because the rate limit is based on your IP address | ||
response = self.client.get( | ||
url, {"product": "good"}, HTTP_X_REAL_IP="11.11.11.11" | ||
url, {"product": "good"}, headers={"x-real-ip": "11.11.11.11"} | ||
) | ||
assert response.status_code == 200 | ||
|
||
|
@@ -175,7 +175,7 @@ def test_hit_or_not_hit_ratelimit(self): | |
) | ||
|
||
response = self.client.get( | ||
url, {"product": "good"}, HTTP_AUTH_TOKEN=token.key | ||
url, {"product": "good"}, headers={"auth-token": token.key} | ||
) | ||
assert response.status_code == 200 | ||
|
||
|
@@ -255,7 +255,9 @@ def mocked_get(**params): | |
token = Token.objects.create(user=user, notes="test token") | ||
token.permissions.add(view_pii_perm) | ||
|
||
response = self.client.get(url, {"crash_id": "123"}, HTTP_AUTH_TOKEN=token.key) | ||
response = self.client.get( | ||
url, {"crash_id": "123"}, headers={"auth-token": token.key} | ||
) | ||
assert response.status_code == 200 | ||
dump = json.loads(response.content) | ||
for key in public_data.keys(): | ||
|
@@ -326,7 +328,7 @@ def mocked_get(**params): | |
token.permissions.add(view_pii_perm) | ||
|
||
response = self.client.get( | ||
url, {"crash_id": "abc123"}, HTTP_AUTH_TOKEN=token.key | ||
url, {"crash_id": "abc123"}, headers={"auth-token": token.key} | ||
) | ||
assert response.status_code == 200 | ||
dump = json.loads(response.content) | ||
|
@@ -548,7 +550,7 @@ def mocked_publish(queue, crash_ids): | |
assert response.status_code == 403 | ||
|
||
params = {"crash_ids": crash_id} | ||
response = self.client.get(url, params, HTTP_AUTH_TOKEN="somecrap") | ||
response = self.client.get(url, params, headers={"auth-token": "somecrap"}) | ||
assert response.status_code == 403 | ||
|
||
user = User.objects.create(username="test") | ||
|
@@ -560,10 +562,10 @@ def mocked_publish(queue, crash_ids): | |
token = Token.objects.create(user=user, notes="Only reprocessing") | ||
token.permissions.add(perm) | ||
|
||
response = self.client.get(url, params, HTTP_AUTH_TOKEN=token.key) | ||
response = self.client.get(url, params, headers={"auth-token": token.key}) | ||
assert response.status_code == 405 | ||
|
||
response = self.client.post(url, params, HTTP_AUTH_TOKEN=token.key) | ||
response = self.client.post(url, params, headers={"auth-token": token.key}) | ||
assert response.status_code == 200 | ||
assert json.loads(response.content) is True | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,12 +38,12 @@ class UserAdminBetter(UserAdmin): | |
"get_policyexception", | ||
] | ||
|
||
@admin.display(description="Hacker (PII)") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of setting properties on the methods, there's a decorator that you can use to set things. We switched to that. https://docs.djangoproject.com/en/5.0/ref/contrib/admin/#django.contrib.admin.display |
||
def is_hacker(self, obj): | ||
"""Return whether user is in the Hackers group and has access to PII.""" | ||
return obj.groups.filter(name="Hackers").exists() | ||
|
||
is_hacker.short_description = "Hacker (PII)" | ||
|
||
@admin.display(description="PolicyException") | ||
def get_policyexception(self, obj): | ||
"""Return whether user has a PolicyException with links to change/delete or add one.""" | ||
if hasattr(obj, "policyexception"): | ||
|
@@ -57,8 +57,6 @@ def get_policyexception(self, obj): | |
) | ||
return format_html('<a href="{}">Create</a>', url) | ||
|
||
get_policyexception.short_description = "PolicyException" | ||
|
||
|
||
@admin.register(PolicyException) | ||
class PolicyExceptionAdmin(admin.ModelAdmin): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,14 +30,14 @@ class LogEntryAdmin(admin.ModelAdmin): | |
|
||
list_display = [ | ||
"action_time", | ||
"admin", | ||
"admin_email", | ||
"object_link", | ||
"action", | ||
"get_change_message", | ||
] | ||
list_display_links = ["action_time", "get_change_message"] | ||
|
||
def admin(self, obj): | ||
def admin_email(self, obj): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We needed to change this method name because it overrides |
||
return obj.user.email | ||
|
||
def action(self, obj): | ||
|
@@ -51,6 +51,10 @@ def obj_repr(self, obj): | |
return edited_obj.email | ||
return edited_obj | ||
|
||
@admin.display( | ||
description="object", | ||
ordering="object_repr", | ||
) | ||
def object_link(self, obj): | ||
object_link = self.obj_repr(obj) # Default to just name | ||
content_type = obj.content_type | ||
|
@@ -69,14 +73,10 @@ def object_link(self, obj): | |
pass | ||
return object_link | ||
|
||
object_link.admin_order_field = "object_repr" | ||
object_link.short_description = "object" | ||
|
||
@admin.display(description="change message") | ||
def get_change_message(self, obj): | ||
return obj.get_change_message() | ||
|
||
get_change_message.short_description = "change message" | ||
|
||
def has_add_permission(self, request): | ||
return False | ||
|
||
|
@@ -127,6 +127,7 @@ class SignatureAdmin(admin.ModelAdmin): | |
search_fields = ["signature"] | ||
|
||
|
||
@admin.action(description="Process crashes") | ||
def process_crashes(modeladmin, request, queryset): | ||
"""Process selected missing processed crashes from admin page.""" | ||
priority_api = PriorityJob() | ||
|
@@ -137,9 +138,6 @@ def process_crashes(modeladmin, request, queryset): | |
) | ||
|
||
|
||
process_crashes.short_description = "Process crashes" | ||
|
||
|
||
@admin.register(MissingProcessedCrash) | ||
class MissingProcessedCrashAdmin(admin.ModelAdmin): | ||
list_display = [ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,4 +43,3 @@ | |
@dark-gray: @dark-grey; | ||
|
||
@jsonview-prop: #fcb35f; | ||
@jsonview-bool: #f89962; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,9 +24,9 @@ div#message { | |
} | ||
.message.warning { | ||
background-color: @pink; | ||
border: 1px solid @jsonview-bool; | ||
border: 1px solid @orange; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got rid of |
||
} | ||
.message h2 { | ||
margin: .5em 0; | ||
font-size: 1.2em; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
# file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
import copy | ||
from io import StringIO | ||
import json | ||
import re | ||
from unittest import mock | ||
|
@@ -201,7 +202,7 @@ def test_html(self): | |
handler500 = getattr(views, end) | ||
|
||
# to make a mock call to the django view functions you need a request | ||
fake_request = RequestFactory().request(**{"wsgi.input": None}) | ||
fake_request = RequestFactory().request(**{"wsgi.input": StringIO("")}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Turns out when you pass |
||
|
||
# the reason for first causing an exception to be raised is because | ||
# the handler500 function is only called by django when an exception | ||
|
@@ -223,7 +224,7 @@ def test_json(self): | |
views = __import__(par, globals(), locals(), [end], 0) | ||
handler500 = getattr(views, end) | ||
|
||
fake_request = RequestFactory().request(**{"wsgi.input": None}) | ||
fake_request = RequestFactory().request(**{"wsgi.input": StringIO("")}) | ||
# This is what the utils.json_view decorator sets on views | ||
# that should eventually return JSON. | ||
fake_request._json_view = True | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got tired of the pip warning, so I updated pip, too.