|
27 | 27 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
28 | 28 | import pkg_resources |
29 | 29 |
|
| 30 | +from pytest import fixture |
| 31 | + |
| 32 | +from servicex.resources.servicex_resource import ServiceXResource |
| 33 | +from tests.resource_test_base import ResourceTestBase |
| 34 | + |
| 35 | + |
| 36 | +class TestServiceXResource(ResourceTestBase): |
| 37 | + module = ServiceXResource.__module__ |
| 38 | + |
| 39 | + @fixture |
| 40 | + def mock_user(self, mocker): |
| 41 | + return mocker.patch(f"{self.module}.UserModel.find_by_sub").return_value |
30 | 42 |
|
31 | | -class TestServiceXResource: |
32 | 43 | def test_get_app_version_no_servicex_app(self, mocker): |
33 | 44 | mock_get_distribution = mocker.patch( |
34 | | - "servicex.resources.servicex_resource.pkg_resources.get_distribution", |
35 | | - side_effect=pkg_resources.DistributionNotFound(None, None)) |
| 45 | + f"{self.module}.pkg_resources.get_distribution", |
| 46 | + side_effect=pkg_resources.DistributionNotFound(None, None) |
| 47 | + ) |
36 | 48 |
|
37 | | - from servicex.resources.servicex_resource import ServiceXResource |
38 | 49 | version = ServiceXResource._get_app_version() |
39 | 50 |
|
40 | 51 | mock_get_distribution.assert_called_with("servicex_app") |
41 | 52 | assert version == 'develop' |
| 53 | + |
| 54 | + def test_get_requesting_user_no_auth(self, client): |
| 55 | + with client.application.app_context(): |
| 56 | + assert ServiceXResource.get_requesting_user() is None |
| 57 | + |
| 58 | + def test_get_requesting_user_with_auth(self, mocker, mock_user): |
| 59 | + mocker.patch(f"{self.module}.get_jwt_identity").return_value = "abcd" |
| 60 | + client = self._test_client(extra_config={'ENABLE_AUTH': True}) |
| 61 | + with client.application.app_context(): |
| 62 | + assert ServiceXResource.get_requesting_user() == mock_user |
| 63 | + |
| 64 | + def test_get_requesting_user_no_identity(self, mocker): |
| 65 | + mocker.patch(f"{self.module}.get_jwt_identity").return_value = None |
| 66 | + client = self._test_client(extra_config={'ENABLE_AUTH': True}) |
| 67 | + with client.application.app_context(): |
| 68 | + assert ServiceXResource.get_requesting_user() is None |
0 commit comments