Skip to content

Commit 5b9aeaf

Browse files
committed
The changes made in this commit include:
- Added `src/signals/migrations/0004_rename_format_signal_format_type.py` - Modified `src/signals/admin.py` to change `format` to `format_type` - Modified `src/signals/filters.py` to change `format` to `format_type` - Modified `src/signals/models.py` to change `format` to `format_type` - Modified `src/signals/tests/factories.py` to change `format` to `format_type` - Added `src/signals/tests/test_api.py` to test the API view for the signal list - Modified `src/signals/views.py` to change `format` to `format_type` - Modified `src/templates/signals/signal_detail.html` to change `signal.format` to `signal.format_type` - Modified `src/templates/signals/signal_list.html` to change `filter.form.format` to `filter.form.format_type`
1 parent b4f58d4 commit 5b9aeaf

File tree

9 files changed

+80
-10
lines changed

9 files changed

+80
-10
lines changed

src/signals/admin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ class SignalAdmin(ImportExportModelAdmin):
5757
list_display: tuple[Literal['name']] = ('name',)
5858
search_fields: tuple[Literal['name'], Literal['description'], Literal['short_description']]
5959
search_fields = ('name', 'description', 'short_description')
60-
list_filter: tuple[Literal['pathogen'], Literal['available_geography'], Literal['signal_type'], Literal['format'],
60+
list_filter: tuple[Literal['pathogen'], Literal['available_geography'], Literal['signal_type'], Literal['format_type'],
6161
Literal['is_smoothed'], Literal['is_weighted'], Literal['is_cumulative'], Literal['has_stderr'], Literal['has_sample_size']]
6262
list_filter = (
6363
'pathogen',
6464
'available_geography',
6565
'signal_type',
66-
'format',
66+
'format_type',
6767
'is_smoothed',
6868
'is_weighted',
6969
'is_cumulative',

src/signals/filters.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Meta:
2222
'available_geography',
2323
'signal_type',
2424
'category',
25-
'format',
25+
'format_type',
2626
'source',
2727
'time_label',
2828
]
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Generated by Django 4.2.6 on 2023-11-01 16:40
2+
3+
from django.db import migrations
4+
5+
6+
class Migration(migrations.Migration):
7+
8+
dependencies = [
9+
('signals', '0003_alter_signal_options'),
10+
]
11+
12+
operations = [
13+
migrations.RenameField(
14+
model_name='signal',
15+
old_name='format',
16+
new_name='format_type',
17+
),
18+
]

src/signals/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ class Signal(TimeStampedModel):
177177
null=True,
178178
blank=True
179179
)
180-
format = models.CharField(
180+
format_type = models.CharField(
181181
help_text=_('Format'),
182182
max_length=128,
183183
choices=FormatChoices.choices

src/signals/tests/factories.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class SignalFactory(DjangoModelFactory):
7171
active = fake.boolean()
7272
short_description = fake.text(max_nb_chars=500)
7373
description = fake.text(max_nb_chars=500)
74-
format = fake.random_element(FormatChoices.values)
74+
format_type = fake.random_element(FormatChoices.values)
7575
time_type = fake.random_element(TimeTypeChoices.values)
7676
time_label = fake.random_element(TimeLabelChoices.values)
7777
category = SubFactory(SignalCategoryFactory)

src/signals/tests/test_api.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
from django.urls import reverse
2+
from faker import Faker
3+
from rest_framework.test import APITestCase
4+
5+
from signals.models import Signal
6+
from signals.tests.factories import SignalFactory
7+
8+
fake = Faker()
9+
10+
11+
class SignalListApiViewTest(APITestCase):
12+
13+
def setUp(self):
14+
for i in range(fake.random_int(min=1, max=100)):
15+
SignalFactory()
16+
17+
def test_signal_list_api_view(self):
18+
response = self.client.get(reverse('signals_api'))
19+
self.assertEqual(response.status_code, 200)
20+
self.assertEqual(response.data['count'], Signal.objects.count())
21+
22+
def test_signal_list_api_view_filters(self):
23+
signal = Signal.objects.order_by("?").first()
24+
signal.base = signal
25+
signal.save()
26+
response = self.client.get(reverse('signals_api'), {'name': signal.name})
27+
for result in response.json()['results']:
28+
self.assertEqual(signal.name, result['name'])
29+
response = self.client.get(reverse('signals_api'), {'pathogen__name': signal.pathogen.first().name})
30+
for result in response.json()['results']:
31+
self.assertTrue(signal.pathogen.first().name in result['pathogen'])
32+
response = self.client.get(reverse('signals_api'), {'available_geography__name': signal.available_geography.first().name})
33+
for result in response.json()['results']:
34+
self.assertTrue(signal.available_geography.first().name in result['available_geography'])
35+
response = self.client.get(reverse('signals_api'), {'signal_type__name': signal.signal_type.first().name})
36+
for result in response.json()['results']:
37+
self.assertTrue(signal.signal_type.first().name in result['signal_type'])
38+
response = self.client.get(reverse('signals_api'), {'category__name': signal.category.name})
39+
for result in response.json()['results']:
40+
self.assertTrue(signal.category.name in result['category'])
41+
response = self.client.get(reverse('signals_api'), {'source__name': signal.source.name})
42+
for result in response.json()['results']:
43+
self.assertTrue(signal.source.name in result['source'])
44+
response = self.client.get(reverse('signals_api'), {'time_label': signal.time_label})
45+
for result in response.json()['results']:
46+
self.assertEqual(signal.time_label, result['time_label'])
47+
response = self.client.get(reverse('signals_api'), {'format_type': signal.format_type})
48+
for result in response.json()['results']:
49+
self.assertEqual(signal.format_type, result['format_type'])
50+
response = self.client.get(reverse('signals_api'), {'base': signal.base.id})
51+
for result in response.json()['results']:
52+
self.assertEqual(signal.base.id, result['base']['id'])

src/signals/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class SignalsListApiView(ListAPIView):
7777
'available_geography__name',
7878
'signal_type__name',
7979
'category__name',
80-
'format',
80+
'format_type',
8181
'base',
8282
'source__name',
8383
'time_label',

src/templates/signals/signal_detail.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ <h5 class="card-title">Details</h5>
7272

7373
<div class="row">
7474
<div class="col-lg-3 col-md-4 label">Format:</div>
75-
<div class="col-lg-9 col-md-8">{{ signal.format|title }}</div>
75+
<div class="col-lg-9 col-md-8">{{ signal.format_type|title }}</div>
7676
</div>
7777

7878
<br>

src/templates/signals/signal_list.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,9 @@ <h5 class="card-title">{{ filter.form.category.label }}</h5>
152152
</div>
153153
<div class="form-group">
154154
<div class="card-body">
155-
<h5 class="card-title">{{ filter.form.format.label }}</h5>
156-
<select name="{{ filter.form.format.name }}" class="form-select">
157-
{% for choice in filter.form.format.field.choices %}
155+
<h5 class="card-title">{{ filter.form.format_type.label }}</h5>
156+
<select name="{{ filter.form.format_type.name }}" class="form-select">
157+
{% for choice in filter.form.format_type.field.choices %}
158158
<option value="{{ choice.0 }}">{{ choice.1 }}</option>
159159
{% endfor %}
160160
</select>

0 commit comments

Comments
 (0)