Beispiel #1
0
class TestProfileUpdateView(SocialhomeTestCase):
    def setUp(self):
        # call BaseUserTestCase.setUp()
        super(TestProfileUpdateView, self).setUp()
        self.user = self.make_user()
        self.factory = RequestFactory()
        # Instantiate the view directly. Never do this outside a test!
        self.view = ProfileUpdateView()
        # Generate a fake request
        request = self.factory.get('/fake-url')
        # Attach the user to the request
        request.user = self.user
        # Attach the request to the view
        self.view.request = request

    def test_get_success_url(self):
        # Expect: '/users/testuser/', as that is the default username for
        #   self.make_user()
        self.assertEqual(
            self.view.get_success_url(),
            '/u/testuser/'
        )

    def test_get_object(self):
        # Expect: self.user, as that is the request's user object
        self.assertEqual(
            self.view.get_object(),
            self.user.profile
        )
Beispiel #2
0
 def setUp(self):
     super().setUp()
     self.user = self.make_user()
     self.profile = self.user.profile
     self.factory = RequestFactory()
     self.view = ProfileUpdateView()
     request = self.factory.get('/fake-url')
     request.user = self.user
     self.view.request = request
Beispiel #3
0
 def setUp(self):
     # call BaseUserTestCase.setUp()
     super(TestProfileUpdateView, self).setUp()
     # Instantiate the view directly. Never do this outside a test!
     self.view = ProfileUpdateView()
     # Generate a fake request
     request = self.factory.get('/fake-url')
     # Attach the user to the request
     request.user = self.user
     # Attach the request to the view
     self.view.request = request
Beispiel #4
0
 def setUp(self):
     super().setUp()
     self.user = self.make_user()
     self.profile = self.user.profile
     self.factory = RequestFactory()
     self.view = ProfileUpdateView()
     request = self.factory.get('/fake-url')
     request.user = self.user
     self.view.request = request
class TestProfileUpdateView(SocialhomeTestCase):
    def setUp(self):
        super().setUp()
        self.user = self.make_user()
        self.profile = self.user.profile
        self.factory = RequestFactory()
        self.view = ProfileUpdateView()
        request = self.factory.get('/fake-url')
        request.user = self.user
        self.view.request = request

    def test_get_success_url(self):
        # Expect: '/users/testuser/', as that is the default username for
        #   self.make_user()
        self.assertEqual(
            self.view.get_success_url(),
            '/u/testuser/'
        )

    def test_get_object(self):
        # Expect: self.user, as that is the request's user object
        self.assertEqual(
            self.view.get_object(),
            self.user.profile
        )

    def test_updates_name(self):
        with self.login(self.user):
            self.post("users:profile-update", data={
                "name": "updated name", "visibility": self.profile.visibility.value
            })
            self.response_302()
            self.profile.refresh_from_db()
            self.assertEqual(self.profile.name, "updated name")
            # Try a bad name
            self.post("users:profile-update", data={
                "name": '<script>alert("such hack");</script>', "visibility": self.profile.visibility.value
            })
            self.profile.refresh_from_db()
            self.assertEqual(self.profile.name, 'alert("such hack");')
Beispiel #6
0
class TestProfileUpdateView(SocialhomeTestCase):
    def setUp(self):
        super().setUp()
        self.user = self.make_user()
        self.profile = self.user.profile
        self.factory = RequestFactory()
        self.view = ProfileUpdateView()
        request = self.factory.get('/fake-url')
        request.user = self.user
        self.view.request = request

    def test_get_success_url(self):
        # Expect: '/users/testuser/', as that is the default username for
        #   self.make_user()
        self.assertEqual(
            self.view.get_success_url(),
            '/u/testuser/'
        )

    def test_get_object(self):
        # Expect: self.user, as that is the request's user object
        self.assertEqual(
            self.view.get_object(),
            self.user.profile
        )

    def test_updates_name(self):
        with self.login(self.user):
            self.post("users:profile-update", data={
                "name": "updated name", "visibility": self.profile.visibility.value
            })
            self.response_302()
            self.profile.refresh_from_db()
            self.assertEqual(self.profile.name, "updated name")
            # Try a bad name
            self.post("users:profile-update", data={
                "name": '<script>alert("such hack");</script>', "visibility": self.profile.visibility.value
            })
            self.profile.refresh_from_db()
            self.assertEqual(self.profile.name, 'alert("such hack");')