|
@@ -875,6 +875,106 @@ class TestWorkspaceEndpoint(FunctionalTest):
|
875
|
875
|
assert 'details' in res.json.keys()
|
876
|
876
|
|
877
|
877
|
|
|
878
|
+class TestWorkspacesEndpoints(FunctionalTest):
|
|
879
|
+ """
|
|
880
|
+ Tests for /api/v2/workspaces
|
|
881
|
+ """
|
|
882
|
+ fixtures = [BaseFixture]
|
|
883
|
+
|
|
884
|
+ def test_api__get_workspaces__ok_200__nominal_case(self):
|
|
885
|
+ """
|
|
886
|
+ Check obtain all workspaces reachables for user with user auth.
|
|
887
|
+ """
|
|
888
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
889
|
+ admin = dbsession.query(models.User) \
|
|
890
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
891
|
+ .one()
|
|
892
|
+
|
|
893
|
+ workspace_api = WorkspaceApi(
|
|
894
|
+ session=dbsession,
|
|
895
|
+ current_user=admin,
|
|
896
|
+ config=self.app_config,
|
|
897
|
+ )
|
|
898
|
+ workspace_api.create_workspace('test', save_now=True) # nopep8
|
|
899
|
+ workspace_api.create_workspace('test2', save_now=True) # nopep8
|
|
900
|
+ workspace_api.create_workspace('test3', save_now=True) # nopep8
|
|
901
|
+ transaction.commit()
|
|
902
|
+ self.testapp.authorization = (
|
|
903
|
+ 'Basic',
|
|
904
|
+ (
|
|
905
|
+ 'admin@admin.admin',
|
|
906
|
+ 'admin@admin.admin'
|
|
907
|
+ )
|
|
908
|
+ )
|
|
909
|
+ res = self.testapp.get('/api/v2/workspaces', status=200)
|
|
910
|
+ res = res.json_body
|
|
911
|
+ assert len(res) == 3
|
|
912
|
+ workspace = res[0]
|
|
913
|
+ assert workspace['label'] == 'test'
|
|
914
|
+ assert workspace['slug'] == 'test'
|
|
915
|
+ workspace = res[1]
|
|
916
|
+ assert workspace['label'] == 'test2'
|
|
917
|
+ assert workspace['slug'] == 'test2'
|
|
918
|
+ workspace = res[2]
|
|
919
|
+ assert workspace['label'] == 'test3'
|
|
920
|
+ assert workspace['slug'] == 'test3'
|
|
921
|
+
|
|
922
|
+ def test_api__get_workspaces__err_403__unallowed_user(self):
|
|
923
|
+ """
|
|
924
|
+ Check obtain all workspaces reachables for one user
|
|
925
|
+ with another non-admin user auth.
|
|
926
|
+ """
|
|
927
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
928
|
+ admin = dbsession.query(models.User) \
|
|
929
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
930
|
+ .one()
|
|
931
|
+ uapi = UserApi(
|
|
932
|
+ current_user=admin,
|
|
933
|
+ session=dbsession,
|
|
934
|
+ config=self.app_config,
|
|
935
|
+ )
|
|
936
|
+ gapi = GroupApi(
|
|
937
|
+ current_user=admin,
|
|
938
|
+ session=dbsession,
|
|
939
|
+ config=self.app_config,
|
|
940
|
+ )
|
|
941
|
+ groups = [gapi.get_one_with_name('users')]
|
|
942
|
+ user = uapi.create_user('test@test.test', password='test@test.test',
|
|
943
|
+ do_save=True, do_notify=False,
|
|
944
|
+ groups=groups) # nopep8
|
|
945
|
+ transaction.commit()
|
|
946
|
+ self.testapp.authorization = (
|
|
947
|
+ 'Basic',
|
|
948
|
+ (
|
|
949
|
+ 'test@test.test',
|
|
950
|
+ 'test@test.test'
|
|
951
|
+ )
|
|
952
|
+ )
|
|
953
|
+ res = self.testapp.get('/api/v2/workspaces', status=403)
|
|
954
|
+ assert isinstance(res.json, dict)
|
|
955
|
+ assert 'code' in res.json.keys()
|
|
956
|
+ assert 'message' in res.json.keys()
|
|
957
|
+ assert 'details' in res.json.keys()
|
|
958
|
+
|
|
959
|
+ def test_api__get_workspaces__err_401__unregistered_user(self):
|
|
960
|
+ """
|
|
961
|
+ Check obtain all workspaces reachables for one user
|
|
962
|
+ without correct user auth (user unregistered).
|
|
963
|
+ """
|
|
964
|
+ self.testapp.authorization = (
|
|
965
|
+ 'Basic',
|
|
966
|
+ (
|
|
967
|
+ 'john@doe.doe',
|
|
968
|
+ 'lapin'
|
|
969
|
+ )
|
|
970
|
+ )
|
|
971
|
+ res = self.testapp.get('/api/v2/workspaces', status=401)
|
|
972
|
+ assert isinstance(res.json, dict)
|
|
973
|
+ assert 'code' in res.json.keys()
|
|
974
|
+ assert 'message' in res.json.keys()
|
|
975
|
+ assert 'details' in res.json.keys()
|
|
976
|
+
|
|
977
|
+
|
878
|
978
|
class TestWorkspaceMembersEndpoint(FunctionalTest):
|
879
|
979
|
"""
|
880
|
980
|
Tests for /api/v2/workspaces/{workspace_id}/members endpoint
|