def test_add_network_node(self): """ Tests whether a row is added to the networks table. :return: """ conn_object = BiomConnection() conn_object.create_tables() conn_object.add_biom(testbiom, 'potato') conn_object = IoConnection() conn_object.add_network_node(values=('potato', 'potato', 5, 20)) conn = psycopg2.connect( **{ "host": "localhost", "database": "test", "user": "******", "password": "******" }) cur = conn.cursor() cur.execute("SELECT * from networks;") result = cur.fetchall() cur.close() conn.close() conn_object.delete_tables() self.assertEqual(result[0], ('potato', 'potato', 5, 20))
def test_add_biom(self): """ Tests if the BIOM file is imported by querying the count data. :return: """ conn_object = BiomConnection() conn_object.create_tables() conn_object.add_biom(testbiom, 'banana') conn = psycopg2.connect( **{ "host": "localhost", "database": "test", "user": "******", "password": "******" }) cur = conn.cursor() cur.execute("SELECT * from counts;") result = cur.fetchall() # long format table of 5 * 6 observations self.assertEqual(len(result), 30) cur.close() conn.close() conn_object.delete_tables()
def test_add_sample(self): """ Tests whether a row is added to the sample table. :return: """ conn_object = BiomConnection() conn_object.create_tables() conn_object.add_summary(values=('banana', 1, 2)) conn_object.add_sample(values=('Sample1', 'banana')) conn = psycopg2.connect( **{ "host": "localhost", "database": "test", "user": "******", "password": "******" }) cur = conn.cursor() cur.execute("SELECT sampleid from samples;") result = cur.fetchall() # long format table of 5 * 6 observations self.assertEqual(result[0][0], 'Sample1') cur.close() conn.close() conn_object.delete_tables()
def test_import_biom_mapping(self): """ Tests if the BiomConnection uses the mapping dict. :return: """ conn_object = BiomConnection() conn_object.create_tables() write_biom_table(testbiom, fmt='hdf5', filepath="test.biom") import_biom("test.biom", mapping={'test': 'banana'}) os.remove("test.biom") conn = psycopg2.connect( **{ "host": "localhost", "database": "test", "user": "******", "password": "******" }) cur = conn.cursor() cur.execute("SELECT studyID " "FROM bioms " "LIMIT 1;") result = cur.fetchall() cur.close() conn.close() conn_object.delete_tables() self.assertEqual(result[0][0], 'banana')