diff --git a/djangoldp/tests/runner.py b/djangoldp/tests/runner.py index 8e04314473e2e7b8898ed9f3fa004daa303dc121..1cf8604dbae8eda88317a21cac92b33636febbb5 100644 --- a/djangoldp/tests/runner.py +++ b/djangoldp/tests/runner.py @@ -24,6 +24,9 @@ from django.test.runner import DiscoverRunner test_runner = DiscoverRunner(verbosity=1) -failures = test_runner.run_tests(['djangoldp.tests.tests']) +failures = test_runner.run_tests([ + 'djangoldp.tests.tests_save', + 'djangoldp.tests.tests_update']) if failures: sys.exit(failures) + diff --git a/djangoldp/tests/tests.py b/djangoldp/tests/tests_save.py similarity index 61% rename from djangoldp/tests/tests.py rename to djangoldp/tests/tests_save.py index 647b26c367aa8bdcdfce3f581a9f937f1d15c9da..e4108d1fa513bedc54980414bf559c9b9f7fc8d3 100644 --- a/djangoldp/tests/tests.py +++ b/djangoldp/tests/tests_save.py @@ -6,7 +6,7 @@ from djangoldp.tests.models import Skill, JobOffer class Serializer(TestCase): - def test_container_serializer_save(self): + def test_save_m2m(self): skill1 = Skill.objects.create(title="skill1") skill2 = Skill.objects.create(title="skill2") job = {"title": "job test", @@ -43,3 +43,28 @@ class Serializer(TestCase): self.assertEquals(result.title, "job test") self.assertIs(result.skills.count(), 0) + + def test_update(self): + skill1 = Skill.objects.create(title="skill1") + skill2 = Skill.objects.create(title="skill2") + job1 = JobOffer.objects.create(title="job test") + + job = {"@id": "https://happy-dev.fr/skills/{}/".format(job1.pk), + "title": "job test updated", + "skills": { + "ldp:contains": [ + {"@id": "https://happy-dev.fr/skills/{}/".format(skill1.pk)}, + {"@id": "https://happy-dev.fr/skills/{}/".format(skill2.pk)}, + ]} + } + + meta_args = {'model': JobOffer, 'depth': 1, 'fields': ("@id", "title", "skills")} + + meta_class = type('Meta', (), meta_args) + serializer_class = type(LDPSerializer)('JobOfferSerializer', (LDPSerializer,), {'Meta': meta_class}) + serializer = serializer_class(data=job) + serializer.is_valid() + result = serializer.save() + + self.assertEquals(result.title, "job test updated") + self.assertIs(result.skills.count(), 0) diff --git a/djangoldp/tests/tests_update.py b/djangoldp/tests/tests_update.py new file mode 100644 index 0000000000000000000000000000000000000000..f2606c030fcfdfb6e778a9533a4ee1081c277464 --- /dev/null +++ b/djangoldp/tests/tests_update.py @@ -0,0 +1,32 @@ +from django.test import TestCase + +from djangoldp.serializers import LDPSerializer +from djangoldp.tests.models import Skill, JobOffer + + +class Serializer(TestCase): + + def test_update(self): + skill1 = Skill.objects.create(title="skill1") + skill2 = Skill.objects.create(title="skill2") + job1 = JobOffer.objects.create(title="job test") + + job = {"@id": "https://happy-dev.fr/skills/{}/".format(job1.pk), + "title": "job test updated", + "skills": { + "ldp:contains": [ + {"@id": "https://happy-dev.fr/skills/{}/".format(skill1.pk)}, + {"@id": "https://happy-dev.fr/skills/{}/".format(skill2.pk)}, + ]} + } + + meta_args = {'model': JobOffer, 'depth': 1, 'fields': ("@id", "title", "skills")} + + meta_class = type('Meta', (), meta_args) + serializer_class = type(LDPSerializer)('JobOfferSerializer', (LDPSerializer,), {'Meta': meta_class}) + serializer = serializer_class(data=job) + serializer.is_valid() + result = serializer.save() + + self.assertEquals(result.title, "job test updated") + self.assertIs(result.skills.count(), 2)