def test_update_categories(self): di = DataImport(name="junk", duplicate_content="no", last_updated=datetime.datetime.now(), upload_format="csv", upload_type="1") di.save() cat = Categories(name="test cat") cat.save() cat2 = Categories(name="test cat2") cat2.save() cat_list = "%s,%s" % (str(cat.id), str(cat2.id)) self.assertEqual(0, len(Categories.objects_with("test cat"))) self.assertEqual(0, len(Categories.objects_with("test cat2"))) self.assertEqual(0, len(Categories.for_object(di))) update_categories(di, cat_list) self.assertEqual(1, len(Categories.objects_with("test cat"))) self.assertEqual(1, len(Categories.objects_with("test cat2"))) self.assertEqual(2, len(Categories.for_object(di))) self.assertEqual("test cat", Categories.for_object(di)[0].name) self.assertEqual("test cat2", Categories.for_object(di)[1].name) di.delete() cat.delete() cat2.delete()
def test_update_categories_work_with_invalid_category(self): di = DataImport(name="junk", duplicate_content="no", last_updated=datetime.datetime.now(), upload_format="csv", upload_type="1") di.save() cat = Categories(name="test cat") cat.save() cat_list = "i'm not a category,56485cb53f3aaaaaaaaaaaaa, %s" % (str( cat.id)) self.assertEqual(0, len(Categories.objects_with("test cat"))) self.assertEqual(0, len(Categories.for_object(di))) update_categories(di, cat_list) self.assertEqual(1, len(Categories.objects_with("test cat"))) self.assertEqual(1, len(Categories.for_object(di))) self.assertEqual("test cat", Categories.for_object(di)[0].name) di.delete() cat.delete()
def test_cats_tagged_holds_anything(self): di = DataImport(name="junk", duplicate_content="no", last_updated=datetime.now(), upload_format="csv", upload_type="1") di.save() cat = Categories(name="test cat", tagged=[self.loc, di]) cat.save() self.assertEqual(2, cat.number_using) cat.delete() di.delete()
def test_cats_for_obj_id(self): di = DataImport(name="junk", duplicate_content="no", last_updated=datetime.now(), upload_format="csv", upload_type="1") di.save() cat = Categories(name="test cat", tagged=[self.loc, di]) cat.save() found_cats = Categories.for_object_id(str(di.id), "DataImport") self.assertEqual(1, len(found_cats)) cat.delete() di.delete()
def test_for_object(self): di = DataImport(name="junk", duplicate_content="no", last_updated=datetime.now(), upload_format="csv", upload_type="1") di.save() cat = Categories(name="test cat", tagged=[self.loc, di]) cat.save() self.assertEqual(cat.name, Categories.for_object(di)[0].name) self.assertEqual(1, len(Categories.for_object(di))) self.assertEqual(cat.name, Categories.for_object(self.loc)[0].name) self.assertEqual(1, len(Categories.for_object(self.loc))) cat.delete() di.delete()
def test_cats_get_all_tagged(self): di = DataImport(name="junk", duplicate_content="no", last_updated=datetime.now(), upload_format="csv", upload_type="1") di.save() cat = Categories(name="test cat1", tagged=[self.loc, di]) cat.save() tagged = Categories.objects_with("test cat1") self.assertEqual(tagged, [self.loc, di]) cat.delete() di.delete()
def test_location_get_tags(self): for l in Location.objects.filter(name="loc-with-cat2"): l.delete() loc = Location(name="loc-with-cat2") loc.save() cat = Categories(name="food-test2", tagged=[loc]) cat.save() self.assertIn(cat, loc.tags) self.assertEqual(1, len(loc.tags)) loc.delete() cat.delete() pass
def test_remove_obj(self): di = DataImport(name="junk", duplicate_content="no", last_updated=datetime.now(), upload_format="csv", upload_type="1") di.save() cat = Categories(name="test cat", tagged=[self.loc, di]) cat.save() cat2 = Categories(name="garfield", tagged=[self.loc]) cat2.save() self.assertEqual(2, len(Categories.for_object(self.loc))) Categories.remove_obj(self.loc) self.assertEqual(0, len(Categories.for_object(self.loc))) di.delete() cat.delete() cat2.delete()
def test_cats_number_using(self): cat = Categories(name="test cat", tagged=[self.loc]) cat.save() self.assertEqual(1, cat.number_using) cat.delete()