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_add_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=[di]) cat.save() tagged = Categories.objects_with("test cat") self.assertEqual(tagged, [di]) cat.add_object(self.loc) tagged = Categories.objects_with("test cat") self.assertEqual(tagged, [di, self.loc]) cat.delete() di.delete()
def test_cats_get_all_tagged_handles_missing(self): tagged = Categories.objects_with("I'm not there") self.assertEqual(tagged, [])