Esempio n. 1
0
 def setUp(self):
     super().setUp()
     self.gps = GenePanelSnapshotFactory(panel__status=GenePanel.STATUS.public)
     self.gps_public = GenePanelSnapshotFactory(panel__status=GenePanel.STATUS.public)
     self.gpes = GenePanelEntrySnapshotFactory(panel=self.gps_public)
     self.gpes_internal = GenePanelEntrySnapshotFactory(panel__panel__status=GenePanel.STATUS.internal)
     self.gpes_retired = GenePanelEntrySnapshotFactory(panel__panel__status=GenePanel.STATUS.retired)
     self.gpes_deleted = GenePanelEntrySnapshotFactory(panel__panel__status=GenePanel.STATUS.deleted)
     self.genes = GenePanelEntrySnapshotFactory.create_batch(4, panel=self.gps)
     self.str = STRFactory(panel__panel__status=GenePanel.STATUS.public)
     self.region = RegionFactory(panel__panel__status=GenePanel.STATUS.public)
     self.region2 = RegionFactory(panel__panel__status=GenePanel.STATUS.public, position_37=None)
Esempio n. 2
0
    def test_add_evaluation_comments_only(self):
        """Add comments"""

        region = RegionFactory()
        current_version = region.panel.version
        region.evaluation.all().delete()
        url = reverse_lazy('panels:review_entity', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })

        region_data = {
            "comments": fake.sentence(),
        }
        res = self.client.post(url, region_data)
        assert res.status_code == 302

        v01gene = region.panel.panel.active_panel.get_region(region.name)
        assert v01gene.evaluation.get(user=self.gel_user).comments.count() == 1

        region_data = {
            "comments": fake.sentence(),
        }
        res = self.client.post(url, region_data)

        assert v01gene.evaluation.get(user=self.gel_user).comments.count() == 2
        assert current_version == region.panel.panel.active_panel.version
Esempio n. 3
0
    def test_add_evaluation(self):
        """Add an evaluation"""

        region = RegionFactory()
        region.evaluation.all().delete()
        region.panel.update_saved_stats()
        url = reverse_lazy('panels:review_entity', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })

        current_version = region.panel.version

        number_of_evaluated_genes = region.panel.stats.get('number_of_evaluated_regions')

        region_data = {
            "rating": Evaluation.RATINGS.AMBER,
            "current_diagnostic": True,
            "comments": fake.sentence(),
            "publications": ";".join([fake.sentence(), fake.sentence()]),
            "phenotypes": ";".join([fake.sentence(), fake.sentence(), fake.sentence()]),
            "moi": [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity": [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
        }
        res = self.client.post(url, region_data)
        assert res.status_code == 302
        assert number_of_evaluated_genes + 1 == region.panel.panel.active_panel.stats.get('number_of_evaluated_regions')
        assert current_version == region.panel.panel.active_panel.version
Esempio n. 4
0
 def test_region_review_view(self):
     gene = GeneFactory()
     gps = GenePanelSnapshotFactory()
     region = RegionFactory(panel=gps, gene_core=gene)
     url = reverse_lazy('panels:review_entity', args=(region.panel.panel.pk, 'region', region.name,))
     r = self.client.get(url)
     self.assertEqual(r.status_code, 200)
Esempio n. 5
0
    def test_form_should_be_prefilled(self):
        region = RegionFactory()
        region.evaluation.all().delete()
        url = reverse_lazy('panels:review_entity', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })

        region_data = {
            "rating": Evaluation.RATINGS.AMBER,
            "current_diagnostic": True,
            "publications": ";".join([fake.sentence(), fake.sentence()]),
            "moi": [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity": [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
        }

        self.client.post(url, region_data)

        url = reverse_lazy('panels:evaluation', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })
        res = self.client.get(url)
        assert res.content.find(str.encode('<option value="{}" selected>'.format(region_data['moi']))) != -1
Esempio n. 6
0
    def test_edit_region_in_panel(self):
        region = RegionFactory()
        url = reverse_lazy('panels:edit_entity',
                           kwargs={
                               'pk': region.panel.panel.pk,
                               'entity_type': 'region',
                               'entity_name': region.name
                           })

        number_of_regions = region.panel.stats.get('number_of_regions')

        # make sure new data has at least 1 of the same items
        source = region.evidence.last().name

        publication = region.publications[0]
        phenotype = region.publications[1]

        new_evidence = Evidence.ALL_SOURCES[randint(0, 9)]
        original_evidences = set([ev.name for ev in region.evidence.all()])
        original_evidences.add(new_evidence)

        region_data = {
            'name': region.name,
            'chromosome': '1',
            'position_37_0': '12345',
            'position_37_1': '12346',
            'position_38_0': '12345',
            'position_38_1': '123456',
            'haploinsufficiency_score':
            choice(Region.DOSAGE_SENSITIVITY_SCORES)[0],
            'triplosensitivity_score':
            choice(Region.DOSAGE_SENSITIVITY_SCORES)[0],
            'required_overlap_percentage': randint(0, 100),
            "gene": region.gene_core.pk,
            "gene_name": "Gene name",
            "source": set([source, new_evidence]),
            "tags": [
                TagFactory().pk,
            ] + [tag.name for tag in region.tags.all()],
            "publications": ";".join([publication,
                                      fake.sentence()]),
            "phenotypes":
            ";".join([phenotype, fake.sentence(),
                      fake.sentence()]),
            "moi": [x
                    for x in Evaluation.MODES_OF_INHERITANCE][randint(1,
                                                                      12)][0],
            "penetrance": Region.PENETRANCE.Incomplete,
            "type_of_variants": Region.VARIANT_TYPES.small,
        }
        res = self.client.post(url, region_data)
        assert res.status_code == 302
        new_region = GenePanel.objects.get(
            pk=region.panel.panel.pk).active_panel.get_region(region.name)
        assert region.panel.panel.active_panel.version != region.panel.version
        new_current_number = new_region.panel.panel.active_panel.stats.get(
            'number_of_regions')
        assert number_of_regions == new_current_number
        self.assertEqual(int(region_data['position_37_1']),
                         new_region.position_37.upper)
Esempio n. 7
0
    def test_delete_evaluation(self):
        region = RegionFactory()
        region.evaluation.all().delete()

        evaluation_url = reverse_lazy('panels:review_entity', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })

        gene_data = {
            "rating": Evaluation.RATINGS.AMBER,
            "current_diagnostic": True,
            "comments": fake.sentence(),
            "publications": ";".join([fake.sentence(), fake.sentence()]),
            "phenotypes": ";".join([fake.sentence(), fake.sentence(), fake.sentence()]),
            "moi": [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity": [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
        }
        self.client.post(evaluation_url, gene_data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel.get_region(region.name)
        assert gene.panel.version == region.panel.version
        assert gene.is_reviewd_by_user(self.gel_user) is True

        delete_evaluation_url = reverse_lazy('panels:delete_evaluation_by_user', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name,
            'evaluation_pk': region.evaluation.get(user=self.gel_user).pk
        })
        res = self.client.get(delete_evaluation_url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        last_gene = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel.get_region(region.name)
        assert res.json().get('status') == 200
        assert last_gene.is_reviewd_by_user(self.gel_user) is False
        assert gene.panel.version == last_gene.panel.version
Esempio n. 8
0
    def test_change_evaluation(self):
        region = RegionFactory()
        current_version = region.panel.version
        region.evaluation.all().delete()
        url = reverse_lazy('panels:review_entity', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })

        old_phenotypes = [fake.sentence(), fake.sentence(), fake.sentence()]
        gene_data = {
            "rating": Evaluation.RATINGS.AMBER,
            "current_diagnostic": True,
            "comments": fake.sentence(),
            "publications": ";".join([fake.sentence(), fake.sentence()]),
            "phenotypes": ";".join(old_phenotypes),
            "moi": [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity": [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
        }
        self.client.post(url, gene_data)
        assert Evaluation.objects.filter(user=self.gel_user).count() == 1

        gene_data = {
            "moi": [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity": [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
        }
        self.client.post(url, gene_data)
        assert Evaluation.objects.filter(user=self.gel_user).count() == 1
        assert Evaluation.objects.get(user=self.gel_user).phenotypes == old_phenotypes
        assert current_version == region.panel.panel.active_panel.version
Esempio n. 9
0
    def test_add_tag_via_edit_details(self):
        """Set tags via edit gene detail section"""

        region = RegionFactory(penetrance=Region.PENETRANCE.Incomplete)
        url = reverse_lazy('panels:edit_entity',
                           kwargs={
                               'pk': region.panel.panel.pk,
                               'entity_type': 'region',
                               'entity_name': region.name
                           })

        tag = TagFactory(name='some tag')

        region_data = {
            'name':
            region.name,
            'chromosome':
            '1',
            'position_37_0':
            '12345',
            'position_37_1':
            '12346',
            'position_38_0':
            '12345',
            'position_38_1':
            '123456',
            'haploinsufficiency_score':
            choice(Region.DOSAGE_SENSITIVITY_SCORES)[0],
            'triplosensitivity_score':
            choice(Region.DOSAGE_SENSITIVITY_SCORES)[0],
            'required_overlap_percentage':
            randint(0, 100),
            "gene":
            region.gene_core.pk,
            "gene_name":
            "Gene name",
            "source":
            set([ev.name for ev in region.evidence.all()]),
            "tags": [tag.pk for tag in region.tags.all()] + [
                tag.pk,
            ],
            "publications":
            ";".join([publication for publication in region.publications]),
            "phenotypes":
            ";".join([phenotype for phenotype in region.phenotypes]),
            "type_of_variants":
            Region.VARIANT_TYPES.small,
            "moi":
            region.moi,
            "penetrance":
            Region.PENETRANCE.Complete,
        }
        res = self.client.post(url, region_data)
        assert res.status_code == 302
        new_region = GenePanel.objects.get(
            pk=region.panel.panel.pk).active_panel.get_region(region.name)
        assert sorted(list(new_region.tags.all())) != sorted(
            list(region.tags.all()))
Esempio n. 10
0
    def test_user_reviews(self):
        gps = GenePanelSnapshotFactory()
        region = RegionFactory.create_batch(10, panel=gps)
        for g in region:
            for evaluation in g.evaluation.all():
                evaluation.user = self.verified_user
                evaluation.save()

        self.assertEqual(self.verified_user.get_recent_evaluations().count(), 35)
Esempio n. 11
0
    def test_download_all_regions(self):
        gpes = GenePanelEntrySnapshotFactory()
        gps = gpes.panel
        region = RegionFactory(panel=gps)

        res = self.client.get(reverse_lazy('panels:download_regions'))
        self.assertEqual(res.status_code, 200)
        self.assertTrue(b"".join(res.streaming_content).find(
            region.verbose_name.encode()) != 1)
Esempio n. 12
0
    def test_edit_region_name_ajax(self):
        region = RegionFactory()
        url = reverse_lazy('panels:edit_entity',
                           kwargs={
                               'pk': region.panel.panel.pk,
                               'entity_type': 'region',
                               'entity_name': region.name
                           })

        old_region_name = region.name

        # make sure new data has at least 1 of the same items
        source = region.evidence.last().name
        publication = region.publications[0]
        phenotype = region.publications[1]

        gene_data = {
            'name': 'NewRegion',
            'chromosome': '1',
            'position_37_0': '12345',
            'position_37_1': '12346',
            'position_38_0': '12345',
            'position_38_1': '123456',
            'haploinsufficiency_score':
            choice(Region.DOSAGE_SENSITIVITY_SCORES)[0],
            'triplosensitivity_score':
            choice(Region.DOSAGE_SENSITIVITY_SCORES)[0],
            'required_overlap_percentage': randint(0, 100),
            "gene": region.gene_core.pk,
            "gene_name": "Other name",
            "source": set([source, Evidence.ALL_SOURCES[randint(0, 9)]]),
            "tags": [
                TagFactory().pk,
            ] + [tag.name for tag in region.tags.all()],
            "publications": ";".join([publication,
                                      fake.sentence()]),
            "phenotypes":
            ";".join([phenotype, fake.sentence(),
                      fake.sentence()]),
            "moi": [x
                    for x in Evaluation.MODES_OF_INHERITANCE][randint(1,
                                                                      12)][0],
            "type_of_variants": Region.VARIANT_TYPES.small,
            "penetrance": Region.PENETRANCE.Incomplete,
        }
        res = self.client.post(url, gene_data)
        assert res.status_code == 302

        new_gps = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel
        old_gps = GenePanelSnapshot.objects.get(pk=region.panel.pk)

        # check panel has no previous gene
        assert new_gps.has_region(old_region_name) is False

        # test previous panel contains old gene
        assert old_gps.has_region(old_region_name) is True
Esempio n. 13
0
 def test_region_evaluation(self):
     region = RegionFactory()
     url = reverse_lazy('panels:evaluation',
                        kwargs={
                            'pk': region.panel.panel.pk,
                            'entity_type': 'region',
                            'entity_name': region.name
                        })
     res = self.client.get(url)
     assert res.status_code == 200
Esempio n. 14
0
    def test_download_panel_contains_regions(self):
        gpes = GenePanelEntrySnapshotFactory()
        gps = gpes.panel
        RegionFactory(panel=gps)

        res = self.client.get(
            reverse_lazy('panels:download_panel_tsv',
                         args=(gps.panel.pk, '01234')))
        self.assertEqual(res.status_code, 200)
        self.assertTrue(res.content.find(b'region') != 1)
Esempio n. 15
0
    def test_remove_publication(self):
        """Remove a publication to a gene panel entry"""

        region = RegionFactory(penetrance=Region.PENETRANCE.Incomplete)
        region.publications = [fake.sentence(), fake.sentence()]
        region.save()

        url = reverse_lazy('panels:edit_entity',
                           kwargs={
                               'pk': region.panel.panel.pk,
                               'entity_type': 'region',
                               'entity_name': region.name
                           })

        region_data = {
            'name': region.name,
            'chromosome': '1',
            'position_37_0': '12345',
            'position_37_1': '12346',
            'position_38_0': '12345',
            'position_38_1': '123456',
            'haploinsufficiency_score':
            choice(Region.DOSAGE_SENSITIVITY_SCORES)[0],
            'triplosensitivity_score':
            choice(Region.DOSAGE_SENSITIVITY_SCORES)[0],
            'required_overlap_percentage': randint(0, 100),
            "gene": region.gene_core.pk,
            "gene_name": "Gene name",
            "source": set([ev.name for ev in region.evidence.all()]),
            "tags": [tag.name for tag in region.tags.all()],
            "publications": ";".join(region.publications[:1]),
            "phenotypes":
            ";".join([phenotype for phenotype in region.phenotypes]),
            "type_of_variants": Region.VARIANT_TYPES.small,
            "moi": region.moi,
            "penetrance": Region.PENETRANCE.Complete,
        }
        res = self.client.post(url, region_data)
        assert res.status_code == 302
        new_region = GenePanel.objects.get(
            pk=region.panel.panel.pk).active_panel.get_region(region.name)
        assert new_region.publications == region.publications[:1]
Esempio n. 16
0
    def test_mark_as_ready_no_gene(self):
        region = RegionFactory(gene=None)
        region.evaluation.all().delete()
        url = reverse_lazy('panels:mark_entity_as_ready', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })

        self.client.post(url, {'ready_comment': fake.sentence()})
        gene = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel.get_region(region.name)
        assert gene.ready is True
Esempio n. 17
0
    def test_edit_region_name_unit(self):
        region = RegionFactory()
        old_region_name = region.name

        ap = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel

        assert ap.has_region(old_region_name) is True
        new_data = {"name": 'NewRegion'}
        ap.update_region(self.verified_user, old_region_name, new_data)

        new_ap = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel
        assert new_ap.has_region(old_region_name) is False
        assert new_ap.has_region('NewRegion') is True
Esempio n. 18
0
    def test_edit_comment(self):
        region = RegionFactory()
        current_version = region.panel.version

        evaluation_url = reverse_lazy('panels:review_entity', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })

        comment = fake.sentence()

        gene_data = {
            "rating": Evaluation.RATINGS.AMBER,
            "current_diagnostic": True,
            "comments": comment,
            "publications": ";".join([fake.sentence(), fake.sentence()]),
            "phenotypes": ";".join([fake.sentence(), fake.sentence(), fake.sentence()]),
            "moi": [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity": [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
        }
        self.client.post(evaluation_url, gene_data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel.get_region(region.name)
        evaluation = gene.evaluation.get(user=self.gel_user)

        assert evaluation.comments.first().comment == comment

        get_comment_url = reverse_lazy('panels:edit_comment_by_user', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name,
            'comment_pk': evaluation.comments.first().pk
        })
        res = self.client.get(get_comment_url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        self.assertEqual(res.status_code, 200)

        new_comment = fake.sentence()
        edit_comment_url = reverse_lazy('panels:submit_edit_comment_by_user', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name,
            'comment_pk': evaluation.comments.first().pk
        })
        res = self.client.post(edit_comment_url, {'comment': new_comment})
        assert res.status_code == 302
        assert evaluation.comments.first().comment == new_comment
        assert current_version == region.panel.panel.active_panel.version
    def test_type_of_variants_added(self):
        region = RegionFactory()
        gps = GenePanelSnapshotFactory()
        url = reverse_lazy('panels:add_entity',
                           kwargs={
                               'pk': gps.panel.pk,
                               'entity_type': 'region'
                           })

        source = region.evidence.last().name
        publication = region.publications[0]
        phenotype = region.publications[1]

        region_data = {
            'name': region.name,
            'chromosome': '1',
            'position_37_0': '12345',
            'position_37_1': '12346',
            'position_38_0': '12345',
            'position_38_1': '123456',
            'haploinsufficiency_score':
            choice(Region.DOSAGE_SENSITIVITY_SCORES)[0],
            'triplosensitivity_score': '',
            'required_overlap_percentage': randint(0, 100),
            "gene": region.gene_core.pk,
            "gene_name": "Other name",
            "source": set([source, Evidence.ALL_SOURCES[randint(0, 9)]]),
            "tags": [
                TagFactory().pk,
            ] + [tag.name for tag in region.tags.all()],
            "publications": ";".join([publication,
                                      fake.sentence()]),
            "phenotypes":
            ";".join([phenotype, fake.sentence(),
                      fake.sentence()]),
            "moi":
            [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "type_of_variants": Region.VARIANT_TYPES.small,
            "penetrance": Region.PENETRANCE.Incomplete,
        }
        res = self.client.post(url, region_data)
        self.assertEqual(res.status_code, 302)
        panel = gps.panel.active_panel

        assert panel.get_region(
            region.name).type_of_variants == region_data['type_of_variants']
Esempio n. 20
0
    def test_curator_comment_added(self):
        region = RegionFactory()
        region.evaluation.all().delete()
        url = reverse_lazy('panels:update_entity_rating', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })

        new_status = 0
        data = {'comment': fake.sentence(), 'status': new_status}

        res = self.client.post(url, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel.get_region(region.name)

        assert res.content.find(str.encode(data['comment'])) != -1
        assert gene.evaluation.count() > 0
Esempio n. 21
0
    def test_update_rating(self):
        region = RegionFactory()
        region.evaluation.all().delete()
        url = reverse_lazy('panels:update_entity_rating', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })

        new_status = 0
        data = {'comment': fake.sentence(), 'status': new_status}

        res = self.client.post(url, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel.get_region(region.name)
        assert res.json().get('status') == 200
        assert Comment.objects.count() == 1
        assert res.content.find(str.encode(data['comment'])) != -1
        assert gene.saved_gel_status == new_status

        new_status = 1
        data = {'comment': fake.sentence(), 'status': new_status}

        res = self.client.post(url, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel.get_region(region.name)
        assert res.json().get('status') == 200
        assert Comment.objects.count() == 3
        assert gene.saved_gel_status == new_status

        new_status = 2
        data = {'comment': fake.sentence(), 'status': new_status}

        res = self.client.post(url, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel.get_region(region.name)
        assert res.json().get('status') == 200
        assert Comment.objects.count() == 6
        assert gene.saved_gel_status == new_status

        new_status = 3
        data = {'comment': fake.sentence(), 'status': new_status}

        res = self.client.post(url, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel.get_region(region.name)
        assert res.json().get('status') == 200
        assert Comment.objects.count() == 10
        assert gene.saved_gel_status == new_status
        assert gene.panel.version != region.panel.version
Esempio n. 22
0
    def test_update_tags(self):
        region = RegionFactory()
        current_version = region.panel.version
        region.evaluation.all().delete()
        url = reverse_lazy('panels:update_entity_tags', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })

        tag1 = TagFactory()
        tag2 = TagFactory()

        res = self.client.post(url, {'tags': [tag1.pk, tag2.pk]}, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel.get_region(region.name)
        assert res.json().get('status') == 200
        assert gene.tags.count() == 2
        assert current_version == region.panel.panel.active_panel.version
Esempio n. 23
0
    def test_update_moi(self):
        region = RegionFactory()
        region.evaluation.all().delete()
        url = reverse_lazy('panels:update_entity_moi', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })

        moi = [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 2)]
        data = {'comment': fake.sentence(), 'moi': moi[1]}

        res = self.client.post(url, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel.get_region(region.name)
        assert res.json().get('status') == 200
        assert Comment.objects.count() == 1
        assert gene.moi == moi[1]
        assert gene.panel.version != region.panel.version
Esempio n. 24
0
    def test_update_publications(self):
        region = RegionFactory()
        region.evaluation.all().delete()
        url = reverse_lazy('panels:update_entity_publications', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })

        publications_array = [fake.word(), fake.word()]
        publications = "{}; {}".format(publications_array[0], publications_array[1])
        data = {'comment': fake.sentence(), 'publications': publications}

        res = self.client.post(url, data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel.get_region(region.name)
        assert res.json().get('status') == 200
        assert Comment.objects.count() == 1
        assert gene.publications == publications_array
        assert gene.panel.version != region.panel.version
Esempio n. 25
0
    def test_update_region_preserves_comments_order(self):
        region = RegionFactory()
        comments = list(CommentFactory.create_batch(4,
                                                    user=self.verified_user))

        for ev in region.evaluation.all():
            ev.comments.add(comments.pop())

        max_comments_num = max(
            [e.comments.count() for e in region.evaluation.all()])
        self.assertEqual(1, max_comments_num)

        old_region_name = region.name
        ap = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel

        new_data = {"name": 'NewRegion'}
        ap.update_region(self.verified_user, old_region_name, new_data)

        new_ap = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel
        new_region = new_ap.get_region('NewRegion')

        max_comments_num_after_update = max(
            [e.comments.count() for e in new_region.evaluation.all()])
        self.assertEqual(1, max_comments_num_after_update)
Esempio n. 26
0
    def test_delete_comment(self):
        region = RegionFactory()
        current_version = region.panel.version

        evaluation_url = reverse_lazy('panels:review_entity', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })

        gene_data = {
            "rating": Evaluation.RATINGS.AMBER,
            "current_diagnostic": True,
            "comments": fake.sentence(),
            "publications": ";".join([fake.sentence(), fake.sentence()]),
            "phenotypes": ";".join([fake.sentence(), fake.sentence(), fake.sentence()]),
            "moi": [x for x in Evaluation.MODES_OF_INHERITANCE][randint(1, 12)][0],
            "mode_of_pathogenicity": [x for x in Evaluation.MODES_OF_PATHOGENICITY][randint(1, 2)][0],
        }
        self.client.post(evaluation_url, gene_data, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        gene = GenePanel.objects.get(pk=region.panel.panel.pk).active_panel.get_region(region.name)
        evaluation = gene.evaluation.get(user=self.gel_user)

        assert evaluation.comments.count() == 1

        delete_comment_url = reverse_lazy('panels:delete_comment_by_user', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name,
            'comment_pk': evaluation.comments.first().pk
        })
        res = self.client.get(delete_comment_url, HTTP_X_REQUESTED_WITH='XMLHttpRequest')
        assert res.json().get('status') == 200
        assert evaluation.comments.count() == 0
        assert res.content.find(str.encode('Your review')) != -1
        assert current_version == region.panel.panel.active_panel.version
Esempio n. 27
0
    def test_add_review_after_comment(self):
        """When you add a comment and then want to add a review it should be logged"""

        region = RegionFactory()
        current_version = region.panel.version
        region.evaluation.all().delete()
        url = reverse_lazy('panels:review_entity', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })

        gene_data = {
            "comments": fake.sentence(),
        }
        res = self.client.post(url, gene_data)
        assert res.status_code == 302

        v01gene = region.panel.panel.active_panel.get_region(region.name)
        assert v01gene.evaluation.get(user=self.gel_user).comments.count() == 1

        review_data = {
            "rating": Evaluation.RATINGS.AMBER,
            "current_diagnostic": True,
            "comments": fake.sentence(),
            "publications": ";".join([fake.sentence(), fake.sentence()]),
        }
        url_review = reverse_lazy('panels:review_entity', kwargs={
            'pk': region.panel.panel.pk,
            'entity_type': 'region',
            'entity_name': region.name
        })
        self.client.post(url_review, review_data)
        res_review = self.client.get(url_review)
        assert res_review.content.find(str.encode(review_data['publications'])) != -1
        assert current_version == region.panel.panel.active_panel.version
Esempio n. 28
0
    def test_update_ensembl(self):
        gene_symbol = 'FAM58A'
        gene_to_update = GeneFactory(gene_symbol=gene_symbol)
        ensembl_data = {
            "GRch37": {
                "82": {
                    "ensembl_id": "ENSG00000147382",
                    "location": "X:152853377-152865500"
                }
            },
            "GRch38": {
                "90": {
                    "ensembl_id": "ENSG00000262919",
                    "location": "X:153587919-153600045"
                }
            }
        }
        json_data = {gene_symbol: ensembl_data}

        gps = GenePanelSnapshotFactory()
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps)  # random genes
        GenePanelEntrySnapshotFactory.create(gene_core=gene_to_update,
                                             panel=gps)
        STRFactory.create_batch(2, panel=gps)  # random STRs
        STRFactory.create(gene_core=gene_to_update, panel=gps)
        RegionFactory.create_batch(2, panel=gps)  # random STRs
        RegionFactory.create(gene_core=gene_to_update, panel=gps)

        gps_2 = GenePanelSnapshotFactory()
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps_2)  # random genes
        STRFactory.create_batch(2, panel=gps_2)  # random STRs
        RegionFactory.create_batch(2, panel=gps_2)  # random STRs
        RegionFactory.create(gene_core=gene_to_update, panel=gps_2)

        # make sure ensembl data doesn't match
        for gene in GenePanelEntrySnapshot.objects.filter(
                gene__gene_symbol=gene_symbol):
            self.assertNotEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        for str in STR.objects.filter(gene__gene_symbol=gene_symbol):
            self.assertNotEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        for region in Region.objects.filter(gene__gene_symbol=gene_symbol):
            self.assertNotEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        gps_pk = gps.pk
        gps_version = gps.version
        gps_2_version = gps_2.version

        process(json_data)

        # make sure previous data didn't change
        for gene in GenePanelEntrySnapshot.objects.filter(
                gene__gene_symbol=gene_symbol, panel_id=gps_pk):
            self.assertNotEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        for str in STR.objects.filter(gene__gene_symbol=gene_symbol,
                                      panel_id=gps_pk):
            self.assertNotEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        for region in Region.objects.filter(gene__gene_symbol=gene_symbol,
                                            panel_id=gps_pk):
            self.assertNotEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        gps = gps.panel.active_panel
        gps_2 = gps_2.panel.active_panel

        self.assertNotEqual(gps_version, gps.version)
        self.assertNotEqual(gps_2_version, gps_2.version)

        # make sure new data has changed
        for gene in GenePanelEntrySnapshot.objects.filter(
                gene__gene_symbol=gene_symbol, panel=gps):
            self.assertEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        for str in STR.objects.filter(gene__gene_symbol=gene_symbol,
                                      panel=gps):
            self.assertEqual(gene.gene.get('ensembl_genes'), ensembl_data)

        for region in Region.objects.filter(gene__gene_symbol=gene_symbol,
                                            panel=gps):
            self.assertEqual(gene.gene.get('ensembl_genes'), ensembl_data)
Esempio n. 29
0
    def test_update_gene_collection(self):
        gene_to_update = GeneFactory()
        gene_to_delete = GeneFactory()
        gene_to_update_symbol = GeneFactory()

        gps = GenePanelSnapshotFactory()
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps)  # random genes
        GenePanelEntrySnapshotFactory.create(gene_core=gene_to_update,
                                             panel=gps)
        STRFactory.create_batch(2, panel=gps)  # random STRs
        STRFactory.create(gene_core=gene_to_update, panel=gps)
        RegionFactory.create_batch(2, panel=gps)  # random STRs
        RegionFactory.create(gene_core=gene_to_update, panel=gps)

        gps = GenePanelSnapshotFactory()
        GenePanelEntrySnapshotFactory.create_batch(2,
                                                   panel=gps)  # random genes
        STRFactory.create_batch(2, panel=gps)  # random STRs
        GenePanelEntrySnapshotFactory.create(gene_core=gene_to_update_symbol,
                                             panel=gps)
        STRFactory.create(gene_core=gene_to_update_symbol, panel=gps)
        RegionFactory.create_batch(2, panel=gps)  # random STRs
        RegionFactory.create(gene_core=gene_to_update_symbol, panel=gps)

        to_insert = [
            Gene(gene_symbol='A', ensembl_genes={
                'inserted': True
            }).dict_tr(),
            Gene(gene_symbol='B', ensembl_genes={
                'inserted': True
            }).dict_tr(),
        ]

        to_update = [
            Gene(gene_symbol=gene_to_update.gene_symbol,
                 ensembl_genes={
                     'updated': True
                 }).dict_tr()
        ]

        to_update_symbol = [(Gene(gene_symbol='C',
                                  ensembl_genes={
                                      'updated': True
                                  }).dict_tr(),
                             gene_to_update_symbol.gene_symbol)]

        to_delete = [gene_to_delete.gene_symbol]

        migration = {
            'insert': to_insert,
            'update': to_update,
            'delete': to_delete,
            'update_symbol': to_update_symbol
        }

        update_gene_collection(migration)

        self.assertTrue(GenePanelEntrySnapshot.objects.get_active().get(
            gene_core__gene_symbol=gene_to_update.gene_symbol).gene.get(
                'ensembl_genes')['updated'])

        self.assertTrue(STR.objects.get_active().get(
            gene_core__gene_symbol=gene_to_update.gene_symbol).gene.get(
                'ensembl_genes')['updated'])

        self.assertTrue(Region.objects.get_active().get(
            gene_core__gene_symbol=gene_to_update.gene_symbol).gene.get(
                'ensembl_genes')['updated'])

        updated_not_updated = [
            gpes.gene['ensembl_genes']
            for gpes in GenePanelEntrySnapshot.objects.filter(
                gene_core__gene_symbol=gene_to_update.gene_symbol)
        ]
        self.assertNotEqual(updated_not_updated[0], updated_not_updated[1])

        updated_not_updated = [
            str_item.gene['ensembl_genes'] for str_item in STR.objects.filter(
                gene_core__gene_symbol=gene_to_update.gene_symbol)
        ]
        self.assertNotEqual(updated_not_updated[0], updated_not_updated[1])

        updated_not_updated = [
            region_item.gene['ensembl_genes']
            for region_item in Region.objects.filter(
                gene_core__gene_symbol=gene_to_update.gene_symbol)
        ]
        self.assertNotEqual(updated_not_updated[0], updated_not_updated[1])

        self.assertFalse(
            GenePanelEntrySnapshot.objects.get(
                gene_core__gene_symbol=gene_to_update_symbol.gene_symbol).
            gene_core.active)

        self.assertFalse(
            STR.objects.get(gene_core__gene_symbol=gene_to_update_symbol.
                            gene_symbol).gene_core.active)

        self.assertFalse(
            Region.objects.get(gene_core__gene_symbol=gene_to_update_symbol.
                               gene_symbol).gene_core.active)

        self.assertFalse(
            Gene.objects.get(
                gene_symbol=gene_to_update_symbol.gene_symbol).active)
        self.assertFalse(
            Gene.objects.get(gene_symbol=gene_to_delete.gene_symbol).active)
        self.assertTrue(Gene.objects.get(gene_symbol='A').active)

        self.assertTrue(
            GenePanelEntrySnapshot.objects.get(gene_core__gene_symbol='C').
            gene.get('ensembl_genes')['updated'])

        self.assertTrue(
            STR.objects.get(gene_core__gene_symbol='C').gene.get(
                'ensembl_genes')['updated'])

        self.assertTrue(
            Region.objects.get(gene_core__gene_symbol='C').gene.get(
                'ensembl_genes')['updated'])