def test_deserialize_new_mission(self):
     data = {"id": 2, "name": "m1", "setting": {"toolbox": "tb1"}}
     serializer = ProblemSetSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     mission = serializer.save()
     assert mission.id == 2
     assert mission.name == 'm1'
     assert mission.section == '1'
     assert mission.setting == {"toolbox": "tb1"}
 def test_deserialize_new_ps_with_tasks(self):
     task1 = Task.objects.create(id=1, name='t1')
     data = {
         'id': 1,
         'name': 'wormholes',
         'setting': {'toolbox': 'fly'},
         'tasks': ['t1']}
     serializer = ProblemSetSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     ps = serializer.save()
     assert list(ps.tasks.all()) == [task1]
 def test_deserialize_new_ps(self):
     data = {'id': 1, 'name': 'wormholes', 'setting': {'toolbox': 'fly'}}
     serializer = ProblemSetSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     ps = serializer.save()
     assert ps.id is not None
     assert ps.name == 'wormholes'
     # TODO: test section/order: assert ps.order == 5
     assert ps.setting == {'toolbox': 'fly'}
     assert ps.tasks.count() == 0
     assert ps.parts.count() == 0
 def test_change_tasks_of_existing_ps(self):
     ps = ProblemSet.objects.create(name='ps1')
     ps.add_task(name='t1')
     t2 = ps.add_task(name='t2')
     t3 = Task.objects.create(name='t3')
     data = {'name': 'ps1', 'tasks': ['t2', 't3']}
     serializer = ProblemSetSerializer(ps, data=data, partial=True)
     serializer.is_valid(raise_exception=True)
     ps = serializer.save()
     ps_db = ProblemSet.objects.get(name='ps1')
     assert ps == ps_db
     assert set(ps_db.tasks.all()) == {t2, t3}
 def test_deserialize_new_mission(self):
     data = {
         "id": 2,
         "name": "m1",
         "setting": { "toolbox": "tb1" }}
     serializer = ProblemSetSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     mission = serializer.save()
     assert mission.id == 2
     assert mission.name == 'm1'
     assert mission.section == '1'
     assert mission.setting == { "toolbox": "tb1" }
 def test_change_parts_of_existing_ps(self):
     ps1 = ProblemSet.objects.create(id=1, name='ps1')
     ps2 = ProblemSet.objects.create(id=2, name='ps2')
     ps3 = ProblemSet.objects.create(id=3, name='ps3')
     ps4 = ProblemSet.objects.create(id=4, name='ps4')
     ps1.parts.set([ps2, ps3])
     data = {'name': 'ps1', 'parts': ['ps3', 'ps4']}
     serializer = ProblemSetSerializer(ps1, data=data, partial=True)
     serializer.is_valid(raise_exception=True)
     ps = serializer.save()
     ps_db = ProblemSet.objects.get(pk=1)
     assert ps == ps_db
     assert set(ps_db.parts.all()) == {ps3, ps4}
 def test_deserialize_new_ps_with_tasks(self):
     task1 = Task.objects.create(id=1, name='t1')
     data = {
         'id': 1,
         'name': 'wormholes',
         'setting': {
             'toolbox': 'fly'
         },
         'tasks': ['t1']
     }
     serializer = ProblemSetSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     ps = serializer.save()
     assert list(ps.tasks.all()) == [task1]
 def test_change_tasks_of_existing_ps(self):
     ps = ProblemSet.objects.create(name='ps1')
     ps.add_task(name='t1')
     t2 = ps.add_task(name='t2')
     t3 = Task.objects.create(name='t3')
     data = {
         'name': 'ps1',
         'tasks': ['t2', 't3']}
     serializer = ProblemSetSerializer(ps, data=data, partial=True)
     serializer.is_valid(raise_exception=True)
     ps = serializer.save()
     ps_db = ProblemSet.objects.get(name='ps1')
     assert ps == ps_db
     assert set(ps_db.tasks.all()) == {t2, t3}
 def test_deserialize_new_ps(self):
     data = {
         'id': 1,
         'name': 'wormholes',
         'setting': {'toolbox': 'fly'}}
     serializer = ProblemSetSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     ps = serializer.save()
     assert ps.id is not None
     assert ps.name == 'wormholes'
     # TODO: test section/order: assert ps.order == 5
     assert ps.setting == {'toolbox': 'fly'}
     assert ps.tasks.count() == 0
     assert ps.parts.count() == 0
 def test_update_existing_mission(self):
     m1 = ProblemSet.objects.create(pk=1, name='m1')
     p1 = ProblemSet.objects.create(pk=2, name='p1', parent=m1)
     data = {
         "id": 1,
         "name": "m1n",
         "setting": { "toolbox": "tb1" },
         "parts": [ "p1" ]}
     serializer = ProblemSetSerializer(m1, data=data)
     serializer.is_valid(raise_exception=True)
     m1 = serializer.save()
     assert m1.id == 1
     assert m1.name == 'm1n'
     assert m1.setting == { "toolbox": "tb1" }
     assert list(m1.parts.all()) == [p1]
 def test_change_parts_of_existing_ps(self):
     ps1 = ProblemSet.objects.create(id=1, name='ps1')
     ps2 = ProblemSet.objects.create(id=2, name='ps2')
     ps3 = ProblemSet.objects.create(id=3, name='ps3')
     ps4 = ProblemSet.objects.create(id=4, name='ps4')
     ps1.parts.set([ps2, ps3])
     data = {
         'name': 'ps1',
         'parts': ['ps3', 'ps4']}
     serializer = ProblemSetSerializer(ps1, data=data, partial=True)
     serializer.is_valid(raise_exception=True)
     ps = serializer.save()
     ps_db = ProblemSet.objects.get(pk=1)
     assert ps == ps_db
     assert set(ps_db.parts.all()) == {ps3, ps4}
 def test_update_existing_ps(self):
     task1 = Task.objects.create(id=1, name='t1')
     ps = ProblemSet.objects.create(id=2, name='ps1')
     data = {
         'id': 2,
         'name': 'ps2',
         'setting': {'toolbox': 'fly'},
         'tasks': ['t1']}
     serializer = ProblemSetSerializer(ps, data=data, partial=True)
     serializer.is_valid(raise_exception=True)
     ps = serializer.save()
     ps_db = ProblemSet.objects.get(pk=2)
     assert ps == ps_db
     assert ps_db.name == 'ps2'
     assert ps_db.setting == {'toolbox': 'fly'}
     assert list(ps_db.tasks.all()) == [task1]
 def test_update_existing_mission(self):
     m1 = ProblemSet.objects.create(pk=1, name='m1')
     p1 = ProblemSet.objects.create(pk=2, name='p1', parent=m1)
     data = {
         "id": 1,
         "name": "m1n",
         "setting": {
             "toolbox": "tb1"
         },
         "parts": ["p1"]
     }
     serializer = ProblemSetSerializer(m1, data=data)
     serializer.is_valid(raise_exception=True)
     m1 = serializer.save()
     assert m1.id == 1
     assert m1.name == 'm1n'
     assert m1.setting == {"toolbox": "tb1"}
     assert list(m1.parts.all()) == [p1]
 def test_update_existing_ps(self):
     task1 = Task.objects.create(id=1, name='t1')
     ps = ProblemSet.objects.create(id=2, name='ps1')
     data = {
         'id': 2,
         'name': 'ps2',
         'setting': {
             'toolbox': 'fly'
         },
         'tasks': ['t1']
     }
     serializer = ProblemSetSerializer(ps, data=data, partial=True)
     serializer.is_valid(raise_exception=True)
     ps = serializer.save()
     ps_db = ProblemSet.objects.get(pk=2)
     assert ps == ps_db
     assert ps_db.name == 'ps2'
     assert ps_db.setting == {'toolbox': 'fly'}
     assert list(ps_db.tasks.all()) == [task1]
 def test_deserialize_ps_without_setting(self):
     data = {'id': 1, 'name': 'wormholes'}
     serializer = ProblemSetSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     ps = serializer.save()
     assert ps.setting == {}
 def test_deserialize_ps_without_setting(self):
     data = {'id': 1, 'name': 'wormholes'}
     serializer = ProblemSetSerializer(data=data)
     serializer.is_valid(raise_exception=True)
     ps = serializer.save()
     assert ps.setting == {}