def LoadOp(line, succ): pr = Genotype( name=line['rs#'], study=Import.study, datasource=Import.ds, ) SaveKVs(pr, line) pr.save() return True
def test_query_csv_to_rows_different_fields(self): """ Tests that query_csv_to_rows creates the correct csv strings when given a query set of Genotype models that have different fields to each other """ expected_experi_model.switch_db(TEST_DB_ALIAS) expected_experi_model.save() expected_ds_model.switch_db(TEST_DB_ALIAS) expected_ds_model.save() date = datetime.datetime(2015, 11, 20, 11, 14, 40, round(386012, -2)) date_string = str(date) xreflsid = "Helge what even is this field anyway?" gen_1 = Genotype( name="foo", statuscode=3, obs={"chicken": "pie"}, study=expected_experi_model, datasource=expected_ds_model, xreflsid=xreflsid, createddate=date, dtt=date, lastupdateddate=date ) gen_1.switch_db(TEST_DB_ALIAS) gen_1.save() gen_2 = Genotype( name="bar", description="baz", obs={"chicken": "snitchel"}, study=expected_experi_model, datasource=expected_ds_model, lastupdatedby="Badi", createddate=date, dtt=date, lastupdateddate=date ) gen_2.switch_db(TEST_DB_ALIAS) gen_2.save() expected_rows = [ "alias,createddate,datasource__name,description,dtt,lastupdatedby,lastupdateddate,name," + "obs,statuscode,study__name,xreflsid", str.format( "unknown,{0},What is up,baz,{0},Badi,{0},bar,\"{{'chicken':'snitchel'}}\",1,What is up,", date_string ), str.format( "unknown,{0},What is up,,{0},,{0},foo,\"{{'chicken':'pie'}}\",3,What is up,{1}", date_string, xreflsid ) ] with switch_db(Genotype, TEST_DB_ALIAS) as TestGen: query = TestGen.objects.all() actual_rows = query_to_csv_rows_list(query, testing=True) self.assertEqual(len(expected_rows), len(actual_rows)) self.assertEqual(actual_rows[0], expected_rows[0]) # Checks header rows are equal # Checks csv representations of genotype docs are in actual_rows for row in expected_rows: with self.subTest(row=row): self.assertIn(row, actual_rows)
def test_query_csv_to_rows_different_fields(self): """ Tests that query_csv_to_rows creates the correct csv strings when given a query set of Genotype models that have different fields to each other """ expected_experi_model.switch_db(TEST_DB_ALIAS) expected_experi_model.save() expected_ds_model.switch_db(TEST_DB_ALIAS) expected_ds_model.save() date = datetime.datetime(2015, 11, 20, 11, 14, 40, round(386012, -2)) date_string = str(date) xreflsid = "Helge what even is this field anyway?" gen_1 = Genotype(name="foo", statuscode=3, obs={"chicken": "pie"}, study=expected_experi_model, datasource=expected_ds_model, xreflsid=xreflsid, createddate=date, dtt=date, lastupdateddate=date) gen_1.switch_db(TEST_DB_ALIAS) gen_1.save() gen_2 = Genotype(name="bar", description="baz", obs={"chicken": "snitchel"}, study=expected_experi_model, datasource=expected_ds_model, lastupdatedby="Badi", createddate=date, dtt=date, lastupdateddate=date) gen_2.switch_db(TEST_DB_ALIAS) gen_2.save() expected_rows = [ "alias,createddate,datasource__name,description,dtt,lastupdatedby,lastupdateddate,name," + "obs,statuscode,study__name,xreflsid", str.format( "unknown,{0},What is up,baz,{0},Badi,{0},bar,\"{{'chicken':'snitchel'}}\",1,What is up,", date_string), str.format( "unknown,{0},What is up,,{0},,{0},foo,\"{{'chicken':'pie'}}\",3,What is up,{1}", date_string, xreflsid) ] with switch_db(Genotype, TEST_DB_ALIAS) as TestGen: query = TestGen.objects.all() actual_rows = query_to_csv_rows_list(query, testing=True) self.assertEqual(len(expected_rows), len(actual_rows)) self.assertEqual(actual_rows[0], expected_rows[0]) # Checks header rows are equal # Checks csv representations of genotype docs are in actual_rows for row in expected_rows: with self.subTest(row=row): self.assertIn(row, actual_rows)
) expected_experiment_yaml = Experiment( name='Bar', description="Test experiment configuration for Kaka", pi="Badi James", createddate=datetime(2016, 1, 7) ) expected_datasource_json = DataSource( name='Foo', source=path_string_json + "/a_test_source.hmp.txt.gz", supplieddate=datetime(2016, 1, 8, 11, 7, 33), ) expected_datasource_yaml = DataSource( name='Bar', source=path_string_yaml + "/a_test_source.hmp.txt.gz", supplieddate=datetime(2016, 1, 8, 11, 7, 33), ) expected_genotype_json = Genotype( name='Test source', description="Test json configuration for kaka", createddate=datetime(2016, 1, 7), obs={'foo': '1', 'bar': '2', 'baz': '3', 'rs#': 'Test source'}, study=expected_experiment_json, datasource=expected_datasource_json ) expected_genotype_yaml = Genotype( name='Test source', description="Test experiment configuration for Kaka", createddate=datetime(2016, 1, 7), obs={'foo': '1', 'bar': '2', 'baz': '3', 'rs#': 'Test source'}, study=expected_experiment_yaml, datasource=expected_datasource_yaml ) yaml_config_string = """--- Data Creator : Badi James Experiment Description : >- Test experiment configuration for Kaka Experiment Code : 123456 Upload Date : dt(2016-01-08T11:07:33Z) Experiment Date : dt(2016-01-07)