Esempio n. 1
0
    def test_nodule_list_viewset(self):
        # first try an endpoint without a nodule
        url = reverse('nodule-list')
        response = self.client.get(url)
        payload = response.json()
        self.assertListEqual(payload, [])

        # now create nodules and figure out what we expect to see in the list
        case = CaseFactory()
        candidates = CandidateFactory.create_batch(size=3, case=case)
        nodules = []
        for candidate in candidates:
            nodule, _ = candidate.get_or_create_nodule()
            nodules.append(nodule)
        serialized = [
            NoduleSerializer(n, context={'request': None}) for n in nodules
        ]
        expecteds = [json.loads(json.dumps(s.data)) for s in serialized]

        # check the actual response
        response = self.client.get(url)
        payload = response.json()
        self.maxDiff = 2000
        for actual, expected in zip(payload, expecteds):
            self.assertDictEqual(actual['candidate']['centroid'],
                                 expected['candidate']['centroid'])
            self.assertEqual(actual['url'], expected['url'])
Esempio n. 2
0
 def test_candidates_dismiss(self):
     series = ImageSeriesFactory(patient_id='42', series_instance_uid='13', uri='/images/1.dcm')
     new_case = CaseFactory(series=series)
     candidate = CandidateFactory(case=new_case)
     url = reverse('candidate-detail', kwargs={'pk': candidate.pk})
     resp = self.client.patch(url, {'review_result': enums.CandidateReviewResult.DISMISSED.value})
     self.assertEqual(resp.status_code, status.HTTP_200_OK)
     candidate.refresh_from_db()
     self.assertEquals(candidate.review_result, enums.CandidateReviewResult.DISMISSED.value)
Esempio n. 3
0
class SmokeTest(APITestCase):
    def assertDictEqual(self, a, b):
        # test all items
        for k, v in a.items():
            self.assertIn(k, b)
            self.assertEqual(v, b.pop(k))

        # make sure non left
        self.assertFalse(len(b))

    def test_create_case(self):
        case = CaseFactory()
        self.assertIsNotNone(case.series)
Esempio n. 4
0
    def test_nodule_list_viewset(self):
        # first try an endpoint without a nodule
        url = reverse('nodule-list')
        response = self.client.get(url)
        payload = response.json()
        self.assertListEqual(payload, [])

        # now create a nodule and figure out what we expect to see in the list
        case = CaseFactory()
        nodules = NoduleFactory.create_batch(size=3, case=case)
        serialized = [NoduleSerializer(n, context={'request': None}) for n in nodules]
        expected = [s.data for s in serialized]

        # check the actual response
        response = self.client.get(url)
        payload = response.json()
        self.assertListEqual(payload, expected)
Esempio n. 5
0
    def test_report(self):
        url = reverse('case-report', kwargs={'pk': 0})
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

        series = ImageSeriesFactory(patient_id='42', series_instance_uid='13', uri='/images/1.dcm')
        new_case = CaseFactory(series=series)
        centroid1 = ImageLocationFactory(x=1, y=2, z=3)
        candidate1 = CandidateFactory(case=new_case, centroid=centroid1, probability_concerning=0.8)
        centroid2 = ImageLocationFactory(x=10, y=20, z=30)
        candidate2 = CandidateFactory(case=new_case, centroid=centroid2, probability_concerning=0.98)
        nodule1, _ = candidate1.get_or_create_nodule()
        nodule2, _ = candidate2.get_or_create_nodule()

        url = reverse('case-detail', kwargs={'pk': new_case.pk})
        response = self.client.get(url)
        expected = {
            'patient_id': '42',
            'series_instance_uid': '13',
            'uri': '/images/1.dcm',
            'url': '/api/images/9/',
            'images': [],
        }
        self.assertDictEqual(expected, response.data['series'])

        candidate1_dict = dict(response.data['candidates'][0])
        self.assertEqual(candidate1_dict['probability_concerning'], 0.8)
        self.assertEqual(candidate1_dict['centroid']['x'], nodule1.candidate.centroid.x)
        self.assertEqual(candidate1_dict['centroid']['y'], nodule1.candidate.centroid.y)
        self.assertEqual(candidate1_dict['centroid']['z'], nodule1.candidate.centroid.z)

        candidate2_dict = response.data['candidates'][1]
        self.assertEqual(candidate2_dict['probability_concerning'], 0.98)
        self.assertEqual(candidate2_dict['centroid']['x'], nodule2.candidate.centroid.x)
        self.assertEqual(candidate2_dict['centroid']['y'], nodule2.candidate.centroid.y)
        self.assertEqual(candidate2_dict['centroid']['z'], nodule2.candidate.centroid.z)

        nodule1_dict = response.data['nodules'][0]
        self.assertEqual(nodule1_dict['candidate']['centroid']['x'], nodule1.candidate.centroid.x)
        self.assertEqual(nodule1_dict['candidate']['centroid']['y'], nodule1.candidate.centroid.y)
        self.assertEqual(nodule1_dict['candidate']['centroid']['z'], nodule1.candidate.centroid.z)

        nodule2_dict = response.data['nodules'][1]
        self.assertEqual(nodule2_dict['candidate']['centroid']['x'], nodule2.candidate.centroid.x)
        self.assertEqual(nodule2_dict['candidate']['centroid']['y'], nodule2.candidate.centroid.y)
        self.assertEqual(nodule2_dict['candidate']['centroid']['z'], nodule2.candidate.centroid.z)
Esempio n. 6
0
class SmokeTest(TestCase):
    def test_create_case(self):
        case = CaseFactory()
        self.assertIsNotNone(case.series)