def configured_app(minimal_app_for_api): app = minimal_app_for_api create_role( app, name="TestRole", permissions=[], ) yield app delete_role(app, 'TestRole') # type:ignore
def test_delete_should_respond_204(self, session): role = create_role(self.app, "mytestrole") response = self.client.delete( f"/api/v1/roles/{role.name}", environ_overrides={'REMOTE_USER': "******"}) assert response.status_code == 204 role_obj = session.query(Role).filter(Role.name == role.name).all() assert len(role_obj) == 0
def setUpClass(cls) -> None: super().setUpClass() cls.app = app.create_app(testing=True) # type:ignore cls.role1 = create_role( cls.app, # type: ignore name="Test1", permissions=[ (permissions.ACTION_CAN_CREATE, permissions.RESOURCE_CONNECTION), ], ) cls.role2 = create_role( cls.app, # type: ignore name="Test2", permissions=[ (permissions.ACTION_CAN_EDIT, permissions.RESOURCE_DAG), ], )
def test_patch_should_respond_200(self, payload, expected_name, expected_actions): role = create_role(self.app, 'mytestrole') response = self.client.patch(f"/api/v1/roles/{role.name}", json=payload, environ_overrides={'REMOTE_USER': "******"}) assert response.status_code == 200 assert response.json['name'] == expected_name assert response.json["actions"] == expected_actions
def test_patch_should_respond_400_for_invalid_update( self, payload, expected_error): role = create_role(self.app, "mytestrole") response = self.client.patch( f"/api/v1/roles/{role.name}", json=payload, environ_overrides={'REMOTE_USER': "******"}, ) assert response.status_code == 400 assert response.json['detail'] == expected_error
def test_patch_should_respond_400_for_invalid_fields_in_update_mask(self): role = create_role(self.app, "mytestrole") payload = {"name": "testme"} response = self.client.patch( f"/api/v1/roles/{role.name}?update_mask=invalid_name", json=payload, environ_overrides={'REMOTE_USER': "******"}, ) assert response.status_code == 400 assert response.json[ 'detail'] == "'invalid_name' in update_mask is unknown"
def test_patch_should_respond_200_with_update_mask(self, update_mask, payload, expected_name, expected_actions): role = create_role(self.app, "mytestrole") assert role.permissions == [] response = self.client.patch( f"/api/v1/roles/{role.name}{update_mask}", json=payload, environ_overrides={'REMOTE_USER': "******"}, ) assert response.status_code == 200 assert response.json['name'] == expected_name assert response.json['actions'] == expected_actions