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.")
def test_combine_envelope_contents(self): # Make some pages. p1 = Page() p1.save() p2 = Page() p2.save() p3 = Page() p3.save() p4 = Page() p4.save() # Make a box for them. b = Box() b.save() # Put them in the box. box.add_content( (p1, p2, p3, p4) ) # Make two envelopes and put pages in them. e1 = Envelope() e1.add_content( (p1, p2) ) e2 = Envelope() e2.add_content( (p3, p4) ) # Combine envelope contents. e2.send_contents_to_envelope(e1) self.assertEqual(len(e2.contents.all()), 0, "Some content is still left in sending envelope.") self.assertEqual(len(e1.contents.all()), 4, "Content in receiving envelope is not correct.") for page in [p1, p2, p3, p4]: self.assertTrue(page in e1.get_content(), "Page not found in receiving envelope.")
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.")
def addbox(request): request.session.set_expiry(0) box = Box() location_id = request.POST['sel2'] box.Location = Location.objects.get(id = location_id) box.save() return redirect('admin')
def test_box_descriptor(self): b = Box() self.assertTrue(b.descriptor is None, "Descriptor not initialized to None.") p = Page() p.title = 'Testbox 1' p.data = 'This Page is used as the descriptor for Testbox 1.' p.save() b.descriptor = p b.save() self.assertTrue(b.descriptor == p, "Descriptor not saved.") self.assertTrue(p.describes_box == b, "Descriptor does not point back to box.")
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
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.")
box.name = name box.url = url box.message = message box.save() return simplejson.dumps( {'state': 'success', 'bb': bb, 'object_type':object_type, 'message': message, 'name': name, 'url': url, 'owner': request.user.username, 'pk':str(box.pk), 'box':box.box, 'planet': box.planet, 'modified': True } ) for box in boxes: points = box['points'] planet = str(box['planet']['x'])+','+str(box['planet']['y']) lockedAreas = Box.objects(planet=planet, box__geo_intersects=makeBox(points[0][0], points[0][1], points[2][0], points[2][1]) ) if lockedAreas.count()>0: return simplejson.dumps( {'state': 'error', 'message': 'This area was already locked'} ) b = Box(planet=planet, box=[points], owner=request.user.username, object_type=object_type, url=url, message=message, name=name, bb=bb) b.save() return simplejson.dumps( {'state': 'success', 'bb': bb, 'object_type':object_type, 'message': message, 'name': name, 'url': url, 'owner': request.user.username, 'pk':str(b.pk), 'box':b.box, 'planet': planet } )
def test_new_box(self): b = Box() b.save() self.assertTrue(b.pk > 0, "Box not created.")