def get_dependencies(self, instance): ''' Filter the dependencies because contenttype and permission are automagically created by django ''' deps = get_dependencies(instance) if self.exclude_content_type: deps = [d for d in deps if not isinstance( d, (ContentType, Permission))] return deps
def get_objects_with_deps(self): from dev_db.dependencies import get_dependencies objects = self.get_objects() deps = [] for object_ in objects: deps += get_dependencies(object_) objects += deps objects = self.cleanup(objects) return objects
def get_dependencies(self, instance): ''' Filter the dependencies because contenttype and permission are automagically created by django ''' deps = get_dependencies(instance) if self.exclude_content_type: deps = [ d for d in deps if not isinstance(d, (ContentType, Permission)) ] return deps
def test_dependency_lookup_site(self): ''' Expected output is a sorted list like Site Category, Site, User, Entity, Love ''' from core.models import Site, SiteCategory site = Site.objects.all()[:1][0] # check the recursive approach dependencies = get_dependencies(site) correct_deps = [site.category, site] self.assertEqual(correct_deps, dependencies)
def test_dependency_lookup_item(self): ''' Expected output is a sorted list like Site Category, Site, User, Entity, Love ''' from core.models import Item instance = Item.objects.all()[:1][0] # check the recursive approach dependencies = get_dependencies(instance) correct_deps = list(instance.tags.all())[::-1] + [instance.user, instance.site.category, instance.site, instance] self.assertEqual(dependencies, correct_deps)
def test_dependency_lookup_item(self): ''' Expected output is a sorted list like Site Category, Site, User, Entity, Love ''' from core.models import Item instance = Item.objects.all()[:1][0] # check the recursive approach dependencies = get_dependencies(instance) correct_deps = list(instance.tags.all())[::-1] + [ instance.user, instance.site.category, instance.site, instance ] self.assertEqual(dependencies, correct_deps)
def test_recursion(self): from core.models import Post post = Post.objects.get(pk=1) deps = get_dependencies(post) correct_deps = [post, post.blogger, post] self.assertEqual(correct_deps, deps)