def args_to_json_object(self, *args):
     for arg in args:
         if arg is None:
             yield None
         elif isinstance(arg, six.string_types):
             yield arg
         elif isinstance(arg, (int, float)):
             yield arg
         elif isinstance(arg, datetime):
             yield datetime.strftime(arg, self.dateformat)
         elif isinstance(arg, hb.JSONObject):
             yield arg
         elif isinstance(arg, collections.Mapping):
             yield hb.JSONObject(arg)
         elif isinstance(arg, collections.Iterable):
             arg = list(
                 arg
             )  ## in case it's a set or something that doesnt support indexing
             if len(arg) > 0 and isinstance(
                     arg[0], (six.string_types, int, float, datetime)):
                 json_friendly_arg = []
                 for a in arg:
                     if isinstance(a, datetime):
                         json_friendly_arg.append(
                             datetime.strftime(a, self.dateformat))
                     else:
                         json_friendly_arg.append(a)
                 yield json_friendly_arg
             elif len(arg) > 0 and isinstance(arg[0], hb.JSONObject):
                 yield arg
             else:
                 yield [hb.JSONObject(v) for v in arg]
         else:
             yield hb.JSONObject(arg)
Пример #2
0
    def test_add_nodes(self, client, projectmaker):
        """
        Test add new nodes to network
        """

        project = projectmaker.create('test')
        network = hb.JSONObject()
        nodes = []
        links = []

        nnodes = 3
        nlinks = 2
        x = [0, 0, 1]
        y = [0, 1, 0]

        for i in range(nnodes):
            node = hb.JSONObject()
            node.id = i * -1
            node.name = 'node ' + str(i)
            node.description = 'test node ' + str(i)
            node.x = x[i]
            node.y = y[i]

            nodes.append(node)

        for i in range(nlinks):
            link = hb.JSONObject()
            link.id = i * -1
            link.name = 'link ' + str(i)
            link.description = 'test link ' + str(i)
            link.node_1_id = nodes[i].id
            link.node_2_id = nodes[i + 1].id
            links.append(link)

        network.project_id = project.id
        network.name = 'Test @ %s'%(datetime.datetime.now())
        network.description = 'a network for soap unit tests.'
        network.nodes = nodes
        network.links = links

        network = client.add_network(network)
        network = client.get_network(network.id)
        nodes = []

        for i in range (1200):
             node1 = hb.JSONObject()
             new_node_num = nnodes + 1
             node1.id = new_node_num * -1
             node1.name = 'node1_'+str(i)
             node1.description = 'test node ' + str(new_node_num)
             node1.x = 100+i
             node1.y = 101+i
             nodes.append(node1)

        new_nodes=client.add_nodes(network.id, nodes)
        new_network = client.get_network(network.id)

        assert len(network.nodes)+len(nodes) == len(new_network.nodes); "new nodes were not added correctly_2",

        return  new_network
Пример #3
0
    def test_set_network_status(self, client, projectmaker):
        project = projectmaker.create('test')
        network = hb.JSONObject()
        nodes = []
        links = []

        nnodes = 3
        nlinks = 2
        x = [0, 0, 1]
        y = [0, 1, 0]

        for i in range(nnodes):
            node = hb.JSONObject()
            node.id = i * -1
            node.name = 'Node ' + str(i)
            node.description = 'Test node ' + str(i)
            node.x = x[i]
            node.y = y[i]

            nodes.append(node)

        for i in range(nlinks):
            link = hb.JSONObject()
            link.id = i * -1
            link.name = 'Link ' + str(i)
            link.description = 'Test link ' + str(i)
            link.node_1_id = nodes[i].id
            link.node_2_id = nodes[i + 1].id
            #link = client.add_link(link)

            links.append(link)

        network.project_id = project.id
        network.name = 'Test @ %s' % (datetime.datetime.now())
        network.description = 'A network for SOAP unit tests.'
        network.nodes = nodes
        network.links = links

        network = client.add_network(network)

        client.set_network_status(network.id, 'X')

        assert client.get_network(network.id).status == 'X', \
            'Deleting network did not work correctly.'

        client.set_network_status(network.id, 'A')

        assert client.get_network(network.id).status == 'A', \
            'Reactivating network did not work correctly.'
Пример #4
0
    def test_update_network(self, client, network_with_data):

        net = hb.JSONObject(client.get_network(network_with_data.id))

        link_id = net.links[1].id
        old_node_1_id = net.links[1].node_1_id
        old_node_2_id = net.links[1].node_2_id

        net.links[1].node_1_id = net.nodes[-1].id
        net.links[1].node_2_id = net.nodes[-2].id
        net.links[1].layout = {'color': 'red'}

        net.nodes[1].layout = {'color': 'green'}

        net.description = \
            'A different network for SOAP unit tests.'

        updated_network = client.update_network(net)

        assert net.id == updated_network.id, \
            'network_id has changed on update.'
        assert net.name == updated_network.name, \
            "network_name changed on update."
        assert updated_network.links[1].id == link_id
        assert updated_network.links[1].node_1_id != old_node_1_id
        assert updated_network.links[1].node_1_id == net.nodes[-1].id
        assert updated_network.links[1].layout['color'] == 'red'

        assert updated_network.links[1].node_2_id != old_node_2_id
        assert updated_network.links[1].node_2_id == net.nodes[-2].id

        assert updated_network.nodes[1].layout['color'] == 'green'
Пример #5
0
    def test_update_node(self, client, network_with_data):
        network = network_with_data

        node_to_update = hb.JSONObject(network.nodes[0])
        node_to_update.name = "Updated Node Name"
        node_to_update.layout = {'app': ["Unit Test1", "Unit Test2"]}

        new_node = client.update_node(node_to_update)

        new_network = hb.JSONObject(client.get_network(network.id))

        updated_node = None
        for n in new_network.nodes:
            if n.id == node_to_update.id:
                updated_node = n
        assert updated_node.layout is not None
        assert updated_node.layout['app'] == ["Unit Test1", "Unit Test2"]
        assert updated_node.name == "Updated Node Name"
Пример #6
0
    def test_validate_topology(self, client, projectmaker):
        project = projectmaker.create('test')
        network = hb.JSONObject({})
        nodes = []
        links = []

        nnodes = 3
        nlinks = 2
        x = [0, 0, 1]
        y = [0, 1, 0]

        for i in range(nnodes):
            node = hb.JSONObject()
            node.id = i * -1
            node.name = 'Node ' + str(i)
            node.description = 'Test node ' + str(i)
            node.x = x[i]
            node.y = y[i]

            nodes.append(node)

        #NOTE: NOT ADDING ENOUGH LINKS!!
        for i in range(nlinks - 1):
            link = hb.JSONObject()
            link.id = i * -1
            link.name = 'Link ' + str(i)
            link.description = 'Test link ' + str(i)
            link.node_1_id = nodes[i].id
            link.node_2_id = nodes[i + 1].id

            links.append(link)

        network.project_id = project.id
        network.name = 'Test @ %s' % (datetime.datetime.now())
        network.description = 'A network for SOAP unit tests.'
        network.nodes = nodes
        network.links = links

        network = client.add_network(network)

        result = client.validate_network_topology(network.id)
        assert len(result) == 1  #This means orphan nodes are present
Пример #7
0
def add_user(username, password):
    """
        Get the details for a network
    """

    #Connect to hydra
    conn = hf.connect()

    #Check if the user exists.
    try:
        user = conn.get_user_by_name(uname=username)
        print("User {0} already exists with ID {1}".format(username, user.id))
    except:
        user = hb.JSONObject({'username': username, 'password': password})
        newuser = conn.add_user(user=user)
        print("User {0} added with ID {1}".format(username, newuser.id))
Пример #8
0
    def test_bulk_set_network_owners(self, client, networkmaker):
        net = networkmaker.create()

        networkowners = client.get_all_network_owners([net.id])

        assert len(networkowners) == 1

        new_owner = hb.JSONObject(dict(
            network_id=net.id,
            user_id=2,
            view='Y',
            edit='Y',
            share='Y',
        ))
        client.bulk_set_network_owners([new_owner])

        networkowners = client.get_all_network_owners([net.id])

        assert len(networkowners) == 2
Пример #9
0
    def test_set_link_status(self, client, network_with_data):
        network = network_with_data

        link_to_delete = network.links[0]

        client.set_link_status(link_to_delete.id, 'X')

        new_network = hb.JSONObject(client.get_network(network.id))

        link_ids = []
        for l in new_network.links:
            link_ids.append(l.id)
        assert link_to_delete.id not in link_ids

        client.set_link_status(link_to_delete.id, 'A')
        new_network = client.get_network(network.id)
        link_ids = []
        for l in new_network.links:
            link_ids.append(l.id)
        assert link_to_delete.id in link_ids
Пример #10
0
    def test_add_node(self, client, projectmaker, template):
        project = projectmaker.create('test')
        network = hb.JSONObject()
        nodes = []
        links = []

        nnodes = 3
        nlinks = 2
        x = [0, 0, 1]
        y = [0, 1, 0]

        for i in range(nnodes):
            node = hb.JSONObject()
            node.id = i * -1
            node.name = 'node ' + str(i)
            node.description = 'test node ' + str(i)
            node.x = x[i]
            node.y = y[i]

            nodes.append(node)

        for i in range(nlinks):
            link = hb.JSONObject()
            link.id = i * -1
            link.name = 'link ' + str(i)
            link.description = 'test link ' + str(i)
            link.node_1_id = nodes[i].id
            link.node_2_id = nodes[i + 1].id

            links.append(link)

        network.project_id = project.id
        network.name = 'Test @ %s' % (datetime.datetime.now())
        network.description = 'a network for soap unit tests.'
        network.nodes = nodes
        network.links = links

        network = client.add_network(network)
        network = client.get_network(network.id)

        node = hb.JSONObject()
        new_node_num = nnodes + 1
        node.id = new_node_num * -1
        node.name = 'node ' + str(new_node_num)
        node.description = 'test node ' + str(new_node_num)
        node.x = 100
        node.y = 101

        tmpl = template

        type_summary_arr = []

        type_summary = hb.JSONObject()
        type_summary.id = tmpl.id
        type_summary.name = tmpl.name
        type_summary.id = tmpl.templatetypes[0].id
        type_summary.name = tmpl.templatetypes[0].name

        type_summary_arr.append(type_summary)

        node.types = type_summary_arr

        new_node = client.add_node(network.id, node)

        node_attr_ids = []
        for resource_attr in new_node.attributes:
            node_attr_ids.append(resource_attr.attr_id)

        for typeattr in tmpl.templatetypes[0].typeattrs:
            assert typeattr.attr_id in node_attr_ids

        new_network = client.get_network(network.id)

        assert len(new_network.nodes) == len(network.nodes) + 1
        "new node was not added correctly"

        return new_network
Пример #11
0
    def test_add_links(self, client, projectmaker):

        project = projectmaker.create('test')
        network = hb.JSONObject()
        nodes = []
        links = []

        nnodes = 3
        nlinks = 2
        x = [0, 0, 1]
        y = [0, 1, 0]

        for i in range(nnodes):
            node = hb.JSONObject()
            node.id = i * -1
            node.name = 'Node ' + str(i)
            node.description = 'Test node ' + str(i)
            node.x = x[i]
            node.y = y[i]

            nodes.append(node)

        for i in range(nlinks):
            link = hb.JSONObject()
            link.id = i * -1
            link.name = 'Link ' + str(i)
            link.description = 'Test link ' + str(i)
            link.node_1_id = nodes[i].id
            link.node_2_id = nodes[i + 1].id

            links.append(link)

        network.project_id = project.id
        network.name = 'Test @ %s' % (datetime.datetime.now())
        network.description = 'A network for SOAP unit tests.'
        network.nodes = nodes
        network.links = links

        network = client.add_network(network)
        links = []

        link = hb.JSONObject()
        link.id = i * -1
        link.name = 'New Link'
        link.description = 'Test link ' + str(i)
        link.node_1_id = network.nodes[0].id
        link.node_2_id = network.nodes[2].id
        links.append(link)

        link2 = hb.JSONObject()
        link2.id = i * -2
        link2.name = 'New Link_2'
        link2.description = 'Test link ' + str(i)
        link2.node_1_id = network.nodes[0].id
        link2.node_2_id = network.nodes[2].id
        links.append(link2)

        new_links = client.add_links(network.id, links)

        new_network = client.get_network(network.id)

        assert len(network.links) + len(links) == len(new_network.links)
        "new nodes were not added correctly_2",