Skip to content

Commit bfdc565

Browse files
committed
tests
1 parent c475e4f commit bfdc565

File tree

3 files changed

+40
-8
lines changed

3 files changed

+40
-8
lines changed

chakin/commands/expression/delete_biomaterials.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77
@click.option(
88
"--names",
99
help="JSON list of biomaterial names to delete.",
10-
default="[]",
11-
show_default=True,
1210
type=str
1311
)
1412
@click.option(
1513
"--ids",
1614
help="JSON list of biomaterial ids to delete.",
17-
default="[]",
18-
show_default=True,
1915
type=str
2016
)
2117
@click.option(
@@ -31,7 +27,7 @@
3127
@pass_context
3228
@custom_exception
3329
@str_output
34-
def cli(ctx, names="[]", ids="[]", organism_id="", analysis_id=""):
30+
def cli(ctx, names="", ids="", organism_id="", analysis_id=""):
3531
"""Will delete biomaterials based on selector. Only one selector will be used.
3632
3733
Output:

docs/commands/expression.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ Will delete biomaterials based on selector. Only one selector will be used.
130130
**Options**::
131131

132132

133-
--names TEXT JSON list of biomaterial names to delete. [default: []]
134-
--ids TEXT JSON list of biomaterial ids to delete. [default: []]
133+
--names TEXT JSON list of biomaterial names to delete.
134+
--ids TEXT JSON list of biomaterial ids to delete.
135135
--organism_id TEXT Delete all biomaterial associated with this organism id.
136136
--analysis_id TEXT Delete all biomaterial associated with this analysis id.
137137
-h, --help Show this message and exit.

test/expression_test.py

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,51 @@ def test_add_biomaterial(self):
99
biomaterial_name = "test_biomat"
1010
biomaterial_provider = "Helena Ventseslav"
1111
biomaterial_description = "This is a description"
12+
biosample_accession = 'biosample-foobar'
13+
sra_accession = "sra-bar"
14+
bioproject_accession = 'bioproject-foo'
15+
attrs = {
16+
'foo': 'bar',
17+
'oof': 'arb'
18+
}
1219
org = self._create_fake_org()
1320

14-
biomat = self.ci.expression.add_biomaterial(biomaterial_name, org["organism_id"], description=biomaterial_description, biomaterial_provider=biomaterial_provider, bioproject_accession="something")
21+
biomat_ret = self.ci.expression.add_biomaterial(biomaterial_name, org["organism_id"], description=biomaterial_description, biomaterial_provider=biomaterial_provider, biosample_accession=biosample_accession, sra_accession=sra_accession, bioproject_accession=bioproject_accession, attributes=attrs)
22+
23+
biomat = self.ci.expression.get_biomaterials(biomaterial_name=biomaterial_name)[0]
24+
25+
assert biomat_ret == biomat
1526

1627
assert biomat, "Issue : Biomaterial not created"
1728
assert biomat["name"] == biomaterial_name, "Biomaterial name issue : " + biomat["name"]
1829
assert biomat["provider_id"], "Bioprovider not set! "
1930
assert biomat["description"] == biomaterial_description, "Description issue : " + biomat["description"]
2031

32+
res = self.ci.session.query(self.ci.model.biomaterialprop).filter_by(biomaterial_id=biomat['biomaterial_id'])
33+
34+
props = {prop.type_id: prop.value for prop in res}
35+
for at in attrs:
36+
type_id = self.ci.get_cvterm_id(at, 'biomaterial_property')
37+
assert type_id in props
38+
39+
assert props[type_id] == attrs[at]
40+
41+
dbs = self.ci.session.query(self.ci.model.db.db_id, self.ci.model.db.name, self.ci.model.db.description) \
42+
.filter((self.ci.model.db.name == 'NCBI SRA') | (self.ci.model.db.name == 'NCBI BioProject') | (self.ci.model.db.name == 'NCBI BioSample'))
43+
44+
dbs = {db.name: db.db_id for db in dbs}
45+
46+
biomat = self.ci.session.query(self.ci.model.biomaterial).filter_by(biomaterial_id=biomat['biomaterial_id']).one()
47+
48+
xrefs = {dbx.dbxref.db_id: dbx.dbxref.accession for dbx in biomat.biomaterial_dbxref_collection}
49+
50+
assert len(dbs) == 3
51+
assert len(xrefs) == 3
52+
53+
assert xrefs[dbs['NCBI SRA']] == "sra-bar"
54+
assert xrefs[dbs['NCBI BioProject']] == "bioproject-foo"
55+
assert xrefs[dbs['NCBI BioSample']] == "biosample-foobar"
56+
2157
def test_add_expression(self):
2258

2359
# Setup testing data

0 commit comments

Comments
 (0)