fix #5145 bug(reporting): Model Changes to allow old_status to be None and str rep change (#5146)

Because:

* old_status needs to be ble to be None for creation changelogs
* String representation change would allow for easier debugging

This commit:

* allows old_status to be None
* Changes the str rep of ReportLog object to something more descriptive
This commit is contained in:
Tif Tran 2021-06-04 08:58:40 -07:00 коммит произвёл GitHub
Родитель 5f491b9ab6
Коммит 58520ffde2
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 50 добавлений и 1 удалений

Просмотреть файл

@ -0,0 +1,31 @@
# Generated by Django 3.1.8 on 2021-05-02 06:08
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("reporting", "0001_initial"),
]
operations = [
migrations.AlterField(
model_name="reportlog",
name="experiment_old_status",
field=models.CharField(
blank=True,
choices=[
("Draft", "Draft"),
("Preview", "Preview"),
("Review", "Review"),
("Ship", "Ship"),
("Accepted", "Accepted"),
("Live", "Live"),
("Complete", "Complete"),
],
max_length=255,
null=True,
),
),
]

Просмотреть файл

@ -16,7 +16,10 @@ class ReportLog(models.Model):
choices=ReportLogConstants.ExperimentType.choices,
)
experiment_old_status = models.CharField(
max_length=255, choices=ReportLogConstants.ExperimentStatus.choices
max_length=255,
choices=ReportLogConstants.ExperimentStatus.choices,
blank=True,
null=True,
)
experiment_new_status = models.CharField(
max_length=255, choices=ReportLogConstants.ExperimentStatus.choices
@ -40,6 +43,9 @@ class ReportLog(models.Model):
self.clean()
super().save(*args, **kwargs)
def __str__(self):
return f"{self.timestamp} - {self.experiment_type} - {self.event_reason} "
class Meta:
ordering = ("timestamp",)
verbose_name = "ReportLog"

Просмотреть файл

@ -15,3 +15,15 @@ class TestReportLog(TestCase):
self.assertEqual(ReportLog.objects.count(), 0)
ReportLogFactory.create()
self.assertEqual(ReportLog.objects.count(), 1)
def test_reportlog_saves_with_null_old_status(self):
self.assertEqual(ReportLog.objects.count(), 0)
ReportLog.objects.create(
experiment_slug="experiment-slug",
experiment_name="experiment name",
experiment_type="Nimbus IOS",
experiment_new_status="Draft",
event="Create",
event_reason="New",
)
self.assertEqual(ReportLog.objects.count(), 1)