summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorprathamesh2018-04-14 07:23:58 +0530
committerprathamesh2018-04-14 07:23:58 +0530
commitb12f12c77f38fee5830e887ee830dfa7ab2e687d (patch)
tree96d9811fd0f7479b4e08911a312bd9ef7fdc3b62
parent8a67d61e97592a496f526399aebf6aa39e7138b0 (diff)
downloadlearn_django-b12f12c77f38fee5830e887ee830dfa7ab2e687d.tar.gz
learn_django-b12f12c77f38fee5830e887ee830dfa7ab2e687d.tar.bz2
learn_django-b12f12c77f38fee5830e887ee830dfa7ab2e687d.zip
Create outline for the sccript tests in django
-rw-r--r--tutorial_10_django_tests/slides.md119
1 files changed, 119 insertions, 0 deletions
diff --git a/tutorial_10_django_tests/slides.md b/tutorial_10_django_tests/slides.md
new file mode 100644
index 0000000..0365e34
--- /dev/null
+++ b/tutorial_10_django_tests/slides.md
@@ -0,0 +1,119 @@
+Slide 1
+--------
+Title Slide
+** Writing Tests in Django**
+
+Slide 2
+--------
+
+**Learning Objectives**
+
+In this tutorial, we will learn to;
+ - Write tests in django
+ - Run tests in django
+
+Slide 3
+---------------
+
+**System Requirements**
+ - Ubuntu 16.10
+ - Python 3.5 or higher version
+ - python3.4-venv
+
+Slide 4
+---------------
+
+**Pre-requisites**
+
+In order to follow this tutorial, you need to know;
+ - how to create models in django
+ - how to use django shell
+ - If not, see the relevant django tutorial on http://spoken-tutorial.org
+
+Slide 5
+-------
+
+** Testing in Django**
+ - Automated testing is very useful
+ - We can validate our code during development
+ - Testing is very complex,as we need to test models, views and forms.
+ - In this tutorial we learn to write tests for models
+
+Demonstration
+-------------
+
+ - Write tests in tests.py in blog app
+
+ from django.test import TestCase
+
+ # Create your tests here.
+
+ from blog.models import Blog
+
+ class BlogTestCase(TestCase):
+ def setUp(self):
+ Blog.objects.create(name='Blog1')
+
+ def test_blog_created(self):
+ blog = Blog.objects.get(id=1)
+ name = 'Blog1'
+ self.assertEqual(blog.name, name)
+
+ - Run test
+
+ python manage.py test blog
+
+We will see test Ran successfully
+
+Demonstration
+-------------
+**Adding one more testcase**
+
+ def test_was_created_recently(self):
+ blog = Blog.objects.get(id=1)
+ is_created_recently = True
+ self.assertEqual(blog.was_created_recently(), is_created_recently)
+ - Run
+
+Demonstration
+-------------
+**Failing testcase**
+
+ - Edit testcase
+
+ def test_was_created_recently(self):
+ blog = Blog.objects.get(id=1)
+ is_created_recently = False # Change True to False
+ self.assertEqual(blog.was_created_recently(), is_created_recently)
+
+ - Run
+
+ - Show assertion error in the output
+
+
+Demonstration
+-------------
+** Using assertTrue **
+
+ - Edit testcase
+
+ def test_was_created_recently(self):
+ blog = Blog.objects.get(id=1)
+ self.assertTrue(blog.was_created_recently())
+
+ - Run
+
+
+Demonstration
+--------------
+ - Run individual test case
+
+ python manage.py shell test blogs.tests.test_was_created_recently
+
+Demonstration
+--------------
+ - Add testcase for Article model
+ - Run
+(For script creator: Can add this or give this as an assignment)
+
+**Concluding Slides**