def test_project_delete(self, user1):
        conn = get_connection(user1)
        user_name = conn.getUser().getName()
        django_client = self.new_django_client(user_name, user_name)

        project = ProjectI()
        project.name = rstring('test_project_delete')
        project.description = rstring('Test update')
        project = get_update_service(user1).saveAndReturnObject(project)
        version = api_settings.API_VERSIONS[-1]
        project_url = reverse('api_project',
                              kwargs={'api_version': version,
                                      'object_id': project.id.val})
        # Before delete, we can read
        pr_json = get_json(django_client, project_url)
        assert pr_json['data']['Name'] == 'test_project_delete'
        # Delete
        delete_json(django_client, project_url, {})
        # Get should now return 404
        rsp = get_json(django_client, project_url, status_code=404)
        assert rsp['message'] == 'Project %s not found' % project.id.val
        # Delete (again) should return 404
        rsp = delete_json(django_client, project_url, {}, status_code=404)
        assert rsp['message'] == 'Project %s not found' % project.id.val
        save_url = reverse('api_save', kwargs={'api_version': version})
        # TODO: Try to save deleted object - should return ApiException
        # see https://trello.com/c/qWNt9vLN/178-save-deleted-object
        with pytest.raises(AssertionError):
            rsp = put_json(django_client, save_url, pr_json, status_code=400)
            assert rsp['message'] == 'Project %s not found' % project.id.val
Exemplo n.º 2
0
    def test_roi_delete(self, user1, image_rois):
        """Test GET and DELETE of a single ROI."""
        image, rois = image_rois
        conn = get_connection(user1)
        user_name = conn.getUser().getName()
        client = self.new_django_client(user_name, user_name)
        version = api_settings.API_VERSIONS[-1]

        # Before delete, we can read
        roi_id = rois[0].id.val
        roi_url = reverse('api_roi',
                          kwargs={
                              'api_version': version,
                              'object_id': roi_id
                          })
        rsp = get_json(client, roi_url)
        assert_objects(conn, [rsp['data']],
                       rois[:1],
                       dtype="Roi",
                       opts={'load_shapes': True})
        shape_json = rsp['data']['shapes'][0]
        shape_id = shape_json['@id']
        shape_class = shape_json['@type'].split('#')[1]  # e.g. Ellipse
        shape = conn.getQueryService().get(shape_class, shape_id)
        assert shape.id.val == shape_id

        # Delete
        delete_json(client, roi_url, {})
        # Get should now return 404
        rsp = get_json(client, roi_url, status_code=404)
        assert rsp['message'] == 'Roi %s not found' % roi_id

        # Check that Shape has also been deleted
        with pytest.raises(ValidationException):
            shape = conn.getQueryService().get(shape_class, shape_id)
Exemplo n.º 3
0
    def test_container_crud(self, dtype):
        """
        Test create, read, update and delete of Containers.

        Create with POST to /save
        Read with GET of /m/dtype/:id/
        Update with PUT to /m/dtype/:id/
        Delete with DELETE to /m/dtype/:id/
        """
        django_client = self.django_root_client
        group = self.ctx.groupId
        version = api_settings.API_VERSIONS[-1]
        # Need to get the Schema url to create @type
        base_url = reverse('api_base', kwargs={'api_version': version})
        rsp = get_json(django_client, base_url)
        schema_url = rsp['url:schema']
        # specify group via query params
        save_url = "%s?group=%s" % (rsp['url:save'], group)
        project_name = 'test_container_create_read'
        payload = {
            'Name': project_name,
            '@type': '%s#%s' % (schema_url, dtype)
        }
        rsp = post_json(django_client, save_url, payload, status_code=201)
        new_obj = rsp['data']
        # We get the complete new Object returned
        assert new_obj['Name'] == project_name
        object_id = new_obj['@id']

        # Read Object
        object_url = "%sm/%ss/%s/" % (base_url, dtype.lower(), object_id)
        rsp = get_json(django_client, object_url)
        object_json = rsp['data']
        assert object_json['@id'] == object_id
        conn = BlitzGateway(client_obj=self.root)
        assert_objects(conn, [object_json], [object_id], dtype=dtype)

        # Update Object...
        object_json['Name'] = 'new name'
        rsp = put_json(django_client, save_url, object_json)
        # ...and read again to check
        rsp = get_json(django_client, object_url)
        updated_json = rsp['data']
        assert updated_json['Name'] == 'new name'

        # Delete
        delete_json(django_client, object_url, {})
        # Get should now return 404
        rsp = get_json(django_client, object_url, status_code=404)
Exemplo n.º 4
0
    def test_link_unlink_tagset_tags(self):
        """
        Tests linking of tagset to tag, then unlinking
        """
        tag = self.make_tag()
        tagset = self.make_tag(ns=omero.constants.metadata.NSINSIGHTTAGSET)
        tagId = tag.id.val
        tagsetId = tagset.id.val

        links_url = reverse("api_links")
        # Link tagset to tag
        data = {'tagset': {tagsetId: {'tag': [tagId]}}}
        rsp = post_json(self.django_client, links_url, data)
        assert rsp == {"success": True}

        # Check that tag is listed under tagset...
        tags_url = reverse("api_tags_and_tagged")
        r = get_json(self.django_client, tags_url, {'id': tagsetId})
        assert len(r['tags']) == 1
        assert r['tags'][0]['id'] == tagId

        # Unlink first Tag from Tagset
        # data {} is same as for creating link above
        response = delete_json(self.django_client, links_url, data)
        assert response["success"]

        # Since the Delete is ansync - need to check repeatedly for deletion
        for i in range(10):
            rsp = get_json(self.django_client, tags_url, {'id': tagsetId})
            if len(rsp['tags']) == 0:
                break
            sleep(0.5)
        # Check that link has been deleted
        assert len(rsp['tags']) == 0
 def test_delete_unsupported(self, user1, dtype):
     """Test delete is rejected for unsupported types."""
     conn = get_connection(user1)
     user_name = conn.getUser().getName()
     django_client = self.new_django_client(user_name, user_name)
     version = api_settings.API_VERSIONS[-1]
     # Delete (fake url - image doesn't need to exist for test)
     url_name = 'api_%s' % dtype.lower()
     delete_url = reverse(url_name, kwargs={'api_version': version,
                                            'object_id': 1})
     rsp = delete_json(django_client, delete_url, status_code=405)
     assert rsp['message'] == 'Delete of %s not supported' % dtype
Exemplo n.º 6
0
    def test_unlink_screen_plate(self, screens, plates):
        # Link both plates to both screens
        request_url = reverse("api_links")
        sids = [s.id.val for s in screens]
        pids = [p.id.val for p in plates]
        data = {
            'screen': {sids[0]: {'plate': pids},
                       sids[1]: {'plate': pids}}
        }
        rsp = post_json(self.django_client, request_url, data)
        assert rsp == {"success": True}

        # Confirm that first Screen linked to 2 Plates
        plates_url = reverse("api_plates")
        rsp = get_json(self.django_client, plates_url, {'id': sids[0]})
        assert len(rsp['plates']) == 2

        # Unlink first Plate from first Screen
        request_url = reverse("api_links")
        data = {
            'screen': {sids[0]: {'plate': pids[:1]}}
        }
        response = delete_json(self.django_client, request_url, data)
        # Returns remaining link from 2nd Screen to first Plate
        assert response == {"success": True,
                            "screen": {str(sids[1]): {"plate": pids[:1]}}
                            }

        # Since the Delete is ansync - need to check repeatedly for deletion
        # by counting plates under screen...
        plates_url = reverse("api_plates")
        for i in range(10):
            rsp = get_json(self.django_client, plates_url, {'id': sids[0]})
            if len(rsp['plates']) == 1:
                break
            sleep(0.5)

        # Check that link has been deleted, leaving 2nd plate under 1st screen
        assert len(rsp['plates']) == 1
        assert rsp['plates'][0]['id'] == pids[1]
Exemplo n.º 7
0
    def test_paste_move_remove_deletamany_image(self):

        # Add dataset
        request_url = reverse("manage_action_containers",
                              args=["addnewcontainer"])
        data = {'folder_type': 'dataset', 'name': 'foobar'}
        response = post(self.django_client, request_url, data)
        did = json.loads(response.content).get("id")

        img = self.make_image()
        print img

        # Link image to Dataset
        request_url = reverse("api_links")
        data = {'dataset': {did: {'image': [img.id.val]}}}

        post_json(self.django_client, request_url, data)

        # Unlink image from Dataset
        request_url = reverse("api_links")
        data = {'dataset': {did: {'image': [img.id.val]}}}
        response = delete_json(self.django_client, request_url, data)
        # Response will contain remaining links from image (see test_links.py)
        assert response == {"success": True}