from books.factories import InstrumentFactory, InstrumentTypeFactory
from core.tests.base_test import SkillboxTestCase

INSTRUMENT_TYPES_QUERY = """
query InstrumentTypesQuery {
  instrumentTypes {
    name
    type
    category {
      id
      name
      foreground
      background
    }
  }
}
"""


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)
        InstrumentFactory(new_type=second_type)
        InstrumentFactory(new_type=second_type)
        InstrumentFactory(new_type=second_type)
        InstrumentFactory(new_type=second_type)

    def test_instrument_types_empty_not_returned(self):
        result = self.get_client().execute(INSTRUMENT_TYPES_QUERY)
        self.assertIsNone(result.errors)
        self.assertEqual(len(result.data['instrumentTypes']), 2)
