This repo contains simple and complex Django App that I Implement while learning Django web framework
This is a simple hello world app in Django.
Learned to:
- Create function based views
- Use HttpResponse to return http request to client
fun homePageView(requests):
return HttpResponse("Hello, World)
A simple app that has two pages. The index
and about.html
pages.
Learned how to return these pages using class based views
.
from django.views.generic import TemplateVew
class HomePageView(TemplateView):
template_name = 'home.html'
Learnt to create simple test cases for the basic app.
"Code without tests is broken as designed"~J.Kaplan Moss
Used SimpleTestCase
that lets testing without lookup on the database.
from django.test import impleTestCase
class SimpleTestCase(SimpleTestCase):
def test_homepage_status_code(self):
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
def test_about_page_status_code(self):
response = self.client.get('/about/')
self.assertEqual(response.status_code, 200)
To run the tests, run:
python manage.py test
A simple app that implements models with SQLite database. Uses the TemplateView to List all Posts stored in the database using TestCase
.
The app also tests the following\
- PostModel
class PostModelTest(TestCase):
def setUp(self):
Post.objects.create(title="Sublime or Vs Code?", text="Code editor wars.")
def test_text_content(self):
post = Post.objects.get(id=1)
expected_object_text = f'{post.text}'
self.assertEqual(expected_object_text, 'Code editor wars.')
- PostTitle
class PostTitleTest(TestCase):
def setUp(self):
Post.objects.create(title="Sublime or Vs Code?", text="Code editor wars.")
def test_post_title(self):
post = Post.objects.get(id=1)
expected_object_text = f'{post.title}'
self.assertEqual(expected_object_text, 'Sublime or Vs Code?')
- HomePageView
class HomePageViewTest(TestCase):
def setUp(self) :
Post.objects.create(title="Cloud wars", text="AWS leads GCP and Azure to dominate the cloud market")
def test_view_url_exists_at_proper_location(self):
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
def test_view_url_by_name(self):
resp = self.client.get(reverse('home'))
self.assertEqual(resp.status_code, 200)
def test_view_uses_correct_template(self):
resp = self.client.get(reverse('home'))
self.assertEqual(resp.status_code, 200)
self.assertTemplateUsed(resp, 'home.html')
9/15/2022
[9/16/2022]
A simple blog app that implements CRUD
operations.\
unit-tests create its own database which is empty.
django.test.Client
dummy Web browser for simulatingGET
andPOST
requests on a URL.\
[x] Fix
self.assertEqual(response.status_code, 200)
AssertionError: 404 != 200
on `def test_post_detail_view(self):` test\
[ ] Use form widgets
[ ] Use crispy forms
[ ] Use bootstrap or Tailwind to style
[ ] Create user dashboard\
Todo
- Celery to handle email resets
- Allauth - To integrate with third parties