Skip to content

Commit 82d9277

Browse files
Merge branch 'main' into github-artifacts
2 parents f16d3b1 + 3ec8972 commit 82d9277

File tree

7 files changed

+53
-9
lines changed

7 files changed

+53
-9
lines changed

.github/workflows/lint-test.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ jobs:
9797
- name: Migrations and run tests with coverage.py
9898
run: |
9999
python manage.py makemigrations --check
100-
python manage.py migrate
101100
coverage run manage.py test --no-input
102101
coverage report -m
103102
env:

docker-compose.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@
88
# and additionally use the Django development server which is
99
# unsuitable for production.
1010

11-
version: "3.6"
11+
version: "3.8"
1212
services:
1313
postgres:
1414
image: postgres:13-alpine
1515
ports:
16-
- "127.0.0.1:7777:5432"
16+
- "7777:5432"
1717
environment:
1818
POSTGRES_DB: pysite
1919
POSTGRES_PASSWORD: pysite
@@ -38,7 +38,7 @@ services:
3838
- admin.web
3939
- staff.web
4040
ports:
41-
- "127.0.0.1:8000:8000"
41+
- "8000:8000"
4242
depends_on:
4343
postgres:
4444
condition: service_healthy

manage.py

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,13 +95,15 @@ def set_dev_site_name() -> None:
9595
name="pythondiscord.local:8000"
9696
)
9797

98-
def prepare_server(self) -> None:
99-
"""Perform preparation tasks before running the server."""
98+
def prepare_environment(self) -> None:
99+
"""Perform common preparation tasks."""
100100
django.setup()
101101

102102
print("Applying migrations.")
103103
call_command("migrate", verbosity=self.verbosity)
104104

105+
def prepare_server(self) -> None:
106+
"""Preform runserver-specific preparation tasks."""
105107
if self.debug:
106108
# In Production, collectstatic is ran in the Docker image
107109
print("Collecting static files.")
@@ -121,6 +123,7 @@ def run_server(self) -> None:
121123

122124
# Prevent preparing twice when in dev mode due to reloader
123125
if not self.debug or in_reloader:
126+
self.prepare_environment()
124127
self.prepare_server()
125128

126129
print("Starting server.")
@@ -148,6 +151,11 @@ def run_server(self) -> None:
148151
# Run gunicorn for the production server.
149152
gunicorn.app.wsgiapp.run()
150153

154+
def run_tests(self) -> None:
155+
"""Prepare and run the test suite."""
156+
self.prepare_environment()
157+
call_command(*sys.argv[1:])
158+
151159

152160
def clean_up_static_files(build_folder: Path) -> None:
153161
"""Recursively loop over the build directory and fix links."""
@@ -168,8 +176,12 @@ def clean_up_static_files(build_folder: Path) -> None:
168176
def main() -> None:
169177
"""Entry point for Django management script."""
170178
# Use the custom site manager for launching the server
171-
if len(sys.argv) > 1 and sys.argv[1] == "run":
172-
SiteManager(sys.argv).run_server()
179+
if len(sys.argv) > 1 and sys.argv[1] in ("run", "test"):
180+
manager = SiteManager(sys.argv)
181+
if sys.argv[1] == "run":
182+
manager.run_server()
183+
elif sys.argv[1] == "test":
184+
manager.run_tests()
173185

174186
# Pass any others directly to standard management commands
175187
else:
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Generated by Django 4.0.6 on 2022-07-27 20:32
2+
3+
import django.utils.timezone
4+
from django.db import migrations, models
5+
from django.apps.registry import Apps
6+
7+
8+
def set_last_applied_to_inserted_at(apps: Apps, schema_editor):
9+
Infractions = apps.get_model("api", "infraction")
10+
Infractions.objects.all().update(last_applied=models.F("inserted_at"))
11+
12+
13+
class Migration(migrations.Migration):
14+
15+
dependencies = [
16+
('api', '0083_remove_embed_validation'),
17+
]
18+
19+
operations = [
20+
migrations.AddField(
21+
model_name='infraction',
22+
name='last_applied',
23+
field=models.DateTimeField(default=django.utils.timezone.now, help_text='The date and time of when this infraction was last applied.'),
24+
),
25+
migrations.RunPython(set_last_applied_to_inserted_at)
26+
]

pydis_site/apps/api/models/bot/infraction.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ class Infraction(ModelReprMixin, models.Model):
2323
default=timezone.now,
2424
help_text="The date and time of the creation of this infraction."
2525
)
26+
last_applied = models.DateTimeField(
27+
# This default is for backwards compatibility with bot versions
28+
# that don't explicitly give a value.
29+
default=timezone.now,
30+
help_text="The date and time of when this infraction was last applied."
31+
)
2632
expires_at = models.DateTimeField(
2733
null=True,
2834
help_text=(

pydis_site/apps/api/serializers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class Meta:
176176
fields = (
177177
'id',
178178
'inserted_at',
179+
'last_applied',
179180
'expires_at',
180181
'active',
181182
'user',

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ start = "python manage.py run --debug"
5252
makemigrations = "python manage.py makemigrations"
5353
django_shell = "python manage.py shell"
5454
test = "coverage run manage.py test"
55-
coverage = "coverage run manage.py test --no-input; coverage report -m"
55+
coverage = "coverage run manage.py test --no-input && coverage report -m"
5656
report = "coverage report -m"
5757
lint = "pre-commit run --all-files"
5858
precommit = "pre-commit install"

0 commit comments

Comments
 (0)