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)
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'])
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)