Exemplo n.º 1
0
    def test_show_phase_nodes(self):
        from next.model.models import Scenario
        from next.views import show_cumulative_phase_nodes, create_edges
        sc1 = self.session.query(Scenario).filter(Scenario.name == "Test").first()
        params = {'id': sc1.id, 'phase_id': 2}
        #test getting all nodes
        request = testing.DummyRequest()
        request.matchdict = params
        response = show_cumulative_phase_nodes(request)
        feature_coll = simplejson.loads(response.body)
        features = feature_coll['features']
        self.assertEqual(4, len(features))
        #test getting the demand nodes
        #need to create_edges first to generate edges
        response = create_edges(request)

        get_params = {'type': "demand"}
        request = testing.DummyRequest(params=get_params)
        request.matchdict = params
        response = show_cumulative_phase_nodes(request)
        feature_coll = simplejson.loads(response.body)
        features = feature_coll['features']
        self.assertEqual(2, len(features))
        feature = features[0]
        coords = feature['geometry']['coordinates']
        self.assertTrue(([1, 1] == coords) or ([-2, -2] == coords))
        self.assertEqual("demand", feature['properties']['type'])
Exemplo n.º 2
0
 def helper_get_phase_nodes(self, scenario_id, phase_id, node_type=None):
     " Helper to get nodes of type from scenario "
     from next.views import show_cumulative_phase_nodes
     request = testing.DummyRequest()
     params = {'id': scenario_id, 'phase_id': phase_id}
     if (node_type):
         request.GET = {'type': node_type}
         
     request.matchdict = params
     response = show_cumulative_phase_nodes(request)
     return simplejson.loads(response.body)