def _test_guide_image(self, delete_image = None, delete_tip = None): guide = Guide(title = "What to do in Montreal!", location = "Montreal, Canada", owner = self.account, is_draft = True) guide.save() tip = Tip(title = "this is a tip title", location = "this is a tip location", description = "this is a tip description", guide = guide) tip.save() image = Image(owner = guide.owner, tip = tip, is_uploaded = False) image.save() self.assertEqual(guide.image, None) image.is_uploaded = True image.save() self.assertEqual(guide.image.pk, image.pk) if delete_image: image.delete() elif delete_tip: tip.delete() self.assertEqual(guide.image, None)
def test_guide_tags_as_list(self): guide = Guide(title = "What to do in Montreal!", location = "Montreal, Canada", owner = self.account, is_draft = True) guide.save() tip = Tip(title = "Peel Pub", location = "Peel Street, near McGill campus", guide = guide) tip.save() self.assertEqual(len(guide.tags_as_list), 0) tip.tags.add("pub", "student", "fun") self.assertEqual(len(guide.tags_as_list), 3) self.assertTrue("pub" in [tag.tag for tag in guide.tags_as_list]) self.assertTrue("student" in [tag.tag for tag in guide.tags_as_list]) self.assertTrue("fun" in [tag.tag for tag in guide.tags_as_list]) tip.tags.remove("pub") self.assertEqual(len(guide.tags_as_list), 2) self.assertFalse("pub" in [tag.tag for tag in guide.tags_as_list]) self.assertTrue("student" in [tag.tag for tag in guide.tags_as_list]) self.assertTrue("fun" in [tag.tag for tag in guide.tags_as_list]) tip.tags.clear() self.assertEqual(len(guide.tags_as_list), 0) tip.tags.set("pub", "student", "fun") self.assertEqual(len(guide.tags_as_list), 3) tip.delete() self.assertEqual(len(guide.tags_as_list), 0)
def _test_account_favourite_tips(self, is_public_guide = None, is_draft_guide = None, remove_favourited_tip = None, delete_tip = None, delete_guide = None, toggle_guide_visibility = None): assert(any(guide for guide in [is_public_guide, is_draft_guide])) if is_public_guide: tip = Tip(title = "Peel Pub", location = "Peel Street, near McGill campus", guide = self.guide) elif is_draft_guide: tip = Tip(title = "Peel Pub", location = "Peel Street, near McGill campus", guide = self.draft_guide) tip.save() account = tip.guide.owner print "adding tip" account.add_favourited_tip(tip) if is_public_guide: self.assertTrue(account.has_favourited_tip(tip)) else: self.assertFalse(account.has_favourited_tip(tip)) print "check favourite tips on account" if is_public_guide: self.assertTrue(tip in account.favourite_tips) else: self.assertFalse(tip in account.favourite_tips) if remove_favourited_tip: print "removing tip" account.remove_favourited_tip(tip) elif delete_tip: print "deleting tip" tip.delete() elif delete_guide: print "deleting guide" tip.guide.delete() elif toggle_guide_visibility: print "toggling guide visibility" tip.guide.is_draft = not tip.guide.is_draft tip.guide.save() if is_public_guide: self.assertFalse(tip in account.favourite_tips) elif is_draft_guide and not toggle_guide_visibility: self.assertFalse(tip in account.favourite_tips) elif is_draft_guide and toggle_guide_visibility: self.assertTrue(tip in account.favourite_tips)
def _test_account_get_favourite_tag_generator(self, is_public_guide = None, is_draft_guide = None, tip_before_tags = None, remove_favourited_tip = None, delete_tip = None, delete_guide = None, toggle_guide_visibility = None): assert(any(guide for guide in [is_public_guide, is_draft_guide])) if is_public_guide: tip = Tip(title = "Peel Pub", location = "Peel Street, near McGill campus", guide = self.guide) else: tip = Tip(title = "Peel Pub", location = "Peel Street, near McGill campus", guide = self.draft_guide) tip.save() account = tip.guide.owner if tip_before_tags == True: print "adding tip as favourite" account.add_favourited_tip(tip) print "add tags" tip.tags.add("pub", "student", "fun") else: print "add tags" tip.tags.add("pub", "student", "fun") print "adding tip as favourite" account.add_favourited_tip(tip) print "check favourite tags on account" if is_public_guide: self.assertTrue("pub" in [tag.tag.name for tag in account.get_favourite_tag_generator()]) self.assertTrue("student" in [tag.tag.name for tag in account.get_favourite_tag_generator()]) self.assertTrue("fun" in [tag.tag.name for tag in account.get_favourite_tag_generator()]) else: self.assertFalse("pub" in [tag.tag.name for tag in account.get_favourite_tag_generator()]) self.assertFalse("student" in [tag.tag.name for tag in account.get_favourite_tag_generator()]) self.assertFalse("fun" in [tag.tag.name for tag in account.get_favourite_tag_generator()]) if remove_favourited_tip: print "removing tip" account.remove_favourited_tip(tip) elif delete_tip: print "deleting tip" tip.delete() elif delete_guide: print "deleting guide" self.guide.delete() elif toggle_guide_visibility: print "toggling guide visibility" tip.guide.is_draft = not tip.guide.is_draft tip.guide.save() if is_public_guide: self.assertFalse("pub" in [tag.tag.name for tag in account.get_favourite_tag_generator()]) self.assertFalse("student" in [tag.tag.name for tag in account.get_favourite_tag_generator()]) self.assertFalse("fun" in [tag.tag.name for tag in account.get_favourite_tag_generator()]) elif is_draft_guide and not toggle_guide_visibility: self.assertFalse("pub" in [tag.tag.name for tag in account.get_favourite_tag_generator()]) self.assertFalse("student" in [tag.tag.name for tag in account.get_favourite_tag_generator()]) self.assertFalse("fun" in [tag.tag.name for tag in account.get_favourite_tag_generator()]) elif is_draft_guide and toggle_guide_visibility: self.assertTrue("pub" in [tag.tag.name for tag in account.get_favourite_tag_generator()]) self.assertTrue("student" in [tag.tag.name for tag in account.get_favourite_tag_generator()]) self.assertTrue("fun" in [tag.tag.name for tag in account.get_favourite_tag_generator()])