コード例 #1
0
    def test_annotation_creation(self):
        self.fake_authentication()

        neuron_ids = [2365, 2381]
        # Expect entity 2365 and 2381 to be not annotated
        for nid in neuron_ids:
            aq = create_annotation_query(self.test_project_id, {'neuron_id': nid})
            self.assertEqual(len(aq), 0)

        # Annotate both with the same annotation
        _annotate_entities(self.test_project_id, neuron_ids,
                {'myannotation': {'user_id': self.test_user_id}})

        # Expect entity 2365 and 2381 to be annotated
        for nid in neuron_ids:
            aq = create_annotation_query(self.test_project_id, {'neuron_id': nid})
            self.assertEqual(len(aq), 1)
            self.assertEqual(aq[0].name, 'myannotation')

        # Annotate both with the pattern annotation
        _annotate_entities(self.test_project_id, neuron_ids,
                {'pattern {n9} test-{n}-annotation': { 'user_id': self.test_user_id}})

        # Expect entity 2365 and 2381 to be annotated
        aq = create_annotation_query(self.test_project_id, {'neuron_id': 2365}).order_by('name')
        self.assertEqual(len(aq), 2)
        self.assertEqual(aq[0].name, 'myannotation')
        self.assertEqual(aq[1].name, 'pattern 9 test-1-annotation')
        aq = create_annotation_query(self.test_project_id, {'neuron_id': 2381}).order_by('name')
        self.assertEqual(len(aq), 2)
        self.assertEqual(aq[0].name, 'myannotation')
        self.assertEqual(aq[1].name, 'pattern 10 test-2-annotation')
コード例 #2
0
    def test_rename_neuron_fail(self):
        self.fake_authentication()
        neuron_id = 362

        # Lock this neuron for another user
        _annotate_entities(self.test_project_id, [neuron_id],
                           {'locked': {
                               'user_id': 1
                           }})

        count_logs = lambda: Log.objects.all().count()
        log_count = count_logs()
        old_name = ClassInstance.objects.get(id=neuron_id).name
        new_name = 'newname'
        self.assertFalse(old_name == new_name)

        url = f'/{int(self.test_project_id)}/neurons/{neuron_id}/rename'
        response = self.client.post(url, {'name': new_name})
        self.assertEqual(response.status_code, 403)
        parsed_response = json.loads(response.content.decode('utf-8'))
        self.assertTrue('error' in parsed_response)
        self.assertTrue(parsed_response['error'])

        self.assertEqual(old_name,
                         ClassInstance.objects.get(id=neuron_id).name)
        self.assertEqual(log_count, count_logs())
コード例 #3
0
    def test_export_compact_skeleton_with_annotations(self):
        self.fake_authentication()

        skeleton_id = 373
        neuron_id = 374
        _, new_annotations, existing = _annotate_entities(self.test_project_id,
                [neuron_id], {'myannotation': {'user_id': self.test_user_id}})
        new_annotation_link_id = new_annotations.pop()
        url = '/%d/%d/1/1/compact-skeleton' % (self.test_project_id, skeleton_id)
        response = self.client.get(url, {
            'with_annotations': True
        })
        self.assertStatus(response)
        parsed_response = json.loads(response.content.decode('utf-8'))
        expected_response = [
                [[377, None, 3, 7620.0, 2890.0, 0.0, -1.0, 5],
                 [403, 377, 3, 7840.0, 2380.0, 0.0, -1.0, 5],
                 [405, 377, 3, 7390.0, 3510.0, 0.0, -1.0, 5],
                 [407, 405, 3, 7080.0, 3960.0, 0.0, -1.0, 5],
                 [409, 407, 3, 6630.0, 4330.0, 0.0, -1.0, 5]],
                [[377, 356, 1, 6730.0, 2700.0, 0.0],
                 [409, 421, 1, 6260.0, 3990.0, 0.0]],
                {"uncertain end": [403]},
                [],
                [[new_annotation_link_id]]]
        self.assertEqual(len(parsed_response), len(expected_response))
        self.assertCountEqual(parsed_response[0], expected_response[0])
        self.assertCountEqual(parsed_response[1], expected_response[1])
        self.assertEqual(parsed_response[2], expected_response[2])
        self.assertEqual(parsed_response[3], expected_response[3])
        self.assertEqual(parsed_response[4], expected_response[4])
コード例 #4
0
ファイル: test_neurons.py プロジェクト: catmaid/CATMAID
    def test_rename_neuron_fail(self):
        self.fake_authentication()
        neuron_id = 362

        # Lock this neuron for another user
        _annotate_entities(self.test_project_id, [neuron_id],
                {'locked': { 'user_id': 1 }})

        count_logs = lambda: Log.objects.all().count()
        log_count = count_logs()
        old_name = ClassInstance.objects.get(id=neuron_id).name
        new_name = 'newname'
        self.assertFalse(old_name == new_name)

        url = '/%d/neurons/%s/rename' % (self.test_project_id, neuron_id)
        response = self.client.post(url, {'name': new_name})
        self.assertEqual(response.status_code, 200)
        parsed_response = json.loads(response.content.decode('utf-8'))
        self.assertTrue('error' in parsed_response)
        self.assertTrue(parsed_response['error'])

        self.assertEqual(old_name, ClassInstance.objects.get(id=neuron_id).name)
        self.assertEqual(log_count, count_logs())