Exemplo n.º 1
0
    def test_update_network_with_empty_network(self):
        client = self.get_ndex2_client()
        # create network and add it
        net = NiceCXNetwork()
        oneid = net.create_node('node1')
        twoid = net.create_node('node2')
        net.create_edge(oneid, twoid, 'hello')
        netname = 'NiceCXNetwork upload_to() test network' + str(
            datetime.now())
        net.set_name(netname)
        creds = self.get_ndex_credentials_as_tuple()
        res = net.upload_to(creds['server'],
                            creds['user'],
                            creds['password'],
                            user_agent=creds['user_agent'])
        try:
            self.assertTrue('http' in res)
            netid = re.sub('^.*/', '', res)
            netsum = self.wait_for_network_to_be_ready(client, netid)
            self.assertIsNotNone(
                netsum, 'Network is still not ready,'
                ' maybe server is busy?')
            self.assertEqual(netid, netsum['externalId'])
            self.assertTrue('name' in netsum, msg=str(netsum))
            self.assertEqual(netname, netsum['name'], str(netsum))
            self.assertEqual('PRIVATE', netsum['visibility'])
            self.assertEqual(False, netsum['isReadOnly'])
            self.assertEqual(1, netsum['edgeCount'])
            self.assertEqual(2, netsum['nodeCount'])
            self.assertEqual(False, netsum['isShowcase'])
            self.assertEqual('NONE', netsum['indexLevel'])
            newnet = NiceCXNetwork()

            newres = newnet.update_to(netid,
                                      creds['server'],
                                      creds['user'],
                                      creds['password'],
                                      user_agent=creds['user_agent'])
            self.assertEqual('', newres)
            netsum = self.wait_for_network_to_be_ready(client,
                                                       netid,
                                                       num_retries=5,
                                                       retry_weight=1)
            self.assertIsNotNone(
                netsum, 'Network is still not ready,'
                ' maybe server is busy?')
            self.assertEqual(netid, netsum['externalId'])
            self.assertEqual('PRIVATE', netsum['visibility'])
            self.assertEqual(False, netsum['isReadOnly'])
            self.assertEqual(0, netsum['edgeCount'])
            self.assertEqual(0, netsum['nodeCount'])
            self.assertEqual(False, netsum['isShowcase'])
            self.assertEqual('NONE', netsum['indexLevel'])
        finally:
            client.delete_network(netid)
            try:
                client.get_network_as_cx_stream(netid)
                self.fail('Expected exception')
            except HTTPError:
                pass
Exemplo n.º 2
0
 def test_upload_to_success(self):
     with requests_mock.mock() as m:
         resurl = client.DEFAULT_SERVER + '/v2/network/asdf'
         m.get(self.get_rest_admin_status_url(),
               json=self.get_rest_admin_status_dict("2.4.0"))
         m.post(client.DEFAULT_SERVER + '/v2/network',
                request_headers={'Connection': 'close'},
                status_code=1,
                text=resurl)
         net = NiceCXNetwork()
         net.create_node('bob')
         res = net.upload_to(client.DEFAULT_SERVER, 'bob', 'warnerbrandis',
                             user_agent='jeez')
         self.assertEqual(res, resurl)
         decode_txt = m.last_request.text.read().decode('UTF-8')
         self.assertEqual(m.last_request.headers['User-Agent'],
                          client.userAgent + ' jeez')
         self.assertTrue('Content-Disposition: form-data; name='
                         '"CXNetworkStream"; filename='
                         '"filename"' in decode_txt)
         self.assertTrue('Content-Type: application/'
                         'octet-stream' in decode_txt)
         self.assertTrue('{"nodes": [{' in decode_txt)
         self.assertTrue('"@id": 0' in decode_txt)
         self.assertTrue('"n": "bob"' in decode_txt)
         self.assertTrue('"r": "bob"' in decode_txt)
         self.assertTrue('{"status": [{"' in decode_txt)
         self.assertTrue('"error": ""' in decode_txt)
         self.assertTrue('"success": true' in decode_txt)
Exemplo n.º 3
0
 def test_bad_nodes_add_edge(self):
     niceCx_creatures = NiceCXNetwork()
     niceCx_creatures.set_name("Test Network")
     node1_id = niceCx_creatures.create_node(node_name=324)
     node2_id = niceCx_creatures.create_node(node_name=453)
     niceCx_creatures.create_edge(edge_source=node1_id, edge_target=node2_id, edge_interaction=['inte'])
     upload_message = niceCx_creatures.upload_to(upload_server, upload_username, upload_password)
     self.assertTrue(upload_message)
Exemplo n.º 4
0
    def test_bad_node_attr(self):
        niceCx_creatures = NiceCXNetwork()
        niceCx_creatures.set_name("Test Network")
        fox_node = niceCx_creatures.create_node(node_name=453)
        niceCx_creatures.add_node_attribute(property_of=fox_node, name='Color', values=['Red',"tree"])

        upload_message = niceCx_creatures.upload_to(upload_server, upload_username, upload_password)
        self.assertTrue(upload_message)
Exemplo n.º 5
0
 def test_bad_nodes_add_edge(self):
     niceCx_creatures = NiceCXNetwork()
     niceCx_creatures.set_name("Test Network")
     node1_id = niceCx_creatures.create_node(node_name=324)
     node2_id = niceCx_creatures.create_node(node_name=453)
     niceCx_creatures.create_edge(edge_source=node1_id, edge_target=node2_id, edge_interaction=['inte'])
     upload_message = niceCx_creatures.upload_to(upload_server, upload_username, upload_password)
     self.assertTrue(upload_message)
Exemplo n.º 6
0
    def test_bad_node_attr(self):
        niceCx_creatures = NiceCXNetwork()
        niceCx_creatures.set_name("Test Network")
        fox_node = niceCx_creatures.create_node(node_name=453)
        niceCx_creatures.add_node_attribute(property_of=fox_node, name='Color', values=['Red',"tree"])

        upload_message = niceCx_creatures.upload_to(upload_server, upload_username, upload_password)
        self.assertTrue(upload_message)
Exemplo n.º 7
0
    def test_add_bad_net_attrs(self):
        niceCx_creatures = NiceCXNetwork()
        niceCx_creatures.set_name("Test")
        niceCx_creatures.create_node(node_name="Fox")
        niceCx_creatures.set_network_attribute(name="version", values="1.0")
        print(niceCx_creatures)
        upload_message = niceCx_creatures.upload_to(upload_server, upload_username, upload_password)

        self.assertTrue(upload_message)
Exemplo n.º 8
0
    def test_add_bad_net_attrs(self):
        niceCx_creatures = NiceCXNetwork()
        niceCx_creatures.set_name("Test")
        niceCx_creatures.create_node(node_name="Fox")
        niceCx_creatures.set_network_attribute(name="version", values="1.0")
        print(niceCx_creatures)
        upload_message = niceCx_creatures.upload_to(upload_server, upload_username, upload_password)

        self.assertTrue(upload_message)
Exemplo n.º 9
0
    def test_bad_edge_attr(self):
        niceCx_creatures = NiceCXNetwork()
        niceCx_creatures.set_name("Test Network")
        node1_id = niceCx_creatures.create_node(node_name=324)
        node2_id = niceCx_creatures.create_node(node_name=453)
        edge = niceCx_creatures.create_edge(edge_source=node1_id, edge_target=node2_id, edge_interaction='inte')
        niceCx_creatures.add_edge_attribute(property_of=edge, name= "djks", values= "jfkl")

        upload_message = niceCx_creatures.upload_to(upload_server, upload_username, upload_password)
        self.assertTrue(upload_message)
Exemplo n.º 10
0
    def test_bad_edge_attr(self):
        niceCx_creatures = NiceCXNetwork()
        niceCx_creatures.set_name("Test Network")
        node1_id = niceCx_creatures.create_node(node_name=324)
        node2_id = niceCx_creatures.create_node(node_name=453)
        edge = niceCx_creatures.create_edge(edge_source=node1_id, edge_target=node2_id, edge_interaction='inte')
        niceCx_creatures.add_edge_attribute(property_of=edge, name= "djks", values= "jfkl")

        upload_message = niceCx_creatures.upload_to(upload_server, upload_username, upload_password)
        self.assertTrue(upload_message)
Exemplo n.º 11
0
    def test_add_int_attr(self):
        niceCx = NiceCXNetwork()
        int_node = niceCx.create_node(node_name="testint")
        niceCx.add_node_attribute(property_of=int_node, name='Size', values=1, type="integer")

        upload_message = niceCx.upload_to(upload_server, upload_username, upload_password)
        UUID = upload_message.split('/')[-1]
        time.sleep(1)
        imported_cx = ndex2.create_nice_cx_from_server(server='dev.ndexbio.org', uuid=UUID, username=upload_username, password=upload_password)
        for i in imported_cx.get_node_attributes(0):
            self.assertEqual(i.get('d'), "integer")
Exemplo n.º 12
0
    def test_add_lst_flt(self):
        niceCx = NiceCXNetwork()
        list_float_node = niceCx.create_node(node_name="testlstflt")

        niceCx.add_node_attribute(property_of=list_float_node, name='Too many scores', values=[15.3,43.6,-34.0,43.3], type="list_of_float")

        upload_message = niceCx.upload_to(upload_server, upload_username, upload_password)
        UUID = upload_message.split('/')[-1]
        time.sleep(1)
        imported_cx = ndex2.create_nice_cx_from_server(server='dev.ndexbio.org', uuid=UUID, username=upload_username,
                                                       password=upload_password)
        for i in imported_cx.get_node_attributes(0):
            self.assertEqual(i.get('d'), "list_of_double")
Exemplo n.º 13
0
    def test_add_flt(self):
        niceCx = NiceCXNetwork()
        float_node = niceCx.create_node(node_name="testflt")
        niceCx.add_node_attribute(property_of=float_node,
                                  name='Score',
                                  values=1.0,
                                  type="float")

        upload_message = niceCx.upload_to(upload_server, upload_username,
                                          upload_password)
        UUID = upload_message.split('/')[-1]
        time.sleep(1)
        imported_cx = ndex2.create_nice_cx_from_server(
            server='dev.ndexbio.org',
            uuid=UUID,
            username=upload_username,
            password=upload_password)
        for i in imported_cx.get_node_attributes(0):
            self.assertEqual(i.get('d'), "double")
Exemplo n.º 14
0
    def test_load_edges(self):
        self.assertFalse(upload_username == 'username')

        nice_cx = NiceCXNetwork()

        node_id_1 = nice_cx.create_node(node_name='node%s' % str(1), node_represents='ABC')
        node_id_2 = nice_cx.create_node(node_name='node%s' % str(2), node_represents='DEF')

        edge_id_1 = nice_cx.create_edge(edge_source=node_id_1, edge_target=node_id_2, edge_interaction='neighbor')

        citation1 = nice_cx.add_citation(id=0, title='Hi 1', identifier='pmid:28947956')
        nice_cx.add_edge_citations(edge_id_1, citation1.get('@id'))

        supports1 = nice_cx.add_support(id=0, text='Hi supports 1')
        nice_cx.add_edge_supports(edge_id_1, supports1.get('@id'))

        nice_cx.set_name('Citation testing')
        upload_message = nice_cx.upload_to(upload_server, upload_username, upload_password)
        print(upload_message)
Exemplo n.º 15
0
    def test_add_lst_int(self):
        niceCx = NiceCXNetwork()
        list_int_node = niceCx.create_node(node_name="testlstint")
        niceCx.add_node_attribute(property_of=list_int_node,
                                  name='Too many sizes',
                                  values=[1, 2, 3, 4, 5],
                                  type="list_of_integer")

        upload_message = niceCx.upload_to(upload_server, upload_username,
                                          upload_password)
        UUID = upload_message.split('/')[-1]
        time.sleep(1)
        imported_cx = ndex2.create_nice_cx_from_server(
            server='dev.ndexbio.org',
            uuid=UUID,
            username=upload_username,
            password=upload_password)
        for i in imported_cx.get_node_attributes(0):
            self.assertEqual(i.get('d'), "list_of_integer")
Exemplo n.º 16
0
    def test_load_edges(self):
        self.assertFalse(upload_username == 'username')

        nice_cx = NiceCXNetwork()

        node_id_1 = nice_cx.create_node(node_name='node%s' % str(1), node_represents='ABC')
        node_id_2 = nice_cx.create_node(node_name='node%s' % str(2), node_represents='DEF')

        edge_id_1 = nice_cx.create_edge(edge_source=node_id_1, edge_target=node_id_2, edge_interaction='neighbor')

        citation1 = nice_cx.add_citation(id=0, title='Hi 1', identifier='pmid:28947956')
        nice_cx.add_edge_citations(edge_id_1, citation1.get('@id'))

        supports1 = nice_cx.add_support(id=0, text='Hi supports 1')
        nice_cx.add_edge_supports(edge_id_1, supports1.get('@id'))

        nice_cx.set_name('Citation testing')
        upload_message = nice_cx.upload_to(upload_server, upload_username, upload_password)
        print(upload_message)
Exemplo n.º 17
0
 def test_bad_name_add_node(self):
     niceCx_creatures = NiceCXNetwork()
     niceCx_creatures.set_name("Test Network")
     node1_id = niceCx_creatures.create_node(node_name=54, node_represents="Tree")
     upload_message = niceCx_creatures.upload_to(upload_server, upload_username, upload_password)
     self.assertTrue(upload_message)
Exemplo n.º 18
0
 def test_bad_name_add_node(self):
     niceCx_creatures = NiceCXNetwork()
     niceCx_creatures.set_name("Test Network")
     node1_id = niceCx_creatures.create_node(node_name=54, node_represents="Tree")
     upload_message = niceCx_creatures.upload_to(upload_server, upload_username, upload_password)
     self.assertTrue(upload_message)
Exemplo n.º 19
0
 def test_set_name(self):
     niceCx_creatures = NiceCXNetwork()
     niceCx_creatures.set_name(43)
     niceCx_creatures.create_node(node_name="tree")
     upload_message = niceCx_creatures.upload_to(upload_server, upload_username, upload_password)
     self.assertTrue(upload_message)
Exemplo n.º 20
0
# #### to_networkx()

# In[ ]:

NiceCX_creatures = NiceCXNetwork()
networkx_network = NiceCX_creatures.to_networkx()

# #### to_pandas_dataframe()

# In[ ]:

NiceCX_creatures = NiceCXNetwork()
pandas_network = NiceCX_creatures.to_pandas_dataframe()

# #### upload(ndex_server, username, password, update_uuid=None)

# In[ ]:

upload_message = NiceCX_creatures.upload_to("http://public.ndexbio.org",
                                            "ENTER YOUR USER",
                                            "ENTER YOUR PASSWORD")
uuid = upload_message.rpartition('/')[-1]

# ##### apply_template(server, username, password, uuid)

# ##### addNode(json_obj=None)

# ##### add_edge_element(json_obj=None, edge)

# ##### addNetworkAttribute(json_obj=None)
Exemplo n.º 21
0
 def test_set_name(self):
     niceCx_creatures = NiceCXNetwork()
     niceCx_creatures.set_name(43)
     niceCx_creatures.create_node(node_name="tree")
     upload_message = niceCx_creatures.upload_to(upload_server, upload_username, upload_password)
     self.assertTrue(upload_message)