def setUp(self): blog = Blog(name='Databases') blog.save() self.blogs = [blog] authors = ('John Smith', 'Jane Doe', 'Joe Plummer') headlines = ('MySQL is a relational DB', 'Postgres is a really good relational DB', 'Neo4J is a graph DB') self.entries = [ Entry(headline=headline, blog=blog) for headline in headlines ] for entry in self.entries: entry.save() self.authors = [Author(name=name) for name in authors] for author in self.authors: author.save() for i, entry in enumerate(self.entries): entry.authors.add(self.authors[i]) entry.authors.add(self.authors[(i + 1) % len(self.authors)]) model_registry.register(curious_tests.models) model_registry.get_manager('Blog').allowed_relationships = ['authors']
def setUp(self): blog = Blog(name="Databases") blog.save() self.blogs = [blog] headlines = ("MySQL is a relational DB", "Postgres is a really good relational DB", "Neo4J is a graph DB") self.entries = [Entry(headline=headline, blog=blog) for headline in headlines] for entry in self.entries: entry.save() blog = Blog(name="Graph Databases") blog.save() self.blogs.append(blog) entry = Entry(headline="Graph databases store edges with data", blog=blog) entry.save() self.entries.append(entry)
def setUp(self): blog = Blog(name='Databases') blog.save() self.blogs = [blog] authors = ('John Smith', 'Jane Doe', 'Joe Plummer') comments = ('Ok', 'Believe it', "Sounds right") headlines = ('MySQL is a relational DB', 'Postgres is a really good relational DB', 'Neo4J is a graph DB') self.entries = [ Entry(headline=headline, blog=blog) for headline in headlines ] for entry in self.entries: entry.save() self.authors = [Author(name=name) for name in authors] for author in self.authors: author.save() self.comments = [ Comment(comment=comment, entry=entry) for comment, entry in zip(comments, self.entries) ] for comment in self.comments: comment.save() for i, entry in enumerate(self.entries): entry.authors.add(self.authors[i]) entry.authors.add(self.authors[(i + 1) % len(self.authors)]) model_registry.register(curious_tests.models)
def test_recursive_traversal_does_not_get_stuck_in_loop(self): blog = Blog(name='Weird CS Terms') blog.save() headlines = ('Foo', 'Bar', 'Baz', 'Faz') entries = [ Entry(headline=headline, blog=blog) for headline in headlines ] for entry in entries: entry.save() entries[1].response_to = entries[0] entries[1].save() entries[2].response_to = entries[1] entries[2].save() entries[3].response_to = entries[2] entries[3].save() entries[0].response_to = entries[3] entries[0].save() qs = 'Entry(id__in=[%s]) Entry.responses*' % (entries[0].id, ) query = Query(qs) result = query() self.assertEquals(result[0][0][1], -1) assertQueryResultsEqual(self, result[0][0][0], [ (entries[0], None), (entries[1], None), (entries[2], None), (entries[3], None), ]) self.assertEquals(result[1], Entry)
def test_recursive_traversal_on_same_model_from_multiple_objects(self): blog = Blog(name='Weird CS Terms') blog.save() headlines = ('Foo', 'Bar', 'Baz', 'Faz') entries = [ Entry(headline=headline, blog=blog) for headline in headlines ] for entry in entries: entry.save() entries[1].response_to = entries[0] entries[1].save() entries[2].response_to = entries[1] entries[2].save() entries[3].response_to = entries[2] entries[3].save() qs = 'Entry(id__in=[%s,%s]) Entry.responses*' % (self.entries[0].id, entries[0].id) query = Query(qs) result = query() self.assertEquals(result[0][0][1], -1) assertQueryResultsEqual(self, result[0][0][0], [ (self.entries[0], None), (self.entries[1], None), (self.entries[2], None), (self.entries[3], None), (entries[0], None), (entries[1], None), (entries[2], None), (entries[3], None), ]) self.assertEquals(result[1], Entry)
def setUp(self): blog = Blog(name='Databases') blog.save() self.blogs = [blog] headlines = ('MySQL is a relational DB', 'Postgres is a really good relational DB', 'Neo4J is a graph DB') self.entries = [Entry(headline=headline, blog=blog) for headline in headlines] for entry in self.entries: entry.save() blog = Blog(name='Graph Databases') blog.save() self.blogs.append(blog) entry = Entry(headline='Graph databases store edges with data', blog=blog) entry.save() self.entries.append(entry)
def setUp(self): blog = Blog(name='Databases') blog.save() self.blog = blog headlines = ['MySQL is a relational DB']*TestQueryAPI.N self.entries = [Entry(headline=headline, blog=blog) for i, headline in enumerate(headlines)] for entry in self.entries: entry.save() # register model model_registry.register(curious_tests.models)
def setUp(self): blog = Blog(name='Databases') blog.save() self.blog = blog headlines = ['MySQL is a relational DB']*TestBatchFetch.N self.entries = [Entry(headline=headline, blog=blog) for i, headline in enumerate(headlines)] for entry in self.entries: entry.save() # register model model_registry.register(curious_tests.models) model_registry.get_manager('Blog').allowed_relationships = ['authors']
def setUp(self): self.blogs = [Blog(name='A'), Blog(name='C'), Blog(name='B')] for b in self.blogs: b.save() headlines = ('A entry', 'C entry', 'B entry') self.entries = [ Entry(headline=headline, blog=self.blogs[i]) for i, headline in enumerate(headlines) ] for entry in self.entries: entry.save() model_registry.register(curious_tests.models)
def setUp(self): blog = Blog(name='Databases') blog.save() self.blogs = [blog] headlines = ('MySQL is a relational DB', 'Postgres is a really good relational DB', 'Neo4J is a graph DB') self.entries = [ Entry(headline=headline, blog=blog) for headline in headlines ] for entry in self.entries: entry.save() self.query_count = len(connection.queries)
def setUp(self): self.blogs = [Blog(name='Databases'), Blog(name='More Databases')] for blog in self.blogs: blog.save() authors = ['John Smith']*TestQueryCount.N headlines = ['MySQL is a relational DB']*TestQueryCount.N self.entries = [Entry(headline=headline, blog=self.blogs[i%2]) for i, headline in enumerate(headlines)] for entry in self.entries: entry.save() self.authors = [Author(name=name) for name in authors] for author in self.authors: author.save() for i, entry in enumerate(self.entries): entry.authors.add(self.authors[i]) entry.authors.add(self.authors[(i+1)%len(self.authors)])
def setUp(self): blog = Blog(name='Databases') blog.save() self.blog = blog authors = ('John Smith', 'Jane Doe', 'Joe Plummer', 'Jessical Jones') headlines = ('MySQL is a good relational DB', 'Postgres is a really good relational DB', 'Neo4J is a graph DB', 'But we are not comparing relational and graph DBs') self.entries = [ Entry(headline=headline, blog=blog) for headline in headlines ] for entry in self.entries: entry.save() self.entries[1].response_to = self.entries[0] self.entries[1].save() self.entries[2].response_to = self.entries[1] self.entries[2].save() self.entries[3].response_to = self.entries[2] self.entries[3].save() self.authors = [Author(name=name, age=30) for name in authors] for i, author in enumerate(self.authors): author.save() for i, entry in enumerate(self.entries): entry.authors.add(self.authors[i]) model_registry.register(curious_tests.models) qs = 'Blog(%s) Blog.entry_set(headline__icontains="MySQL")' % self.blog.pk query = Query(qs) result = query() self.assertEquals(result[0][0][1], -1) assertQueryResultsEqual(self, result[0][0][0], [(self.entries[0], None)]) self.assertEquals(result[1], Entry)
def setUp(self): self.blog = Blog(name='Databases') self.blog.save() self.entries = [ Entry(headline='Abc {}'.format(i), blog=self.blog) for i in xrange(self.N) ] for index, entry in enumerate(self.entries): if index < len(self.entries) - 1: entry.related_blog_id = self.entries[index + 1].pk for entry in self.entries: entry.save() self.query_count = len(connection.queries) model_registry.register(curious_tests.models) Blog.entry_ = remote_fk('entry_id', Entry) Entry.related_blog_ = remote_fk('related_blog_id', Entry) model_registry.get_manager('Entry').allowed_relationships = [ 'related_blog_', ]
def setUp(self): blog = Blog(name='Databases') blog.save() self.blogs = [blog] authors = ('John Smith', 'Jane Doe', 'Joe Plummer') headlines = ('MySQL is a relational DB', 'Postgres is a really good relational DB', 'Neo4J is a graph DB') self.entries = [ Entry(headline=headline, blog=blog) for headline in headlines ] for entry in self.entries: entry.save() self.authors = [Author(name=name) for name in authors] for author in self.authors: author.save() for i, entry in enumerate(self.entries): entry.authors.add(self.authors[i]) entry.authors.add(self.authors[(i + 1) % len(self.authors)])