Ejemplo n.º 1
0
    def test_change_callback_app_does_not_exist(self):
        user_ = User.objects.create(email="*****@*****.**",
                                    cn="test",
                                    given_name="Test Test")

        request = self.factory.post('/api/setcallbackurl/', {
            "app_id": 100000000000001,
            "callback_url": "https://testcall.com"
        })
        request.session = {'user_id': user_.id}
        response = set_callback_url(request)
        content = json.loads(response.content.decode())
        self.assertEqual(response.status_code, 400)
        self.assertEqual(content["message"], "App does not exist.")
Ejemplo n.º 2
0
    def test_change_callback_not_in_session(self):
        user_ = User.objects.create(email="*****@*****.**",
                                    cn="test",
                                    given_name="Test Test")

        app_ = App.objects.create(user=user_, name="An App")

        request = self.factory.post('/api/setcallbackurl/', {
            "app_id": app_.id,
        })
        response = set_callback_url(request)
        content = json.loads(response.content.decode())
        self.assertEqual(response.status_code, 400)
        self.assertEqual(content["message"],
                         "User ID not set in session. Please log in again.")
Ejemplo n.º 3
0
 def test_change_callback_url_not_valid(self):
     user_ = User.objects.create(email="*****@*****.**",
                                 cn="test",
                                 given_name="Test Test")
     app_ = App.objects.create(user=user_, name="An App")
     request = self.factory.post('/api/setcallbackurl/', {
         "app_id": app_.id,
         "callback_url": "NotReallyAURL"
     })
     request.session = {'user_id': user_.id}
     response = set_callback_url(request)
     content = json.loads(response.content.decode())
     self.assertEqual(response.status_code, 400)
     self.assertEqual(content["message"],
                      "The requested callback URL is not valid.")
Ejemplo n.º 4
0
    def test_change_callback_no_url_provided(self):
        user_ = User.objects.create(email="*****@*****.**",
                                    cn="test",
                                    given_name="Test Test")

        app_ = App.objects.create(user=user_, name="An App")

        request = self.factory.post('/api/setcallbackurl/', {
            "app_id": app_.id,
        })
        request.session = {'user_id': user_.id}
        response = set_callback_url(request)
        content = json.loads(response.content.decode())
        self.assertEqual(response.status_code, 400)
        self.assertEqual(content["message"],
                         "Request does not have a Callback URL.")
Ejemplo n.º 5
0
    def test_change_callback_url_success(self):
        user_ = User.objects.create(email="*****@*****.**",
                                    cn="test",
                                    given_name="Test Test")

        app_ = App.objects.create(user=user_, name="An App")

        request = self.factory.post('/api/setcallbackurl/', {
            "app_id": app_.id,
            "callback_url": "https://testcall.com"
        })
        request.session = {'user_id': user_.id}
        response = set_callback_url(request)
        content = json.loads(response.content.decode())
        self.assertEqual(response.status_code, 200)
        self.assertEqual(content["message"],
                         "Callback URL successfully changed.")
        app_ = App.objects.filter(id=app_.id, user=user_.id)[0]
        self.assertTrue(app_.callback_url == "https://testcall.com")