Skip to content

Commit

Permalink
Add/update migrations and tests for ChoicesEnum fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bjester committed Nov 21, 2023
1 parent db59986 commit 2ce461f
Show file tree
Hide file tree
Showing 7 changed files with 93 additions and 26 deletions.
14 changes: 7 additions & 7 deletions kolibri/core/content/migrations/0033_content_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ class Migration(migrations.Migration):
(
"type",
models.CharField(
choices=[("Download", "DOWNLOAD"), ("Removal", "REMOVAL")],
choices=[("DOWNLOAD", "Download"), ("REMOVAL", "Removal")],
max_length=8,
),
),
(
"reason",
models.CharField(
choices=[
("SyncInitiated", "SYNC_INITIATED"),
("UserInitiated", "USER_INITIATED"),
("SYNC_INITIATED", "SyncInitiated"),
("USER_INITIATED", "UserInitiated"),
],
max_length=14,
),
Expand All @@ -60,10 +60,10 @@ class Migration(migrations.Migration):
"status",
models.CharField(
choices=[
("Completed", "COMPLETED"),
("Failed", "FAILED"),
("InProgress", "IN_PROGRESS"),
("Pending", "PENDING"),
("COMPLETED", "Completed"),
("FAILED", "Failed"),
("IN_PROGRESS", "InProgress"),
("PENDING", "Pending"),
],
max_length=11,
),
Expand Down
28 changes: 14 additions & 14 deletions kolibri/core/device/migrations/0019_syncqueue_and_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ class Migration(migrations.Migration):
name="status",
field=models.CharField(
choices=[
("Ineligible", "INELIGIBLE"),
("Pending", "PENDING"),
("Queued", "QUEUED"),
("Ready", "READY"),
("Stale", "STALE"),
("Syncing", "SYNCING"),
("Unavailable", "UNAVAILABLE"),
("INELIGIBLE", "Ineligible"),
("PENDING", "Pending"),
("QUEUED", "Queued"),
("READY", "Ready"),
("STALE", "Stale"),
("SYNCING", "Syncing"),
("UNAVAILABLE", "Unavailable"),
],
default="PENDING",
max_length=20,
Expand All @@ -57,13 +57,13 @@ class Migration(migrations.Migration):
name="status",
field=models.CharField(
choices=[
("Ineligible", "INELIGIBLE"),
("Pending", "PENDING"),
("Queued", "QUEUED"),
("Ready", "READY"),
("Stale", "STALE"),
("Syncing", "SYNCING"),
("Unavailable", "UNAVAILABLE"),
("INELIGIBLE", "Ineligible"),
("PENDING", "Pending"),
("QUEUED", "Queued"),
("READY", "Ready"),
("STALE", "Stale"),
("SYNCING", "Syncing"),
("UNAVAILABLE", "Unavailable"),
],
default="PENDING",
max_length=20,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2023-11-21 15:08
from __future__ import unicode_literals

from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("device", "0019_syncqueue_and_status"),
]

operations = [
migrations.AlterField(
model_name="learnerdevicestatus",
name="status_sentiment",
field=models.IntegerField(
choices=[(-1, "Negative"), (0, "Neutral"), (1, "Positive")]
),
),
]
2 changes: 1 addition & 1 deletion kolibri/core/device/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ def save_learner_status(cls, learner_user_id, status):
instance_model = InstanceIDModel.get_or_create_current_instance()[0]

# in order to save a status, it must be defined
if not any(status == choice for _, choice in DeviceStatus.choices()):
if not any(status == choice for choice, _ in DeviceStatus.choices()):
raise ValueError("Value '{}' is not a valid status".format(status[0]))

cls.objects.update_or_create(
Expand Down
7 changes: 6 additions & 1 deletion kolibri/core/device/test/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def test_save_learner_status__updated(self):
test_status = ("TestStatus", StatusSentiment.Positive)

with mock.patch.object(DeviceStatus, "choices") as mock_choices:
mock_choices.return_value = [(test_status[0], test_status)]
mock_choices.return_value = [(test_status, test_status[0])]
LearnerDeviceStatus.save_learner_status(self.user.id, test_status)

self.assertFalse(
Expand Down Expand Up @@ -176,7 +176,12 @@ def test_morango_fields(self):
LearnerDeviceStatus.save_learner_status(
self.user.id, DeviceStatus.InsufficientStorage
)

device_status = LearnerDeviceStatus.objects.get(user=self.user)
# this is called after deserializing during a sync, so make sure that a model can be
# successfully saved after deserializing
device_status.full_clean()

self.assertEqual(self.facility.dataset_id, device_status.dataset_id)
self.assertEqual(
"{}:{}".format(self.instance.id, self.user.id),
Expand Down
6 changes: 3 additions & 3 deletions kolibri/core/discovery/migrations/0009_add_location_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ class Migration(migrations.Migration):
name="location_type",
field=models.CharField(
choices=[
("Dynamic", "dynamic"),
("Reserved", "reserved"),
("Static", "static"),
("dynamic", "Dynamic"),
("reserved", "Reserved"),
("static", "Static"),
],
default="static",
max_length=8,
Expand Down
39 changes: 39 additions & 0 deletions kolibri/core/notifications/migrations/0006_fix_choices.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2023-11-21 15:03
from __future__ import unicode_literals

from django.db import migrations
from django.db import models


class Migration(migrations.Migration):

dependencies = [
("notifications", "0005_learnerprogressnotification_assignment_collections"),
]

operations = [
migrations.AlterField(
model_name="learnerprogressnotification",
name="notification_event",
field=models.CharField(
blank=True,
choices=[
("Answered", "Answered"),
("Completed", "Completed"),
("HelpNeeded", "Help"),
("Started", "Started"),
],
max_length=200,
),
),
migrations.AlterField(
model_name="learnerprogressnotification",
name="reason",
field=models.CharField(
blank=True,
choices=[("MultipleUnsuccessfulAttempts", "Multiple")],
max_length=200,
),
),
]

0 comments on commit 2ce461f

Please sign in to comment.