Return only instrument types with assigned instruments

This commit is contained in:
Ramon Wenger 2021-11-10 12:47:52 +01:00
parent 422a1a3d58
commit f03beb8b34
7 changed files with 50 additions and 4 deletions

View File

@ -13,7 +13,7 @@ def create_new_types(apps, schema_editor):
language_communication_types = [ language_communication_types = [
'Analyse', 'Argumentation', 'Beschreibung', 'Grafiken', 'Interview', 'Analyse', 'Argumentation', 'Beschreibung', 'Grafiken', 'Interview',
'Kommunikation', 'Korrespondenz', 'Orthografie', 'Präsentation', 'Kommunikation', 'Korrespondenz', 'Orthografie', 'Präsentation',
'Struktur', 'Umfrage', 'Zusammenfassung' 'Struktur', 'Umfrage', 'Zusammenfassung', 'Blog'
] ]
society_types = [ society_types = [
'Ethik', 'Identität und Sozialisation', 'Kultur', 'Ökologie', 'Ethik', 'Identität und Sozialisation', 'Kultur', 'Ökologie',

View File

@ -0,0 +1,19 @@
# Generated by Django 2.2.24 on 2021-11-10 11:40
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('basicknowledge', '0012_auto_20211101_1008'),
]
operations = [
migrations.AlterField(
model_name='basicknowledge',
name='new_type',
field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='instruments', to='basicknowledge.InstrumentType'),
),
]

View File

@ -53,7 +53,7 @@ class BasicKnowledge(StrictHierarchyPage):
('subtitle', SubtitleBlock()), ('subtitle', SubtitleBlock()),
], null=True, blank=True) ], null=True, blank=True)
new_type = models.ForeignKey(InstrumentType, null=True, on_delete=models.PROTECT) new_type = models.ForeignKey(InstrumentType, null=True, on_delete=models.PROTECT, related_name='instruments')
old_type = models.CharField( old_type = models.CharField(
max_length=100, max_length=100,

View File

@ -64,4 +64,4 @@ class InstrumentQuery(object):
return BasicKnowledge.objects.all().live() return BasicKnowledge.objects.all().live()
def resolve_instrument_types(self, info, **kwargs): def resolve_instrument_types(self, info, **kwargs):
return InstrumentType.objects.all() return InstrumentType.objects.filter(instruments__isnull=False)

View File

View File

@ -0,0 +1,27 @@
from books.factories import InstrumentFactory, InstrumentTypeFactory
from core.tests.base_test import SkillboxTestCase
INSTRUMENT_TYPES_QUERY = """
query InstrumentTypesQuery {
instrumentTypes {
name
type
category
}
}
"""
class InstrumentTypesQueryTestCase(SkillboxTestCase):
def setUp(self) -> None:
self.createDefault()
self.type = InstrumentTypeFactory(name='Type O Negative')
second_type = InstrumentTypeFactory(name='Typecast')
InstrumentTypeFactory(name='Guitar')
self.instrument = InstrumentFactory(new_type=self.type)
InstrumentFactory(new_type=second_type)
def test_instrument_types_empty_not_returned(self):
result = self.get_client().get_result(INSTRUMENT_TYPES_QUERY)
self.assertIsNone(result.errors)
self.assertEqual(len(result.data['instrumentTypes']), 2)

View File

@ -23,7 +23,7 @@ class SkillboxTestCase(TestCase):
self.school_class = SchoolClass.objects.get(name='skillbox') self.school_class = SchoolClass.objects.get(name='skillbox')
def get_client(self, user=None) -> Client: def get_client(self, user=None) -> GQLClient:
request = RequestFactory().get('/') request = RequestFactory().get('/')
if user is None: if user is None:
user = self.teacher user = self.teacher