This repository has been archived by the owner on Aug 7, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: track worksheet usage * fix: track worksheet badges * make user nullable * remove unused args * Merge branch 'worksheet_usage' into worksheet_badges * remove unused args * silence pylint unused arg error * silence pylint unused arg error * fix: worksheet usage * merge * simplify * relock * Merge branch 'worksheet_usage' into worksheet_badges * merge from master * testy signals * pytest config
- Loading branch information
Showing
7 changed files
with
152 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
// Use IntelliSense to learn about possible attributes. | ||
// Hover to view descriptions of existing attributes. | ||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 | ||
"version": "0.2.0", | ||
"configurations": [ | ||
{ | ||
"name": "Django Server", | ||
"type": "python", | ||
"request": "launch", | ||
"django": true, | ||
"justMyCode": false, | ||
"program": "${workspaceFolder}/example_project/manage.py", | ||
"args": [ | ||
"runserver", | ||
"localhost:8000" | ||
] | ||
}, | ||
{ | ||
"name": "Pytest", | ||
"type": "python", | ||
"request": "test", | ||
"justMyCode": false, | ||
"presentation": { | ||
"hidden": true | ||
} | ||
} | ||
] | ||
} |
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,7 @@ | ||
{ | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true, | ||
"python.testing.pytestArgs": [ | ||
"./aimmo" | ||
] | ||
} |
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,30 @@ | ||
# Generated by Django 3.2.23 on 2023-11-10 11:35 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
import django.utils.timezone | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('aimmo', '0035_worksheetusage'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='WorksheetBadge', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('worksheet_id', models.IntegerField()), | ||
('badge_id', models.IntegerField()), | ||
('created_at', models.DateTimeField(default=django.utils.timezone.now)), | ||
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL)), | ||
], | ||
options={ | ||
'unique_together': {('user', 'worksheet_id', 'badge_id')}, | ||
}, | ||
), | ||
] |
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,45 @@ | ||
from common.models import UserProfile | ||
from django.contrib.auth.models import User | ||
from django.test import TestCase | ||
|
||
from ..models import WorksheetBadge | ||
|
||
|
||
class TestSignals(TestCase): | ||
def test_pre_save___user_profile__create_worksheet_badge(self): | ||
user = User.objects.create_user( | ||
"JDoe", | ||
"[email protected]", | ||
"password", | ||
) | ||
|
||
user_profile = UserProfile.objects.create(user=user) | ||
assert not WorksheetBadge.objects.exists() | ||
|
||
def assert_worksheet_badges(): | ||
worksheet_badges = [ | ||
WorksheetBadge( | ||
user=user, | ||
worksheet_id=1, | ||
badge_id=1, | ||
), | ||
WorksheetBadge( | ||
user=user, | ||
worksheet_id=1, | ||
badge_id=2, | ||
), | ||
] | ||
assert len(worksheet_badges) == WorksheetBadge.objects.count() | ||
for worksheet_badge, expected_worksheet_badge in zip(WorksheetBadge.objects.all(), worksheet_badges): | ||
assert ( | ||
worksheet_badge.user == expected_worksheet_badge.user | ||
and worksheet_badge.worksheet_id == expected_worksheet_badge.worksheet_id | ||
and worksheet_badge.badge_id == expected_worksheet_badge.badge_id | ||
) | ||
|
||
user_profile.aimmo_badges = "1:1,1:2" | ||
user_profile.save() | ||
assert_worksheet_badges() | ||
|
||
user_profile.save() | ||
assert_worksheet_badges() |