Esempio n. 1
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'}
        _post_response(self.django_client, request_url, data)
        response = _csrf_post_response(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_response(self.django_client, request_url, data)
        _csrf_post_response(self.django_client,
                            request_url,
                            json.dumps(data),
                            content_type="application/json")

        # Unlink image from Dataset
        request_url = reverse("api_links")
        data = {'dataset': {did: {'image': [img.id.val]}}}
        _delete_response(self.django_client, request_url, data)
        response = _csrf_delete_response(self.django_client,
                                         request_url,
                                         json.dumps(data),
                                         content_type="application/json")
        # Response will contain remaining links from image (see test_links.py)
        response = json.loads(response.content)
        assert response == {"success": True}
    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 = _csrf_post_response_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_response_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 = _csrf_delete_response(self.django_client,
                                         request_url,
                                         json.dumps(data),
                                         content_type="application/json")
        # Returns remaining link from 2nd Screen to first Plate
        response = json.loads(response.content)
        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_response_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]
Esempio n. 3
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 = _csrf_post_response_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_response_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 = _csrf_delete_response(self.django_client,
                                         request_url,
                                         json.dumps(data),
                                         content_type="application/json")
        # Returns remaining link from 2nd Screen to first Plate
        response = json.loads(response.content)
        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_response_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]
    def test_paste_move_remove_deletamany_image(self):

        # Add dataset
        request_url = reverse("manage_action_containers",
                              args=["addnewcontainer"])
        data = {
            'folder_type': 'dataset',
            'name': 'foobar'
        }
        _post_response(self.django_client, request_url, data)
        response = _csrf_post_response(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_response(self.django_client, request_url, data)
        _csrf_post_response(self.django_client,
                            request_url,
                            json.dumps(data),
                            content_type="application/json")

        # Unlink image from Dataset
        request_url = reverse("api_links")
        data = {
            'dataset': {did: {'image': [img.id.val]}}
        }
        _delete_response(self.django_client, request_url, data)
        response = _csrf_delete_response(self.django_client,
                                         request_url,
                                         json.dumps(data),
                                         content_type="application/json")
        # Response will contain remaining links from image (see test_links.py)
        response = json.loads(response.content)
        assert response == {"success": True}
Esempio n. 5
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 = _csrf_post_response_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_response_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 = _csrf_delete_response(self.django_client,
                                         links_url,
                                         json.dumps(data),
                                         content_type="application/json")
        response = json.loads(response.content)
        assert response["success"]

        # Since the Delete is ansync - need to check repeatedly for deletion
        for i in range(10):
            rsp = _get_response_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
Esempio n. 6
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 = _csrf_post_response_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_response_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 = _csrf_delete_response(self.django_client,
                                         links_url,
                                         json.dumps(data),
                                         content_type="application/json")
        response = json.loads(response.content)
        assert response["success"]

        # Since the Delete is ansync - need to check repeatedly for deletion
        for i in range(10):
            rsp = _get_response_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