Skip to content

Commit

Permalink
Change to decimal, change to tuple, change slug to nt_version
Browse files Browse the repository at this point in the history
  • Loading branch information
uhlissuh committed Mar 18, 2020
1 parent 4fee17a commit 95fc027
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
7 changes: 4 additions & 3 deletions normandy/recipes/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ class WindowsVersionFilter(BaseComparisonFilter):
``windows_version``
.. attribute:: value
string, must be one of the following: 6.1, 6.2, 6.3, 10.0
number, decimal, must be one of the following: 6.1, 6.2, 6.3, 10.0
:example: ``6.1``
Expand All @@ -614,7 +614,7 @@ class WindowsVersionFilter(BaseComparisonFilter):
"""

type = "windows_version"
value = serializers.CharField()
value = serializers.DecimalField(max_digits=3, decimal_places=1)

@property
def left_of_operator(self):
Expand All @@ -626,7 +626,7 @@ def to_jexl(self):
def validate_value(self, value):
from normandy.recipes.models import WindowsVersion

if not WindowsVersion.objects.filter(slug=value).exists():
if not WindowsVersion.objects.filter(nt_version=value).exists():
raise serializers.ValidationError(f"Unrecognized windows version slug {value!r}")

return value
Expand Down Expand Up @@ -700,6 +700,7 @@ def capabilities(self):
PrefExistsFilter,
PrefCompareFilter,
PrefUserSetFilter,
WindowsVersionFilter,
]
}

Expand Down
18 changes: 9 additions & 9 deletions normandy/recipes/management/commands/initial_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ def add_countries(self):

def add_windows_versions(self):
self.stdout.write("Adding Windows Versions...", ending="")
versions = {
"6.1": "Windows 7",
"6.2": "Windows 8",
"6.3": "Windows 8.1",
"10.0": "Windows 10.0",
}

for slug, name in versions.items():
WindowsVersion.objects.update_or_create(slug=slug, defaults={"name": name})
versions = [
(6.1, "Windows 7"),
(6.2, "Windows 8"),
(6.3, "Windows 8.1"),
(10.0, "Windows 10"),
]

for nt_version, name in versions:
WindowsVersion.objects.update_or_create(nt_version=nt_version, defaults={"name": name})
self.stdout.write("Done")
6 changes: 3 additions & 3 deletions normandy/recipes/migrations/0018_windowsversion.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 2.2.10 on 2020-03-16 23:24
# Generated by Django 2.2.10 on 2020-03-18 20:48

from django.db import migrations, models

Expand All @@ -17,9 +17,9 @@ class Migration(migrations.Migration):
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
("slug", models.CharField(max_length=255, unique=True)),
("nt_version", models.DecimalField(decimal_places=1, max_digits=3)),
("name", models.CharField(max_length=255)),
],
options={"ordering": ("slug",)},
options={"ordering": ("nt_version",)},
)
]
6 changes: 3 additions & 3 deletions normandy/recipes/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ def __repr__(self):


class WindowsVersion(models.Model):
slug = models.CharField(max_length=255, unique=True)
nt_version = models.DecimalField(max_digits=3, decimal_places=1)
name = models.CharField(max_length=255)

class Meta:
ordering = ("slug",)
ordering = ("nt_version",)

def __repr__(self):
return "<Windows Version {}>".format(self.slug)
return "<Windows Version {}>".format(self.nt_version)


class Country(models.Model):
Expand Down
4 changes: 2 additions & 2 deletions normandy/recipes/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class Meta:
class WindowsVersionFactory(factory.DjangoModelFactory):
class Meta:
model = WindowsVersion
django_get_or_create = ("slug",)
django_get_or_create = ("nt_version",)

slug = "6.1"
nt_version = 6.1
name = "Windows 7"


Expand Down
4 changes: 2 additions & 2 deletions normandy/recipes/tests/test_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,8 @@ def test_generates_jexl_error_on_bad_comparison(self):


class TestWindowsVersionFilter(FilterTestsBase):
def create_basic_filter(self, value="6.1", comparison="equal"):
WindowsVersionFactory(slug="6.1")
def create_basic_filter(self, value=6.1, comparison="equal"):
WindowsVersionFactory(nt_version=6.1)

return WindowsVersionFilter.create(value=value, comparison=comparison)

Expand Down

0 comments on commit 95fc027

Please sign in to comment.