Exemple #1
0
 def test_get_tenant_user_not_found(self):
     """Test that a 401 is returned."""
     mock_user = Mock(username="******")
     mock_request = Mock(path="/api/v1/providers/", user=mock_user)
     middleware = KokuTenantMiddleware()
     result = middleware.process_request(mock_request)
     self.assertIsInstance(result, HttpResponseUnauthorizedRequest)
Exemple #2
0
    def test_process_request_user_access_no_permissions(self, get_access_mock):
        """Test PermissionDenied is not raised for user-access calls"""
        mock_access = {}
        username = "******"
        get_access_mock.return_value = mock_access

        user_data = self._create_user_data()
        customer = self._create_customer_data()
        request_context = self._create_request_context(customer,
                                                       user_data,
                                                       create_customer=True,
                                                       create_tenant=True,
                                                       is_admin=False)
        mock_request = request_context["request"]
        mock_request.path = "/api/v1/user-access/"
        mock_request.META["QUERY_STRING"] = ""
        mock_user = Mock(username=username, admin=False, access=None)
        mock_request = Mock(path="/api/v1/user-access/", user=mock_user)
        IdentityHeaderMiddleware.create_user(
            username=username,
            email=self.user_data["email"],
            customer=Customer.objects.get(
                account_id=customer.get("account_id")),
            request=mock_request,
        )

        middleware = KokuTenantMiddleware()
        with patch.object(BaseTenantMiddleware,
                          "process_request") as mock_process_request:
            _ = middleware.process_request(mock_request)
            mock_process_request.assert_called()
Exemple #3
0
 def test_get_tenant_with_no_user(self):
     """Test that a 401 is returned."""
     mock_request = Mock(path="/api/v1/providers/", user=None)
     middleware = KokuTenantMiddleware()
     result = middleware.process_request(mock_request)
     self.assertIsInstance(result, HttpResponseUnauthorizedRequest)