def test_deserialize_list_of_new_chunks__remove_old(self): domain = Domain.objects.create() ProblemSet.objects.create(id=2, name='c2') data = [{'id': 1, 'name': 'c1'}] serializer = ProblemSetSerializer(many=True) serializer.set(domain.problemsets, data) assert {chunk.pk for chunk in domain.problemsets.all()} == {1}
def test_deserialize_list_of_new_ps_with_parts(self): domain = Domain.objects.create() data = [ {'id': 1, 'name': 'ps1'}, {'id': 2, 'name': 'ps2', 'parts': ['ps1']}] serializer = ProblemSetSerializer(many=True) serializer.set(domain.problemsets, data)
def test_deserialize_list_of_new_missions__delete_existing(self): domain = Domain.objects.create() m1 = ProblemSet.objects.create(pk=1, name='m1') data = [{'id': 2, 'name': 'm2'}] serializer = ProblemSetSerializer(many=True) serializer.set(domain.problemsets, data) problemsets = list(domain.problemsets.all()) assert len(problemsets) == 1 assert problemsets[0].name == 'm2'
def test_deserialize_list_of_new_missions(self): data = [{'id': 1, 'name': 'm1'}, {'id': 2, 'name': 'm2'}] domain = Domain.objects.create() serializer = ProblemSetSerializer(many=True) serializer.set(domain.problemsets, data) problemsets = list(domain.problemsets.all()) assert len(problemsets) == 2 assert problemsets[0].name == 'm1' assert problemsets[0].section == '1' assert problemsets[1].name == 'm2' assert problemsets[1].section == '2'
def test_deserialize_list_of_new_ps(self): domain = Domain.objects.create() data = [{'id': 1, 'name': 'ps1'}, {'id': 2, 'name': 'ps2'}] serializer = ProblemSetSerializer(many=True) serializer.set(domain.problemsets, data) ps1 = ProblemSet.objects.get(pk=1) ps2 = ProblemSet.objects.get(pk=2) assert ps1.name == 'ps1' assert ps1.order == 1 assert ps2.name == 'ps2' assert ps2.order == 2
def test_deserialize_list_of_new_chunks__update_existing(self): domain = Domain.objects.create() ps = ProblemSet.objects.create(id=2, name='ps2', section='5') data = [ {'id': 1, 'name': 'ps1'}, {'id': 2, 'name': 'ps2-v2', 'section': '7'}] serializer = ProblemSetSerializer(many=True) serializer.set(domain.problemsets, data) ps = ProblemSet.objects.get(pk=2) assert ps.name == 'ps2-v2' assert ps.section == '7'
def test_deserialize_list_of_new_ps_with_parts(self): domain = Domain.objects.create() data = [{ 'id': 1, 'name': 'ps1' }, { 'id': 2, 'name': 'ps2', 'parts': ['ps1'] }] serializer = ProblemSetSerializer(many=True) serializer.set(domain.problemsets, data)
def test_deserialize_list_of_new_missions(self): data = [ {'id': 1, 'name': 'm1'}, {'id': 2, 'name': 'm2'}] domain = Domain.objects.create() serializer = ProblemSetSerializer(many=True) serializer.set(domain.problemsets, data) problemsets = list(domain.problemsets.all()) assert len(problemsets) == 2 assert problemsets[0].name == 'm1' assert problemsets[0].section == '1' assert problemsets[1].name == 'm2' assert problemsets[1].section == '2'
def test_deserialize_list_of_new_chunks__update_existing(self): domain = Domain.objects.create() ps = ProblemSet.objects.create(id=2, name='ps2', section='5') data = [{ 'id': 1, 'name': 'ps1' }, { 'id': 2, 'name': 'ps2-v2', 'section': '7' }] serializer = ProblemSetSerializer(many=True) serializer.set(domain.problemsets, data) ps = ProblemSet.objects.get(pk=2) assert ps.name == 'ps2-v2' assert ps.section == '7'