コード例 #1
0
 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}
コード例 #2
0
 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}
コード例 #3
0
 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)
コード例 #4
0
 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'
コード例 #5
0
 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'
コード例 #6
0
 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'
コード例 #7
0
 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
コード例 #8
0
 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'
コード例 #9
0
 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
コード例 #10
0
 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)
コード例 #11
0
 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'
コード例 #12
0
 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'