def test_add_resource_type(self):

        template = self.get_template()
        types = template.templatetypes
        type_name = types[0].name
        type_id = types[0].id

        project = self.create_project('test')
        network = JSONObject()

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

        network.nodes = []
        network.links = []

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

            type_summary = JSONObject()
            type_summary.template_id = template.id
            type_summary.template_name = template.name
            type_summary.id = type_id
            type_summary.name = type_name

            node.types = [type_summary]

            network.nodes.append(node)

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

            network.links.append(link)

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

        net_summary = add_network(network, user_id=self.user_id)
        new_net = get_network(net_summary.id, user_id=self.user_id)

        for node in new_net.nodes:
            assert node.types is not None and node.types[
                0].type_name == "Node type"
            "type was not added correctly!"
Exemple #2
0
    def create_network_with_extra_group(self, project_id=None,
                                        num_nodes=10,
                                        ret_full_net=True,
                                        new_proj=False,
                                        map_projection='EPSG:4326'):
        """
            Test adding data to a network through a scenario.
            This test adds attributes to one node and then assigns data to them.
            It assigns a descriptor, array and timeseries to the
            attributes node.
        """
        network = self.create_network_with_data(
                                 project_id=project_id,
                                 num_nodes=num_nodes,
                                 ret_full_net=ret_full_net,
                                 new_proj=new_proj,
                                 map_projection=map_projection)

        group = JSONObject({})
        group.network_id = network.id
        group.id = -1
        group.name = 'test new group'
        group.description = 'test new group'

        template_id = network.types[0].template_id
        template = JSONObject(self.client.get_template(template_id))

        type_summary_arr = []

        type_summary = JSONObject({})
        type_summary.id = template.id
        type_summary.name = template.name
        type_summary.id = template.templatetypes[2].id
        type_summary.name = template.templatetypes[2].name

        type_summary_arr.append(type_summary)

        group.types = type_summary_arr

        new_group = self.client.add_group(network.id, group)

        group_attr_ids = []
        for resource_attr in new_group.attributes:
            group_attr_ids.append(resource_attr.attr_id)

        updated_network = self.client.get_network(network.id)

        return updated_network