Пример #1
0
 def test_view_function(self):
     request = self.factory.get('/beads_bag')
     response = product_all(request)
     html = response.content.decode('utf8')
     self.assertIn('<title>CraftStore</title>', html)
     self.assertTrue(html.startswith('\n<!DOCTYPE html>\n'))
     self.assertEqual(response.status_code, 200)
Пример #2
0
 def test_homepage_html(self):
     request = HttpRequest()
     response = product_all(request)
     html = response.content.decode('utf8')
     self.assertIn('<title>CraftStore</title>', html)
     self.assertTrue(html.startswith('\n<!DOCTYPE html>\n'))
     self.assertEqual(response.status_code, 200)
Пример #3
0
 def test_homepage_html(self):
     request = HttpRequest()
     response = product_all(request)
     html = response.content.decode('utf8')
     pprint(html)
     self.assertIn('<title>Home</title>', html)
     self.assertTrue(html.startswith('\n<!DOCTYPE html>\n'))
Пример #4
0
 def test_homepage_html(self):
     request = HttpRequest()
     engine = import_module(settings.SESSION_ENGINE)
     request.session = engine.SessionStore()
     response = product_all(request)
     html = response.content.decode('utf8')
     self.assertIn('<title>BookStore</title>', html)
     self.assertTrue(html.startswith('\n<!DOCTYPE html>\n'))
     self.assertEqual(response.status_code, 200)
Пример #5
0
 def test_view_function(self):
     """
     Example: Using request factory
     """
     request = self.factory.get('/item/django-beginners')
     response = product_all(request)
     html = response.content.decode('utf8')
     self.assertIn('<title>Book Nook</title>', html)
     self.assertTrue(html.startswith('\n<!DOCTYPE html>\n'))
     self.assertEqual(response.status_code, 200)
Пример #6
0
 def test_homepage_html(self):
     """
     Example: code validation, search HTML for text
     """
     request = HttpRequest()
     response = product_all(request)
     html = response.content.decode('utf8')
     self.assertIn('<title>Book Nook</title>', html)
     self.assertTrue(html.startswith('\n<!DOCTYPE html>\n'))
     self.assertEqual(response.status_code, 200)
Пример #7
0
    def test_with_request_factory(self):
        """
        request factory provide more advanced testing functionality than client class
        """

        request = self.factory.get("/watch")
        engine = import_module(settings.SESSION_ENGINE)
        request.session = engine.SessionStore()
        response = product_all(request)
        html = response.content.decode("utf8")
        self.assertInHTML("<title>Book Store</title>", html)
        self.assertEqual(response.status_code, 200)
Пример #8
0
    def test_homepage_html(self):
        """
        send a http reqeust to the view directly and capture the repsonse,then we can analysis any thing we want
        inside the page,
        after we added session we need to send session data with the request otherwise it will cause error in the
        test so we use import_module to do that.
        """

        request = HttpRequest()
        engine = import_module(settings.SESSION_ENGINE)
        request.session = engine.SessionStore()
        response = product_all(request)
        html = response.content.decode("utf8")
        self.assertInHTML("<title>Book Store</title>", html)
        self.assertEqual(response.status_code, 200)