Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test cases for ORM queries mentioned in book and some typo fix #53

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
edefe66
typo fix
Shekharnunia Aug 4, 2020
1f4a6c4
testcases are added for first 7 sections of documentation query which…
Shekharnunia Aug 4, 2020
cb76803
Create django.yml
Shekharnunia Aug 4, 2020
2447112
Update django.yml
Shekharnunia Aug 4, 2020
0389847
Update django.yml
Shekharnunia Aug 4, 2020
fe6bf26
python decople added into requirements and sqlite database added into…
Shekharnunia Aug 4, 2020
5a6d161
complex subquery test case added into entities app and black formatti…
Shekharnunia Aug 5, 2020
bd47cf5
F expression test cases are added which will first check for simple F…
Shekharnunia Aug 5, 2020
2185750
Join operation test added which will verify if the given django orm q…
Shekharnunia Aug 5, 2020
fa7deff
test case for grouping queries are added
Shekharnunia Aug 5, 2020
31766c6
bulk create query test cases are added
Shekharnunia Aug 5, 2020
f802515
object copy query test care are written
Shekharnunia Aug 5, 2020
157751c
test case added to check that only single object will be created a model
Shekharnunia Aug 5, 2020
04e986a
test case for denormalized data is added
Shekharnunia Aug 5, 2020
6080409
black formatting applied for models and test files
Shekharnunia Aug 5, 2020
68a0ca8
test case for truncate query is added and for current working cursor …
Shekharnunia Aug 5, 2020
1156cb5
test case for storing date from string into datefield is added
Shekharnunia Aug 5, 2020
b86a910
test case for order by with case insensitivity is added
Shekharnunia Aug 5, 2020
538813e
test case of orderby on two fields is added
Shekharnunia Aug 5, 2020
320bd5f
test case for order by on foreignkey field is added
Shekharnunia Aug 6, 2020
fac8504
test case for orderby with annotation is added
Shekharnunia Aug 6, 2020
768ca9f
test case for one to one model relationship is added
Shekharnunia Aug 6, 2020
a022b0b
typo fix in one to many documentation page
Shekharnunia Aug 6, 2020
6b5404e
test case for one to many relation is added
Shekharnunia Aug 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
test case for truncate query is added and for current working cursor …
…method changed to sqlite sql code
Shekharnunia committed Aug 5, 2020
commit 68a0ca84f45fa9a8dfa90589d7c698b3d27f8b8c
2 changes: 1 addition & 1 deletion heroes_and_monsters/entities/models.py
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ class Meta:
@classmethod
def truncate(cls):
with connection.cursor() as cursor:
cursor.execute('TRUNCATE TABLE "{0}" CASCADE'.format(cls._meta.db_table))
cursor.execute('DELETE FROM "{0}"'.format(cls._meta.db_table))

def __str__(self):
return self.name
12 changes: 12 additions & 0 deletions heroes_and_monsters/entities/tests.py
Original file line number Diff line number Diff line change
@@ -163,3 +163,15 @@ def test_hero_count(self):
category = Category.objects.get(id=2)

self.assertEqual(category.hero_count, hero_count + 1)


class TestTruncateQuery(GlobalCategoryTestData, TestCase):
def test_truncate_data(self):
self.assertEqual(Category.objects.all().count(), 3)
Category.objects.all().delete()
self.assertEqual(Category.objects.all().count(), 0)

def test_truncate_data_using_cursor(self):
self.assertEqual(Category.objects.all().count(), 3)
Category.truncate()
self.assertEqual(Category.objects.all().count(), 0)