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_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_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 members_location_view(request, id): from maps.categories.models import Categories data['role'] = role data['object'] = Location.objects.get(id=id) data['owner'] = data['object'].created_by data['user'] = request.user try: data['frontforms'] = data['object'].frontend_form()[0]['field_groups'] except IndexError: print('Location has no frontend forms') data['categories'] = Categories.for_object(data['object']) return render_to_response('homepage/members-location.html', data, context_instance=RequestContext(request))