mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-03-15 20:54:53 +00:00
parent
f406ce8d4d
commit
09593c80d9
3 changed files with 36 additions and 11 deletions
|
@ -1,9 +1,13 @@
|
|||
# Changelog
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
## v2.7-dev - Unreleased
|
||||
## v2.6.1 - 2023-01-26
|
||||
|
||||
WIP
|
||||
### Improvements
|
||||
- Improve Prometheus docs, add section "Available Metrics"
|
||||
|
||||
### Bug Fixes
|
||||
- Fix a crash in the "createsuperuser" management command (#779)
|
||||
|
||||
## v2.6 - 2023-01-23
|
||||
|
||||
|
|
|
@ -1,10 +1,11 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import getpass
|
||||
from getpass import getpass
|
||||
|
||||
from django.core.exceptions import ValidationError
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from hc.accounts.forms import SignupForm
|
||||
from hc.accounts.forms import LowercaseEmailField
|
||||
from hc.accounts.views import _make_user
|
||||
|
||||
|
||||
|
@ -17,16 +18,15 @@ class Command(BaseCommand):
|
|||
|
||||
while not email:
|
||||
raw = input("Email address:")
|
||||
form = SignupForm({"identity": raw})
|
||||
if not form.is_valid():
|
||||
self.stderr.write("Error: " + " ".join(form.errors["identity"]))
|
||||
try:
|
||||
email = LowercaseEmailField().clean(raw)
|
||||
except ValidationError as e:
|
||||
self.stderr.write("Error: " + " ".join(e.messages))
|
||||
continue
|
||||
|
||||
email = form.cleaned_data["identity"]
|
||||
|
||||
while not password:
|
||||
p1 = getpass.getpass()
|
||||
p2 = getpass.getpass("Password (again):")
|
||||
p1 = getpass()
|
||||
p2 = getpass("Password (again):")
|
||||
if p1.strip() == "":
|
||||
self.stderr.write("Error: Blank passwords aren't allowed.")
|
||||
continue
|
||||
|
|
21
hc/accounts/tests/test_createsuperuser.py
Normal file
21
hc/accounts/tests/test_createsuperuser.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import Mock, patch
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from hc.accounts.management.commands.createsuperuser import Command
|
||||
from hc.test import BaseTestCase
|
||||
|
||||
|
||||
class CreateSuperuserTestCase(BaseTestCase):
|
||||
def test_it_works(self):
|
||||
cmd = Command(stdout=Mock())
|
||||
with patch(cmd.__module__ + ".input") as mock_input:
|
||||
with patch(cmd.__module__ + ".getpass") as mock_getpass:
|
||||
mock_input.return_value = "superuser@example.org"
|
||||
mock_getpass.return_value = "hunter2"
|
||||
cmd.handle()
|
||||
|
||||
u = User.objects.get(email="superuser@example.org")
|
||||
self.assertTrue(u.is_superuser)
|
Loading…
Reference in a new issue