Skip to content

Latest commit

 

History

History
343 lines (227 loc) · 13.5 KB

TESTING.md

File metadata and controls

343 lines (227 loc) · 13.5 KB

TABLE OF CONTENT:

UNIT TESTING

I have used django TestCase for automated testing views, forms and models files.

TESTING VIEWS:

  • 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:

    Test Views

TESTING FORMS:

  • 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:

    Test Poem Form

    • 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:

      Test Comments Form

Testing Models:

  • 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:

    Test Models

Validator Testing

Lighthouse

  • Testing results:

    lighthouse

  • Errors and warnings found, reported as bug, resolved the issues and all tests passed. Click here to view bug details.

    • Home Page:

      html home

    • Poem List Page:

      html poem list page

    • Poem Details:

      html poem details

    • Sign-up page:

      sign up

    • Login page:

      login

    • Logged in home page:

      Logged in home

    • Logout:

      logout

    • Poem Publish Page:

      html publish page

    • Profile:

      profile page

  • No errors or warnings found:

    css validation

  • No errors or warnings found.

  • models.py :

    models.py

  • admin.py:

    admin.py

  • poems - urls.py:

    poems-urls.py

  • views.py:

    views.py

  • forms.py:

    forms.py

  • test_views.py:

    test_views.py

  • test_models.py:

    test_models.py

  • test_forms.py:

    test_forms.py

  • apps.py:

    apps.py

  • asgi.py:

    asgi.py

  • project - urls.py:

    project - urls.

BUGS

Click here to view Bugs issues in GitHub

bug issues page

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.
  • delete the correct post:

    • 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 have data-bs-target="#deleteModal{{ post.id }}"
      • Details can be viewed along with the bugs screenshots here.
  • Bug found while HTML validation Testing:

    • During the HTML validator testing for some of the poems content page, I came accross an error and warning with <o:p>.

      html error

    • 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'.

      page-source-error-view

    • 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:

      Stack explanation for op error

    • 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.

      unsolved bug

    • 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.

User Story Testing

Admin

  • 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.

    Admin

Member User

  • As a Member User I can register an account so that I can manage my posts, comment and like.

    Register

  • As a Member User I can post/add/edit/delete poems so that I can share and manage my poems.

    Profile

  • 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.

    Likes and Comments

  • As a Member User I can view my posts status of approval so that I can manage my poems.

    Manage My Poems

General User

  • As a Site User I can view a list of posts so that I can select one to read.

    Post List

  • As a Site User I can click on a post so that I can read the full text.

    Post content

  • 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.

    likes and comments

Browser Compatability

  • Checked and verified that the site works on different browsers.

  • Safari:

    Safari

  • Chrome:

    Chrome

Responsiveness Testing

  • Desktop - Large Screen sizes:

    Desktop

  • Ipad - Medium Screen sizes:

    Ipad

  • Mobile - Small Screen Sizes:

    Mobile