Exemple #1
0
    def test_box_timeline(self):
        if not settings.BOX_USES_TIMELINE: return
        # What is the latest time, before we start?
        start = self._get_latest_time()

        # @ Time 1: Create empty box.
        b = Box()
        b.save()
        box_created = self._get_latest_time()
        self.assertTrue( (box_created > start),
                         "Timeline not advanced on box creation." )

        # @ Time 2: Add pages to box.
        b.add_content( [p1, p2] )
        pages_added = self._get_latest_time()
        self.assertTrue( (pages_added > box_created),
                         "Timeline not advanced on content addition." )

        # @ Time 4: Remove page 1 from box.
        b.remove_content(p1)
        page_removed = self._get_latest_time()
        self.assertTrue( (page_removed > pages_added),
                         "Timeline not advanced on content removal." )

        # Verify that box contains one page at the present time.
        self.assertEqual(len(b.contents.all()), 1,
                         "Box contents at present time not correct.")

        # View box pages @ time 2 again.
        way_back_when = b.contents.filter(added__lte=pages_added,
                                          removed__gt=pages_added)
        self.assertEqual(len(way_back_when), 2,
                         "Box contents at prior time not correct.")
Exemple #2
0
    def test_move_contents_together(self):
        # Make some test pages.
        p1 = Page()
        p1.title = 'Test Page 1'
        p1.save()
        p2 = Page()
        p2.title = 'Test Page 2'
        p2.save()

        # Make two test boxes.
        b1 = Box()
        b1.save()
        b2 = Box()
        b2.save()

        # Put two pages in box 1.
        b1.add_content( (p1, p2) )

        # Put two pages in the same box into an envelope.
        e.add_content( (p1, p2) )

        # Move the envelope to box 2.
        e.move_to_box(b2)

        self.assertFalse(b1.contains_content(p1), "Page 1 did not leave box 1.")
        self.assertFalse(b1.contains_content(p2), "Page 2 did not leave box 1.")
        self.assertTrue(b2.contains_content(p1), "Page 1 did not move to box 2.")
        self.assertTrue(b2.contains_content(p2), "Page 2 did not move to box 2.")
Exemple #3
0
    def test_envelope_integrity(self):
        """ Contents in an envelope must move from box to box together. """
        # Make some test pages.
        p1 = Page()
        p1.title = 'Test Page 1'
        p1.save()
        p2 = Page()
        p2.title = 'Test Page 2'
        p2.save()
        p3 = Page()
        p3.title = 'Test Page 3'
        p3.save()

        # Make two test boxes.
        b1 = Box()
        b1.save()
        b2 = Box()
        b2.save()

        # Put two pages in box 1.
        b1.add_content(p1)
        b1.add_content(p2)

        # Put the last page in box 2.
        b2.add_content(p3)

        # Put two pages in the same box into an envelope.
        e.add_content(p1)
        e.add_content(p2)

        # Try to put the last page (which is in a different box) into the envelope.
        try:
            e.add_content(p3)
            self.fail("Envelope allowed content from multiple boxes.")
        except EnvelopeIntegrityError:
            # It should have gotten this exception, if it's working right.
            pass

        # Try to take a page out of a box without the other pages in the envelope.
        try:
            b1.remove_content(p1)
            self.fail("Envelope allowed content to be removed from box by itself.")
        except EnvelopeIntegrityError:
            # It should have gotten this exception, if it's working right.
            pass
Exemple #4
0
    def test_box_contents(self):
        b = Box()
        b.save()
        self.assertEqual(len(b.contents.all()), 0, "Box should start out empty.")

        p1 = Page()
        p1.title = 'Test Page 1'
        b.add_content(p1)
        p2 = Page()
        p2.title = 'Test Page 2'
        b.add_content(p2)
        self.assertTrue(b.contains_content(p1), "Page 1 not found in box.")
        self.assertTrue(b.contains_content(p2), "Page 2 not found in box.")

        b.remove_content(p1)
        self.assertFalse(b.contains_content(p1), "Page 1 not removed from box.")
        b.remove_content(p2)
        self.assertFalse(b.contains_content(p2), "Page 2 not removed from box.")

        self.assertEqual(len(b.contents.all()), 0, "Box should now be empty.")