예제 #1
0
    def test_deleted_objects(self):
        """
        for:
        https://github.com/jedie/django-reversion-compare/commit/ba22008130f4c16a32eeb900381c2d82ca6fdd9e
        https://travis-ci.org/jedie/django-reversion-compare/builds/72317520
        """
        with reversion_api.create_revision():
            factory1 = Factory.objects.create(name="factory one",
                                              address="1 Fake Plaza")
            car = Car.objects.create(name="car", manufacturer=factory1)

        with reversion_api.create_revision():
            factory2 = Factory.objects.create(name="factory two",
                                              address="1 Fake Plaza")
            car.manufacturer = factory2
            car.save()

        with reversion_api.create_revision():
            factory1.delete()

        queryset = reversion_api.get_for_object(car)
        version_ids = queryset.values_list("pk", flat=True)  # [3, 2]
        # print("\n", version_ids)

        # response = self.client.get("/admin/tests/car/%s/history/" % car.pk)
        # debug_response(response) # from django-tools
        self.client.get("/admin/tests/car/%s/history/compare/" % car.pk,
                        data={
                            "version_id2": version_ids[0],
                            "version_id1": version_ids[1]
                        })
예제 #2
0
    def create_Simple_data(self):
        with reversion_api.create_revision():
            item1 = SimpleModel.objects.create(text="version one")

        if self.verbose:
            print("version 1:", item1)

        with reversion_api.create_revision():
            item1.text = "version two"
            item1.save()
            reversion_api.set_comment("simply change the CharField text.")

        if self.verbose:
            print("version 2:", item1)

        for no in range(5):
            with reversion_api.create_revision():
                if no == 0:
                    item2 = SimpleModel.objects.create(text="v0")
                    reversion_api.set_comment("create v%i" % no)
                else:
                    item2.text = "v%i" % no
                    item2.save()
                    reversion_api.set_comment("change to v%i" % no)

        return item1, item2
    def test_deleted_objects(self):
        """
        for:
        https://github.com/jedie/django-reversion-compare/commit/ba22008130f4c16a32eeb900381c2d82ca6fdd9e
        https://travis-ci.org/jedie/django-reversion-compare/builds/72317520
        """
        with reversion_api.create_revision():
            factory1 = Factory.objects.create(name="factory one", address="1 Fake Plaza")
            car = Car.objects.create(
                name="car",
                manufacturer=factory1
            )

        with reversion_api.create_revision():
            factory2 = Factory.objects.create(name="factory two", address="1 Fake Plaza")
            car.manufacturer=factory2
            car.save()

        with reversion_api.create_revision():
            factory1.delete()

        queryset = reversion_api.get_for_object(car)
        version_ids = queryset.values_list("pk", flat=True)  # [3, 2]
        # print("\n", version_ids)

        # response = self.client.get("/admin/tests/car/%s/history/" % car.pk)
        # debug_response(response) # from django-tools

        response = self.client.get(
            "/admin/tests/car/%s/history/compare/" % car.pk,
            data={"version_id2":version_ids[0], "version_id1":version_ids[1]}
        )
예제 #4
0
 def test_version_selection(self):
     "Generate two revisions and view the version history selection."
     with reversion_api.create_revision():
         self.item.text = "version two"
         self.item.save()
     with reversion_api.create_revision():
         self.item.text = "version three"
         self.item.save()
     queryset = custom_revision_manager.get_for_object(self.item)
     version_ids = queryset.values_list("pk", flat=True)
     self.assertEqual(len(version_ids), 3)
     url_name = 'admin:%s_%s_history' % (CustomModel._meta.app_label,
                                         CustomModel._meta.model_name)
     history_url = reverse(url_name, args=(self.item.pk, ))
     response = self.client.get(history_url)
     self.assertContainsHtml(
         response,
         '<input type="submit" value="compare">',
         '<input type="radio" name="version_id1" value="%i" style="visibility:hidden" />'
         % version_ids[0],
         '<input type="radio" name="version_id2" value="%i" checked="checked" />'
         % version_ids[0],
         '<input type="radio" name="version_id1" value="%i" checked="checked" />'
         % version_ids[1],
         '<input type="radio" name="version_id2" value="%i" />' %
         version_ids[1],
         '<input type="radio" name="version_id1" value="%i" />' %
         version_ids[2],
         '<input type="radio" name="version_id2" value="%i" />' %
         version_ids[2],
     )
예제 #5
0
    def create_Simple_data(self):
        with reversion_api.create_revision():
            item1 = SimpleModel.objects.create(text="version one")

        if self.verbose:
            print("version 1:", item1)

        with reversion_api.create_revision():
            item1.text = "version two"
            item1.save()
            reversion_api.set_comment("simply change the CharField text.")

        if self.verbose:
            print("version 2:", item1)

        for no in range(5):
            with reversion_api.create_revision():
                if no==0:
                    item2 = SimpleModel.objects.create(text="v0")
                    reversion_api.set_comment("create v%i" % no)
                else:
                    item2.text = "v%i" % no
                    item2.save()
                    reversion_api.set_comment("change to v%i" % no)

        return item1, item2
예제 #6
0
    def create_PersonIdentity_data(self):
        with reversion_api.create_revision():
            person = Person.objects.create(name="Dave")
            identity = Identity.objects.create(id_numer="1234", person=person)

        if self.verbose:
            print("version 1:", person, identity)

        with reversion_api.create_revision():
            person.name = "John"
            person.save()
            reversion_api.set_comment("version 2: change person name.")

        return person, identity
예제 #7
0
    def create_PersonIdentity_data(self):
        with reversion_api.create_revision():
            person = Person.objects.create(name="Dave")
            identity = Identity.objects.create(id_numer="1234", person=person)

        if self.verbose:
            print("version 1:", person, identity)

        with reversion_api.create_revision():
            person.name = "John"
            person.save()
            reversion_api.set_comment("version 2: change person name.")

        return person, identity
예제 #8
0
    def create_CustomModel_data(self):
        with reversion_api.create_revision():
            item1 = CustomModel.objects.create(text="version one")

        if self.verbose:
            print("version 1:", item1)

        return item1
예제 #9
0
    def create_CustomModel_data(self):
        with reversion_api.create_revision():
            item1 = CustomModel.objects.create(text="version one")

        if self.verbose:
            print("version 1:", item1)

        return item1
예제 #10
0
    def test_add_m2m(self):
        with reversion_api.create_revision():
            new_pet = Pet.objects.create(name="added pet")
            self.person.pets.add(new_pet)
            self.person.save()
            reversion_api.set_comment("version 3: add a pet")

        self.assertEqual(reversion_api.Revision.objects.all().count(), 3)
        self.assertEqual(reversion_api.Version.objects.all().count(), 12)

        queryset = reversion_api.get_for_object(self.person)
        version_ids = queryset.values_list("pk", flat=True)
        self.assertEqual(len(version_ids), 3)

        response = self.client.get("/admin/tests/person/%s/history/" %
                                   self.person.pk)
        #        debug_response(response) # from django-tools
        self.assertContainsHtml(
            response,
            '<input type="submit" value="compare">',
            '<input type="radio" name="version_id1" value="%i" style="visibility:hidden" />'
            % version_ids[0],
            '<input type="radio" name="version_id2" value="%i" checked="checked" />'
            % version_ids[0],
            '<input type="radio" name="version_id1" value="%i" checked="checked" />'
            % version_ids[1],
            '<input type="radio" name="version_id2" value="%i" />' %
            version_ids[1],
            '<input type="radio" name="version_id2" value="%i" />' %
            version_ids[2],
            '<input type="radio" name="version_id2" value="%i" />' %
            version_ids[2],
        )

        response = self.client.get("/admin/tests/person/%s/history/compare/" %
                                   self.person.pk,
                                   data={
                                       "version_id2": version_ids[0],
                                       "version_id1": version_ids[1]
                                   })
        #        debug_response(response) # from django-tools

        self.assertContainsHtml(
            response,
            """
            <p class="highlight">
                <ins>+ added pet</ins><br />
                Is changed pet<br />
                always the same pet<br />
            </p>
            """,
            "<blockquote>version 3: add a pet</blockquote>",  # edit comment
        )
        self.assertNotContainsHtml(
            response,
            "<h3>name</h3>",  # person name doesn't changed
            'class="follow"'  # All fields are under reversion control
        )
예제 #11
0
    def test_m2m_not_changed(self):
        with reversion_api.create_revision():
            self.person.name = "David"
            self.person.save()
            reversion_api.set_comment("version 3: change the name")

        self.assertEqual(reversion_api.Revision.objects.all().count(), 3)
        self.assertEqual(reversion_api.Version.objects.all().count(), 11)

        queryset = reversion_api.get_for_object(self.person)
        version_ids = queryset.values_list("pk", flat=True)
        self.assertEqual(len(version_ids), 3)

        response = self.client.get("/admin/tests/person/%s/history/" %
                                   self.person.pk)
        #        debug_response(response) # from django-tools
        self.assertContainsHtml(
            response,
            '<input type="submit" value="compare">',
            '<input type="radio" name="version_id1" value="%i" style="visibility:hidden" />'
            % version_ids[0],
            '<input type="radio" name="version_id2" value="%i" checked="checked" />'
            % version_ids[0],
            '<input type="radio" name="version_id1" value="%i" checked="checked" />'
            % version_ids[1],
            '<input type="radio" name="version_id2" value="%i" />' %
            version_ids[1],
            '<input type="radio" name="version_id2" value="%i" />' %
            version_ids[2],
            '<input type="radio" name="version_id2" value="%i" />' %
            version_ids[2],
        )

        response = self.client.get("/admin/tests/person/%s/history/compare/" %
                                   self.person.pk,
                                   data={
                                       "version_id2": version_ids[0],
                                       "version_id1": version_ids[1]
                                   })
        #        debug_response(response) # from django-tools

        self.assertContainsHtml(
            response,
            '''
            <p><pre class="highlight">
            <del>- Dave</del>
            <ins>+ David</ins>
            </pre></p>
            ''',
            "<blockquote>version 3: change the name</blockquote>",  # edit comment
        )
        self.assertNotContainsHtml(
            response,
            "pet",
            'class="follow"'  # All fields are under reversion control
        )
    def test_textfield(self):
        with reversion_api.create_revision():
            item = VariantModel.objects.create(text="""\
first line
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
last line""")
            item.save()

        with reversion_api.create_revision():
            item.text = """\
first line
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis added aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
last line"""
            item.save()

        # debug_response(self.client.get("/admin/tests/variantmodel/1/history/"))
        response = self.client.get(
            "/admin/tests/variantmodel/1/history/compare/",
            data={
                "version_id2": 1,
                "version_id1": 2
            })
        # debug_response(response) # from django-tools

        self.assertContains(
            response, """\
<del>-nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit</del>
<ins>+nisi ut aliquip ex ea commodo consequat. Duis added aute irure dolor in reprehenderit in voluptate velit</ins>
""")
        self.assertNotContains(response, "first line")
        self.assertNotContains(response, "last line")
    def test_textfield(self):
        with reversion_api.create_revision():
            item = VariantModel.objects.create(
                text="""\
first line
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
last line"""
            )
            item.save()

        with reversion_api.create_revision():
            item.text = """\
first line
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut
labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis added aute irure dolor in reprehenderit in voluptate velit
esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
culpa qui officia deserunt mollit anim id est laborum.
last line"""
            item.save()

        # debug_response(self.client.get("/admin/tests/variantmodel/1/history/"))
        response = self.client.get(
            "/admin/tests/variantmodel/1/history/compare/",
            data={"version_id2": 1, "version_id1": 2}
        )
        # debug_response(response) # from django-tools

        self.assertContains(response, """\
<del>-nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit</del>
<ins>+nisi ut aliquip ex ea commodo consequat. Duis added aute irure dolor in reprehenderit in voluptate velit</ins>
""")
        self.assertNotContains(response, "first line")
        self.assertNotContains(response, "last line")
 def test_version_selection(self):
     "Generate two revisions and view the version history selection."
     with reversion_api.create_revision():
         self.item.text = "version two"
         self.item.save()
     with reversion_api.create_revision():
         self.item.text = "version three"
         self.item.save()
     queryset = custom_revision_manager.get_for_object(self.item)
     version_ids = queryset.values_list("pk", flat=True)
     self.assertEqual(len(version_ids), 3)
     url_name = 'admin:%s_%s_history' % (CustomModel._meta.app_label, CustomModel._meta.model_name)
     history_url = reverse(url_name, args=(self.item.pk, ))
     response = self.client.get(history_url)
     self.assertContainsHtml(response,
         '<input type="submit" value="compare">',
         '<input type="radio" name="version_id1" value="%i" style="visibility:hidden" />' % version_ids[0],
         '<input type="radio" name="version_id2" value="%i" checked="checked" />' % version_ids[0],
         '<input type="radio" name="version_id1" value="%i" checked="checked" />' % version_ids[1],
         '<input type="radio" name="version_id2" value="%i" />' % version_ids[1],
         '<input type="radio" name="version_id1" value="%i" />' % version_ids[2],
         '<input type="radio" name="version_id2" value="%i" />' % version_ids[2],
     )
예제 #15
0
 def test_text_diff(self):
     """"Generate a new revision and check for a correctly generated diff."""
     with reversion_api.create_revision():
         self.item.text = "version two"
         self.item.save()
     queryset = reversion_api.get_for_object(self.item)
     version_ids = queryset.values_list("pk", flat=True)
     self.assertEqual(len(version_ids), 2)
     url_name = 'admin:%s_%s_compare' % (CustomModel._meta.app_label, CustomModel._meta.model_name)
     diff_url = reverse(url_name, args=(self.item.pk, ))
     data = {"version_id2": version_ids[0], "version_id1": version_ids[1]}
     response = self.client.get(diff_url, data=data)
     self.assertContains(response, "<del>- version one</del>")
     self.assertContains(response, "<ins>+ version two</ins>")
 def test_text_diff(self):
     "Generate a new revision and check for a correctly generated diff."
     with reversion_api.create_revision():
         self.item.text = "version two"
         self.item.save()
     queryset = custom_revision_manager.get_for_object(self.item)
     version_ids = queryset.values_list("pk", flat=True)
     self.assertEqual(len(version_ids), 2)
     url_name = 'admin:%s_%s_compare' % (CustomModel._meta.app_label, CustomModel._meta.model_name)
     diff_url = reverse(url_name, args=(self.item.pk, ))
     data = {"version_id2": version_ids[0], "version_id1": version_ids[1]}
     response = self.client.get(diff_url, data=data)
     self.assertContains(response, "<del>- version one</del>")
     self.assertContains(response, "<ins>+ version two</ins>")
    def create_PersonPet_data(self):
        with reversion_api.create_revision():
            pet1 = Pet.objects.create(name="would be changed pet")
            pet2 = Pet.objects.create(name="would be deleted pet")
            pet3 = Pet.objects.create(name="would be removed pet")
            pet4 = Pet.objects.create(name="always the same pet")
            person = Person.objects.create(name="Dave")
            person.pets.add(pet1, pet2, pet3, pet4)
            person.save()
            reversion_api.set_comment("initial version 1")

        if self.verbose:
            print("version 1:", person, person.pets.all())
            # Dave [<Pet: would be changed pet>, <Pet: would be deleted pet>, <Pet: would be removed pet>, <Pet: always the same pet>]

        """ 1 to 2 diff:

        "pets" ManyToManyField:
            would be changed pet -> Is changed pet
            - would be removed pet
            - would be deleted pet
            = always the same pet
        """

        with reversion_api.create_revision():
            pet1.name = "Is changed pet"
            pet1.save()
            pet2.delete()
            person.pets.remove(pet3)
            person.save()
            reversion_api.set_comment("version 2: change follow related pets.")

        if self.verbose:
            print("version 2:", person, person.pets.all())
            # Dave [<Pet: Is changed pet>, <Pet: always the same pet>]

        return pet1, pet2, person
예제 #18
0
    def create_PersonPet_data(self):
        with reversion_api.create_revision():
            pet1 = Pet.objects.create(name="would be changed pet")
            pet2 = Pet.objects.create(name="would be deleted pet")
            pet3 = Pet.objects.create(name="would be removed pet")
            pet4 = Pet.objects.create(name="always the same pet")
            person = Person.objects.create(name="Dave")
            person.pets.add(pet1, pet2, pet3, pet4)
            person.save()
            reversion_api.set_comment("initial version 1")

        if self.verbose:
            print("version 1:", person, person.pets.all())
            # Dave [<Pet: would be changed pet>, <Pet: would be deleted pet>, <Pet: would be removed pet>, <Pet: always the same pet>]

        """ 1 to 2 diff:

        "pets" ManyToManyField:
            would be changed pet -> Is changed pet
            - would be removed pet
            - would be deleted pet
            = always the same pet
        """

        with reversion_api.create_revision():
            pet1.name = "Is changed pet"
            pet1.save()
            pet2.delete()
            person.pets.remove(pet3)
            person.save()
            reversion_api.set_comment("version 2: change follow related pets.")

        if self.verbose:
            print("version 2:", person, person.pets.all())
            # Dave [<Pet: Is changed pet>, <Pet: always the same pet>]

        return pet1, pet2, person
    def test_add_m2m(self):
        with reversion_api.create_revision():
            new_pet = Pet.objects.create(name="added pet")
            self.person.pets.add(new_pet)
            self.person.save()
            reversion_api.set_comment("version 3: add a pet")

        self.assertEqual(reversion_api.Revision.objects.all().count(), 3)
        self.assertEqual(reversion_api.Version.objects.all().count(), 12)

        queryset = reversion_api.get_for_object(self.person)
        version_ids = queryset.values_list("pk", flat=True)
        self.assertEqual(len(version_ids), 3)

        response = self.client.get("/admin/tests/person/%s/history/" % self.person.pk)
#        debug_response(response) # from django-tools
        self.assertContainsHtml(response,
            '<input type="submit" value="compare">',
            '<input type="radio" name="version_id1" value="%i" style="visibility:hidden" />' % version_ids[0],
            '<input type="radio" name="version_id2" value="%i" checked="checked" />' % version_ids[0],
            '<input type="radio" name="version_id1" value="%i" checked="checked" />' % version_ids[1],
            '<input type="radio" name="version_id2" value="%i" />' % version_ids[1],
            '<input type="radio" name="version_id2" value="%i" />' % version_ids[2],
            '<input type="radio" name="version_id2" value="%i" />' % version_ids[2],
        )

        response = self.client.get(
            "/admin/tests/person/%s/history/compare/" % self.person.pk,
            data={"version_id2":version_ids[0], "version_id1":version_ids[1]}
        )
#        debug_response(response) # from django-tools

        self.assertContainsHtml(response,
            """
            <p class="highlight">
                <ins>+ added pet</ins><br />
                Is changed pet<br />
                always the same pet<br />
            </p>
            """,
            "<blockquote>version 3: add a pet</blockquote>", # edit comment
        )
        self.assertNotContainsHtml(response,
            "<h3>name</h3>", # person name doesn't changed
            'class="follow"'# All fields are under reversion control
        )
    def test_m2m_not_changed(self):
        with reversion_api.create_revision():
            self.person.name = "David"
            self.person.save()
            reversion_api.set_comment("version 3: change the name")

        self.assertEqual(reversion_api.Revision.objects.all().count(), 3)
        self.assertEqual(reversion_api.Version.objects.all().count(), 11)

        queryset = reversion_api.get_for_object(self.person)
        version_ids = queryset.values_list("pk", flat=True)
        self.assertEqual(len(version_ids), 3)

        response = self.client.get("/admin/tests/person/%s/history/" % self.person.pk)
#        debug_response(response) # from django-tools
        self.assertContainsHtml(response,
            '<input type="submit" value="compare">',
            '<input type="radio" name="version_id1" value="%i" style="visibility:hidden" />' % version_ids[0],
            '<input type="radio" name="version_id2" value="%i" checked="checked" />' % version_ids[0],
            '<input type="radio" name="version_id1" value="%i" checked="checked" />' % version_ids[1],
            '<input type="radio" name="version_id2" value="%i" />' % version_ids[1],
            '<input type="radio" name="version_id2" value="%i" />' % version_ids[2],
            '<input type="radio" name="version_id2" value="%i" />' % version_ids[2],
        )

        response = self.client.get(
            "/admin/tests/person/%s/history/compare/" % self.person.pk,
            data={"version_id2":version_ids[0], "version_id1":version_ids[1]}
        )
#        debug_response(response) # from django-tools

        self.assertContainsHtml(response,
            '''
            <p><pre class="highlight">
            <del>- Dave</del>
            <ins>+ David</ins>
            </pre></p>
            ''',
            "<blockquote>version 3: change the name</blockquote>", # edit comment
        )
        self.assertNotContainsHtml(response,
            "pet",
            'class="follow"'# All fields are under reversion control
        )
예제 #21
0
    def create_FactoryCar_data(self):
        with reversion_api.create_revision():
            manufacture = Factory.objects.create(name="factory one",
                                                 address="1 Fake Plaza")
            supplier1 = Factory.objects.create(name="always the same supplier",
                                               address="1 Fake Plaza")
            supplier2 = Factory.objects.create(
                name="would be deleted supplier", address="1 Fake Plaza")
            supplier3 = Factory.objects.create(
                name="would be removed supplier", address="1 Fake Plaza")
            car = Car.objects.create(name="motor-car one",
                                     manufacturer=manufacture)
            car.supplier.add(supplier1, supplier2, supplier3)
            car.save()
            reversion_api.set_comment("initial version 1")

        if self.verbose:
            print("version 1:", car)
            # motor-car one from factory one supplier(s): always the same supplier, would be deleted supplier, would be removed supplier
        """ 1 to 2 diff:

        "manufacture" ForeignKey:
            "factory one" -> "factory I"

        "supplier" ManyToManyField:
            + new, would be renamed supplier
            - would be deleted supplier
            - would be removed supplier
            = always the same supplier
        """

        with reversion_api.create_revision():
            manufacture.name = "factory I"
            manufacture.save()
            supplier2.delete()  # - would be deleted supplier
            supplier4 = Factory.objects.create(
                name="new, would be renamed supplier", address="1 Fake Plaza")
            car.supplier.add(supplier4)  # + new, would be renamed supplier
            car.supplier.remove(supplier3)  # - would be removed supplier
            car.save()
            reversion_api.set_comment(
                "version 2: change ForeignKey and ManyToManyField.")

        if self.verbose:
            print("version 2:", car)
            # motor-car one from factory I supplier(s): always the same supplier, new, would be renamed supplier
        """ 2 to 3 diff:

        "name" CharField:
            "motor-car one" -> "motor-car II"

        "manufacture" ForeignKey:
            "factory I" -> "factory II"

        "supplier" ManyToManyField:
            new, would be renamed supplier -> not new anymore supplier
            = always the same supplier
        """

        with reversion_api.create_revision():
            car.name = "motor-car II"
            manufacture.name = "factory II"
            supplier4.name = "not new anymore supplier"
            supplier4.save()
            car.save()
            reversion_api.set_comment(
                "version 3: change CharField, ForeignKey and ManyToManyField.")

        if self.verbose:
            print("version 3:", car)
            # version 3: motor-car II from factory II supplier(s): always the same supplier, not new anymore supplier

        return car
예제 #22
0
    def create_Factory_reverse_relation_data(self):
        from django.db import transaction

        with transaction.atomic(), reversion_api.create_revision():
            manufacturer = Factory.objects.create(name="factory one",
                                                  address="1 Fake Plaza")
            different_manufacturer = Factory.objects.create(
                name="factory two", address="1 Fake Plaza")
            car1 = Car.objects.create(name="motor-car one",
                                      manufacturer=manufacturer)
            car2 = Car.objects.create(name="motor-car two",
                                      manufacturer=manufacturer)
            car3 = Car.objects.create(name="motor-car three",
                                      manufacturer=manufacturer)
            car1.save()
            car2.save()
            car3.save()
            manufacturer.save()
            reversion_api.set_comment("initial version 1")

        if self.verbose:
            print("version 1:", manufacturer)
            # Factory One
        """ 1 to 2 diff:

        "manufacture" ForeignKey:
            "factory one" -> "factory I"

        "supplier" ManyToManyField:
            + new, would be renamed supplier
            - would be deleted supplier
            - would be removed supplier
            = always the same supplier
        """

        with transaction.atomic(), reversion_api.create_revision():
            car3.delete()
            car4 = Car.objects.create(name="motor-car four",
                                      manufacturer=manufacturer)
            car4.save()

            worker1 = Person.objects.create(name="Bob Bobertson",
                                            workplace=manufacturer)

            manufacturer.save()
            reversion_api.set_comment(
                "version 2: discontinued car-three, add car-four, add Bob the worker"
            )

        if self.verbose:
            print("version 2:", manufacturer)
            # motor-car one from factory I supplier(s): always the same supplier, new, would be renamed supplier
        """ 2 to 3 diff:

        "name" CharField:
            "motor-car one" -> "motor-car II"

        "manufacture" ForeignKey:
            "factory I" -> "factory II"

        "supplier" ManyToManyField:
            new, would be renamed supplier -> not new anymore supplier
            = always the same supplier
        """

        with transaction.atomic(), reversion_api.create_revision():
            car2.manufacturer = different_manufacturer
            car2.save()
            manufacturer.save()
            reversion_api.set_comment(
                "version 3: car2 now built by someone else.")

        if self.verbose:
            print("version 3:", manufacturer)
            # version 3: motor-car II from factory II supplier(s): always the same supplier, not new anymore supplier

        return manufacturer
예제 #23
0
    def create_VariantModel_data(self):
        with reversion_api.create_revision():
            item = VariantModel.objects.create(
                boolean = False,
                null_boolean = None,

                char = "a",
                text = "Foo 'one'",
                # skip: models.SlugField()

                integer = 0,
                integers = "1,2,3", # CommaSeparatedIntegerField
                positive_integer = 1,
                big_integer = (-BigIntegerField.MAX_BIGINT - 1),
                # skip:
                # models.PositiveSmallIntegerField()
                # models.SmallIntegerField()

                time = datetime.time(hour=20, minute=15),
                date = datetime.date(year=1941, month=5, day=12), # Z3 was presented in germany ;)
                # PyLucid v0.0.1 release date:
                datetime = datetime.datetime(year=2005, month=8, day=19, hour=8, minute=13, second=24),

                decimal = Decimal('1.23456789'),
                float = 2.345,

                email = "*****@*****.**",
                url = "http://www.pylucid.org/",

                filepath = os.path.join(settings.UNITTEST_TEMP_PATH, "foo"),

                ip_address = "192.168.0.1",
                # skip: models.GenericIPAddressField()
            )
            reversion_api.set_comment("initial version")

        test_data = (
            ("boolean", True),
            ("null_boolean", True),
            ("null_boolean", False),
            ("char", "B"),
            ("text", "Bar 'two'"),
            # skip: models.SlugField()
            ("integer", -1),
            ("integers", "2,3,4"), # CommaSeparatedIntegerField
            ("positive_integer", 3),
            ("big_integer", BigIntegerField.MAX_BIGINT),
            # models.PositiveSmallIntegerField()
            # models.SmallIntegerField()
            ("time", datetime.time(hour=19, minute=30)),
            ("date", datetime.date(year=2099, month=12, day=31)),
            ("datetime", datetime.datetime(year=2000, month=1, day=1, hour=0, minute=0, second=1)),
            ("decimal", Decimal('3.1415926535')),
            ("float", 3.1415),
            ("email", "*****@*****.**"),
            ("url", "https://github.com/jedie/"),
            ("filepath", os.path.join(settings.UNITTEST_TEMP_PATH, "bar")),
            ("ip_address", "10.0.0.0"),
        )
        for no, (field_name, value) in enumerate(test_data):
            with reversion_api.create_revision():
                setattr(item, field_name, value)
                item.save()
                reversion_api.set_comment("%i change: %r field." % (no, field_name))

        return item, test_data
예제 #24
0
    def create_Factory_reverse_relation_data(self):
        from django.db import transaction

        with transaction.atomic(), reversion_api.create_revision():
            manufacturer = Factory.objects.create(name="factory one", address="1 Fake Plaza")
            different_manufacturer = Factory.objects.create(name="factory two", address="1 Fake Plaza")
            car1 = Car.objects.create(
                name="motor-car one",
                manufacturer=manufacturer
            )
            car2 = Car.objects.create(
                name="motor-car two",
                manufacturer=manufacturer
            )
            car3 = Car.objects.create(
                name="motor-car three",
                manufacturer=manufacturer
            )
            car1.save()
            car2.save()
            car3.save()
            manufacturer.save()
            reversion_api.set_comment("initial version 1")

        if self.verbose:
            print("version 1:", manufacturer)
            # Factory One

        """ 1 to 2 diff:

        "manufacture" ForeignKey:
            "factory one" -> "factory I"

        "supplier" ManyToManyField:
            + new, would be renamed supplier
            - would be deleted supplier
            - would be removed supplier
            = always the same supplier
        """

        with transaction.atomic(), reversion_api.create_revision():
            car3.delete()
            car4 = Car.objects.create(
                name="motor-car four",
                manufacturer=manufacturer
            )
            car4.save()

            worker1 = Person.objects.create(
                name="Bob Bobertson",
                workplace=manufacturer
            )

            manufacturer.save()
            reversion_api.set_comment("version 2: discontinued car-three, add car-four, add Bob the worker")

        if self.verbose:
            print("version 2:", manufacturer)
            # motor-car one from factory I supplier(s): always the same supplier, new, would be renamed supplier

        """ 2 to 3 diff:

        "name" CharField:
            "motor-car one" -> "motor-car II"

        "manufacture" ForeignKey:
            "factory I" -> "factory II"

        "supplier" ManyToManyField:
            new, would be renamed supplier -> not new anymore supplier
            = always the same supplier
        """

        with transaction.atomic(), reversion_api.create_revision():
            car2.manufacturer = different_manufacturer
            car2.save()
            manufacturer.save()
            reversion_api.set_comment("version 3: car2 now built by someone else.")

        if self.verbose:
            print("version 3:", manufacturer)
            # version 3: motor-car II from factory II supplier(s): always the same supplier, not new anymore supplier

        return manufacturer
예제 #25
0
    def create_FactoryCar_data(self):
        with reversion_api.create_revision():
            manufacture = Factory.objects.create(name="factory one", address="1 Fake Plaza")
            supplier1 = Factory.objects.create(name="always the same supplier", address="1 Fake Plaza")
            supplier2 = Factory.objects.create(name="would be deleted supplier", address="1 Fake Plaza")
            supplier3 = Factory.objects.create(name="would be removed supplier", address="1 Fake Plaza")
            car = Car.objects.create(
                name="motor-car one",
                manufacturer=manufacture
            )
            car.supplier.add(supplier1, supplier2, supplier3)
            car.save()
            reversion_api.set_comment("initial version 1")

        if self.verbose:
            print("version 1:", car)
            # motor-car one from factory one supplier(s): always the same supplier, would be deleted supplier, would be removed supplier

        """ 1 to 2 diff:

        "manufacture" ForeignKey:
            "factory one" -> "factory I"

        "supplier" ManyToManyField:
            + new, would be renamed supplier
            - would be deleted supplier
            - would be removed supplier
            = always the same supplier
        """

        with reversion_api.create_revision():
            manufacture.name = "factory I"
            manufacture.save()
            supplier2.delete() # - would be deleted supplier
            supplier4 = Factory.objects.create(name="new, would be renamed supplier", address="1 Fake Plaza")
            car.supplier.add(supplier4) # + new, would be renamed supplier
            car.supplier.remove(supplier3) # - would be removed supplier
            car.save()
            reversion_api.set_comment("version 2: change ForeignKey and ManyToManyField.")

        if self.verbose:
            print("version 2:", car)
            # motor-car one from factory I supplier(s): always the same supplier, new, would be renamed supplier

        """ 2 to 3 diff:

        "name" CharField:
            "motor-car one" -> "motor-car II"

        "manufacture" ForeignKey:
            "factory I" -> "factory II"

        "supplier" ManyToManyField:
            new, would be renamed supplier -> not new anymore supplier
            = always the same supplier
        """

        with reversion_api.create_revision():
            car.name = "motor-car II"
            manufacture.name = "factory II"
            supplier4.name = "not new anymore supplier"
            supplier4.save()
            car.save()
            reversion_api.set_comment("version 3: change CharField, ForeignKey and ManyToManyField.")

        if self.verbose:
            print("version 3:", car)
            # version 3: motor-car II from factory II supplier(s): always the same supplier, not new anymore supplier

        return car
예제 #26
0
    def create_VariantModel_data(self):
        with reversion_api.create_revision():
            item = VariantModel.objects.create(
                boolean=False,
                null_boolean=None,
                char="a",
                text="Foo 'one'",
                # skip: models.SlugField()
                integer=0,
                integers="1,2,3",  # CommaSeparatedIntegerField
                positive_integer=1,
                big_integer=(-BigIntegerField.MAX_BIGINT - 1),
                # skip:
                # models.PositiveSmallIntegerField()
                # models.SmallIntegerField()
                time=datetime.time(hour=20, minute=15),
                date=datetime.date(year=1941, month=5,
                                   day=12),  # Z3 was presented in germany ;)
                # PyLucid v0.0.1 release date:
                datetime=datetime.datetime(year=2005,
                                           month=8,
                                           day=19,
                                           hour=8,
                                           minute=13,
                                           second=24),
                decimal=Decimal('1.23456789'),
                float=2.345,
                email="*****@*****.**",
                url="http://www.pylucid.org/",
                filepath=os.path.join(settings.UNITTEST_TEMP_PATH, "foo"),
                ip_address="192.168.0.1",
                # skip: models.GenericIPAddressField()
            )
            reversion_api.set_comment("initial version")

        test_data = (
            ("boolean", True),
            ("null_boolean", True),
            ("null_boolean", False),
            ("char", "B"),
            ("text", "Bar 'two'"),
            # skip: models.SlugField()
            ("integer", -1),
            ("integers", "2,3,4"),  # CommaSeparatedIntegerField
            ("positive_integer", 3),
            ("big_integer", BigIntegerField.MAX_BIGINT),
            # models.PositiveSmallIntegerField()
            # models.SmallIntegerField()
            ("time", datetime.time(hour=19, minute=30)),
            ("date", datetime.date(year=2099, month=12, day=31)),
            ("datetime",
             datetime.datetime(year=2000,
                               month=1,
                               day=1,
                               hour=0,
                               minute=0,
                               second=1)),
            ("decimal", Decimal('3.1415926535')),
            ("float", 3.1415),
            ("email", "*****@*****.**"),
            ("url", "https://github.com/jedie/"),
            ("filepath", os.path.join(settings.UNITTEST_TEMP_PATH, "bar")),
            ("ip_address", "10.0.0.0"),
        )
        for no, (field_name, value) in enumerate(test_data):
            with reversion_api.create_revision():
                setattr(item, field_name, value)
                item.save()
                reversion_api.set_comment("%i change: %r field." %
                                          (no, field_name))

        return item, test_data