Exemplo n.º 1
0
    def test_index_handles_logged_in_user(self):
        #create a session that appears to have a logged in user
        self.request.session = {"user": "******"}

        #setup dummy user
        #we need to save user so user -> badges relationship is created
        u = User(email="*****@*****.**")
        u.save()

        with mock.patch('main.views.User') as user_mock:

            #tell the mock what to do when called
            config = {'get_by_id.return_value': u}
            user_mock.configure_mock(**config)

            #run the test
            resp = index(self.request)

            #ensure we return the state of the session back to normal
            self.request.session = {}
            u.delete()

            #we are now sending a lot of state for logged in users, rather than
            #recreating that all here, let's just check for some text
            #that should only be present when we are logged in.
            self.assertContains(resp, "Report back to base")
Exemplo n.º 2
0
    def test_index_handles_logged_in_user(self):
        #create a session that appears to have a logged in user
        self.request.session = {"user": "******"}

        #setup dummy user
        #we need to save user so user -> badges relationship is created
        u = User(email="*****@*****.**")
        u.save()

        with mock.patch('main.views.User') as user_mock:

            #tell the mock what to do when called
            config = {'get_by_id.return_value': u}
            user_mock.configure_mock(**config)

            #run the test
            resp = index(self.request)

            #ensure we return the state of the session back to normal
            self.request.session = {}
            u.delete()

            #we are now sending a lot of state for logged in users, rather than
            #recreating that all here, let's just check for some text
            #that should only be present when we are logged in.
            self.assertContains(resp, "Report back to base")
    def test_index_handles_logged_in_user(self):
        # Create a session that appears to have a logged in user
        self.request.session = {"user": "******"}
        u = User(email="*****@*****.**")
        u.save()

        with mock.patch('main.views.User') as user_mock:

            # Tell the mock what to do when called
            config = {'get_by_id.return_value': u}
            user_mock.configure_mock(**config)

            # Run the test
            resp = index(self.request)

            # Ensure we return the state of the session back to normal
            self.request.session = {}
            u.delete()

            self.assertContains(resp, "Report back to base")
Exemplo n.º 4
0
    def test_index_handles_logged_in_user(self):
        # Create a session that appears to have a logged in user
        self.request.session = {"user": "******"}
        u = User(email="*****@*****.**")
        u.save()

        with mock.patch('main.views.User') as user_mock:

            # Tell the mock what to do when called
            config = {'get_by_id.return_value': u}
            user_mock.configure_mock(**config)

            # Run the test
            resp = index(self.request)

            # Ensure we return the state of the session back to normal
            self.request.session = {}
            u.delete()

            self.assertContains(resp, "Report back to base")
Exemplo n.º 5
0
    def test_index_handles_logged_in_user(self):
         # Create a session that appears to have a logged in user
        self.request.session={'user':'******'}
        #setup dummy user
        #we need to save user so user -> badges relationship is created
        u=User(email="*****@*****.**")
        u.save()

        with mock.patch('main.views.User') as user_mock:
        # Tell the mock what to do when called
            config = {'get_by_id.return_value': u}# mock.Mock()}
            user_mock.configure_mock(**config)
             #Run the test
            resp=index(self.request)
            #ensure we return the state of the session back to normal so
           #we don't affect other test
            self.request.session={}
           #verify it returns the page for the logged in user
            # expectedHtml = render_to_response(
            # 'main/user.html', {'user': user_mock.get_by_id(1)})
            u.delete()

            #self.assertEquals(resp.content, expectedHtml.content)
            self.assertContains(resp,"Report back to base")