I have used django TestCase for automated testing views, forms and models files.
-
Tested if the views are funcitoning as expected and returns pages that the user needs to be at.
-
Testing Index/Home page view:
class TestIndexViews(TestCase): def test_get_index_page(self): response = self.client.get('/') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'index.html')
-
Testing Poem Lists Page View:
class TestPostListViews(TestCase): def test_get_post_list_page(self): response = self.client.get('/poem_list/') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'poem_list.html')
-
Testing Profile Page View:
class TestProfileViews(TestCase): def test_profile_page(self): response = self.client.get('/profile') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'profile.html')
-
Testing Adding Poems / Publish Poems Page View:
class TestPublishPoemViews(TestCase): def test_can_publish_poem(self): response = self.client.get('/publish') self.assertEqual(response.status_code, 200) self.assertTemplateUsed(response, 'publish.html')
Result:
-
-
Tested Poems Post form and Comment Form to make sure fields are as expected and the form is submitted to where it should:
- Testing Poems Form:
class TestPoemForm(TestCase): def test_post_title_is_required(self): form = PoemForm(({'title': ''})) self.assertFalse(form.is_valid()) self.assertIn('title', form.errors.keys()) self.assertEqual(form.errors['title'][0], 'This field is required.') def test_post_content_is_required(self): form = PoemForm(({'content': ''})) self.assertFalse(form.is_valid()) self.assertIn('content', form.errors.keys()) self.assertEqual(form.errors['content'][0], 'This field is required.') def test_fields_are_explicit_in_form_metaclass(self): form = PoemForm() self.assertEqual( form.Meta.fields, ('title', 'content', 'excerpt', 'featured_image') )
Result:
-
Testing Comments Form:
class TestCommentForm(TestCase): def test_post_title_is_required(self): form = CommentForm(({'body': ''})) self.assertFalse(form.is_valid()) self.assertIn('body', form.errors.keys()) self.assertEqual(form.errors['body'][0], 'This field is required.') def test_fields_are_explicit_in_form_metaclass(self): form = CommentForm() self.assertEqual(form.Meta.fields, ('body',))
Result:
- Testing Poems Form:
-
Models are tested while testing views and forms as well. But in addition, I tested if the models shows that featured image is a requirement and successfully sent to the database:
class TestModels(TestCase): def test_has_featured_image(self): self.assertTrue(Post.featured_image)
Result:
-
Errors and warnings found, reported as bug, resolved the issues and all tests passed. Click here to view bug details.
-
No errors or warnings found.
-
models.py :
-
admin.py:
-
poems - urls.py:
-
views.py:
-
forms.py:
-
test_views.py:
-
test_models.py:
-
test_forms.py:
-
apps.py:
-
asgi.py:
-
project - urls.py:
Click here to view Bugs issues in GitHub
Throughout the development project, I came accross several bugs. I have noted them in projects page as issues in Github, you can view them here. The bugs found and resolved are as follows:
-
Wire-up poems list page once opened.:
- The list of post is not visible when the page is opened.
- Contacted Code institute tutor support. The issue was in views.py.
- Details can be viewed along with the bugs screenshots here.
-
View submitted poem form as admin and approve to publish it in poems page:
- The form to submit a poem is created. Form is visible by authenticated user and can be submitted. It is not known where the form is submitted currently. The form must be visible to admin to be approved.
- The bug avoided me to submit the form from front end. The form submitted was not getting submitted to Admin panel to get approved.
- Steps taken:
- Contacted Code Insitute's Tutor Support.
- Suggestions to make following changes to my views.py file and from django.contrib.auth.models import User
- Details can be viewed along with the bugs screenshots here.
-
Image upload does not save, placeholder image publishes.:
- The user can upload the image, the form gets through correctly. However, the image is not saved and placeholder image gets published.
- Add
request.FILES
in views.py. Images were uploading, but after submitting the form it did not get through, so placeholder image was in use. Now the user image upload is working. - Details can be viewed along with the bugs screenshots here.
-
- When user wants to delete a post of their own, the latest post added gets deleted. The post user choses to delete is therefore not deleted if it is not the latest one.
- Code Institute tutor support suggested me to target delete modal id with:
id="deleteModal{{ post.id }}"
and the button to trigger it would havedata-bs-target="#deleteModal{{ post.id }}"
-
- Details can be viewed along with the bugs screenshots here.
-
-
During the HTML validator testing for some of the poems content page, I came accross an error and warning with
<o:p>
. -
The error displayed was for each paragraph. This was not familiar to me as there was nothing like
<o:p>
anywhere within my code. To figure out what is causing the error and where it is coming from, I opened one of the poems and did 'View Page Source'. -
I did a search on Google for what
<o:p>
means and how did it end up in my code if I have not added it myself. I found that "<o:p>
means 'Office namespace'" from Stack Overflow: -
This meant that the poems I added contained hidden Microsoft word tags. These hidden "Office Paragraph
<o:p>
tags" got carried along with the poem content when I copy + pasted the poem direclty from Microsoft Word document to the admin panel. -
As a solution, my mentor from Code Institute - Tim Nelson, suggested me to first paste those poems that contained this bug to any 'Notes' file. The 'Notes' removes any kind of html tags or decorators. And later copy + paste them to their relevant posts.
-
After following these steps, all the tests passed HTML validator testing without any issues or warnings.
-
-
Unsolved Bug:
-
Once the user submits a poem, and if the admin edits any part of the users submission, such as a space or extra line, all the html content(tags and css) gets visible to user if they want to edit their own post after.
-
If the post submitted by the user in not touched by admin, these codes are hidden to user, when they want to edit back their own post.
-
-
As a Site Admin I can approve or disapprove posts so that I can filter out objectionable posts.
-
As a Site Admin I can create, read, update and delete posts so that I can manage my blog content.
-
As a Site Admin I can aproove Posts before it is published so that the site content will be consistent.
-
As a Member User I can register an account so that I can manage my posts, comment and like.
-
As a Member User I can post/add/edit/delete poems so that I can share and manage my poems.
-
As a Member User I can like or unlike a post so that I can interact with the content.
-
As a Member User I can leave comments on a post so that I can be involved in the conversation.
-
As a Member User I can view my posts status of approval so that I can manage my poems.
-
As a Site User I can view a list of posts so that I can select one to read.
-
As a Site User I can click on a post so that I can read the full text.
-
As a Site User / Admin user I can view comments on an individual post so that I can read the conversation.
-
As a Site User / Admin I can view the number of likes on each post so that I can see which is the most popular or viral.