Example #1
0
	def check_node_in_query(self, node, expected=True, verbose=False):

		anonClient = Client()
		bbox = [node.lon-0.0001, node.lat-0.0001, node.lon+0.0001, node.lat+0.0001]
		response = anonClient.get(reverse('querymap:querymap') + "?bbox={},{},{},{}".format(*bbox))
		self.assertEqual(response.status_code, 200)

		xml = list(response.streaming_content)
		if verbose:
			print ("check_node_in_query", node.objId, "(expected", expected,")")
			for chunk in xml:
				print (chunk.decode(str("utf-8")), end='')
			print ('')
		data = DecodeOsmdataResponse(xml)

		idDicts = GetOsmDataIndex(data)
		nodeIdDict = idDicts['node']
		self.assertEqual(node.objId in nodeIdDict, expected)

		if expected:
			qNode = nodeIdDict[node.objId]
			self.assertEqual(dict(node.tags) == dict(qNode.tags), True)

			self.assertEqual(abs(node.lat - qNode.lat)<1e-6, True)
			self.assertEqual(abs(node.lon - qNode.lon)<1e-6, True)
Example #2
0
    def test_delete_static_way(self):

        #Find a way that is not part of any other relation
        anonClient = Client()
        response = anonClient.get(
            reverse('querymap:querymap') +
            "?bbox={},{},{},{}".format(*self.roi))
        self.assertEqual(response.status_code, 200)

        data = DecodeOsmdataResponse(response.streaming_content)
        nodeIdSet, wayIdSet, relationIdSet, nodeMems, wayMems, relationMems = self.find_object_ids(
            data)
        candidateIds = list(wayIdSet.difference(wayMems))

        if len(candidateIds) > 0:
            idDicts = GetOsmDataIndex(data)
            nodeIdDict, wayIdDict, relationIdDict = idDicts['node'], idDicts[
                'way'], idDicts['relation']
            wayObjToDelete = wayIdDict[candidateIds[0]]

            ok = delete_object(wayObjToDelete, self.user)
            self.assertEqual(ok, True)
            self.check_way_in_query(wayObjToDelete, self.roi, False)
        else:
            print("No free ways in ROI for testing")
Example #3
0
    def test_modify_static_node(self):

        #Find a static node
        anonClient = Client()
        response = anonClient.get(
            reverse('querymap:querymap') +
            "?bbox={},{},{},{}".format(*self.roi))
        self.assertEqual(response.status_code, 200)

        data = DecodeOsmdataResponse(response.streaming_content)
        nodeIdSet, wayIdSet, relationIdSet, nodeMems, wayMems, relationMems = self.find_object_ids(
            data)
        candidateIds = list(nodeIdSet.difference(nodeMems))

        if len(candidateIds) > 0:
            idDicts = GetOsmDataIndex(data)
            nodeIdDict, wayIdDict, relationIdDict = idDicts['node'], idDicts[
                'way'], idDicts['relation']
            nodeObjToModify = nodeIdDict[candidateIds[0]]

            ok, modNode = modify_node(nodeObjToModify, 1, self.user)
            self.assertEqual(ok, True)
            self.check_node_in_query(modNode, True)
            self.check_node_in_query(nodeObjToModify, False)

        else:
            print("No nodes in ROI for testing")
Example #4
0
    def test_multifetch_ways(self):

        cs = CreateTestChangeset(self.user,
                                 tags={"foo": "invade"},
                                 is_open=True)

        xml = """<osmChange generator="JOSM" version="0.6">
		<create>
		  <node changeset="{0}" id="-5393" lat="50.79046578105" lon="-1.04971367626" />
		  <node changeset="{0}" id="-5394" lat="50.81" lon="-1.051" />
		  <node changeset="{0}" id="-5395" lat="50.82" lon="-1.053" />
		  <way changeset="{0}" id="-434">
		   <tag k="note" v="Just a way"/>
		   <nd ref="-5393"/>
		   <nd ref="-5394"/>
		  </way>
		  <way changeset="{0}" id="-435">
		   <tag k="note" v="Just a way"/>
		   <nd ref="-5394"/>
		   <nd ref="-5395"/>
		  </way>
		</create>
		</osmChange>""".format(cs.objId)

        response = self.client.post(reverse('changeset:upload',
                                            args=(cs.objId, )),
                                    xml,
                                    content_type='text/xml')
        if response.status_code != 200:
            print(response.content)
        self.assertEqual(response.status_code, 200)

        xml = fromstring(response.content)
        diffDict = ParseOsmDiffToDict(xml)
        node1Id = diffDict["node"][-5393][0]
        node2Id = diffDict["node"][-5394][0]
        node3Id = diffDict["node"][-5395][0]
        way1Id = diffDict["way"][-434][0]
        way2Id = diffDict["way"][-435][0]

        response = self.client.get(
            reverse('multifetch:multifetch', args=("ways", )) +
            "?ways={},{}".format(way1Id, way2Id))
        self.assertEqual(response.status_code, 200)

        data = DecodeOsmdataResponse([response.content])

        idDicts = GetOsmDataIndex(data)
        self.assertEqual(way1Id in idDicts['way'], True)
        self.assertEqual(way2Id in idDicts['way'], True)
        self.assertEqual(len(idDicts['node']), 0)
        self.assertEqual(len(idDicts['relation']), 0)
Example #5
0
	def check_relation_in_query(self, relation, bbox, expected):
		
		anonClient = Client()
		response = anonClient.get(reverse('querymap:querymap') + "?bbox={},{},{},{}".format(*bbox))
		self.assertEqual(response.status_code, 200)

		data = DecodeOsmdataResponse(response.streaming_content)

		idDicts = GetOsmDataIndex(data)
		nodeIdDict, wayIdDict, relationIdDict = idDicts['node'], idDicts['way'], idDicts['relation']
		self.assertEqual(relation.objId in relationIdDict, expected)
		
		if expected:
			self.assertEqual(dict(relation.tags) == dict(relationIdDict[relation.objId].tags), True)
			self.assertEqual(list(relation.refIds) == list(relationIdDict[relation.objId].refIds), True)
Example #6
0
	def test_get_ways_for_node(self):
		anonClient = Client()

		node = create_node(self.user.id, self.user.username)
		node2 = create_node(self.user.id, self.user.username, node)
		way = create_way(self.user.id, self.user.username, [node.objId, node2.objId])

		response = anonClient.get(reverse('elements:ways_for_node', args=['node', str(node.objId)]))
		if response.status_code != 200:
			print (response.content)
		self.assertEqual(response.status_code, 200)

		osmData = DecodeOsmdataResponse([response.content])
		wayIdDict = GetOsmDataIndex(osmData)['way']

		self.assertEqual(len(wayIdDict), 1)
		self.assertEqual(way.objId in wayIdDict, True)
Example #7
0
    def test_delete_static_relation(self):

        #Find a relation that is not part of any other relation
        anonClient = Client()
        response = anonClient.get(
            reverse('querymap:querymap') +
            "?bbox={},{},{},{}".format(*self.roi))
        self.assertEqual(response.status_code, 200)

        data = DecodeOsmdataResponse(response.streaming_content)
        nodeIdSet, wayIdSet, relationIdSet, nodeMems, wayMems, relationMems = self.find_object_ids(
            data)
        candidateIds = list(relationIdSet.difference(relationMems))

        t = p.GetTransaction("EXCLUSIVE")

        #Try to find a suitable candidate for deletion
        for candidateId in candidateIds:

            #Use first object among candidates
            idDicts = GetOsmDataIndex(data)
            nodeIdDict, wayIdDict, relationIdDict = idDicts['node'], idDicts[
                'way'], idDicts['relation']
            relationObjToDel = relationIdDict[candidateId]

            #Check for parents of relation, skip if found
            parentData = pgmap.OsmData()
            t.GetRelationsForObjs("relation", [int(candidateId)], parentData)
            if len(parentData.relations) > 0:
                continue

            ok = delete_object(relationObjToDel, self.user, t)
            if not ok:
                t.Abort()
            self.assertEqual(ok, True)
            t.Commit()
            self.check_relation_in_query(relationObjToDel, self.roi, False)
            return  #Success!

        t.Commit()
        print(
            "No free relations (with no parent relations) in ROI for testing")
Example #8
0
    def test_modify_static_relation(self):

        #Find a relation that is not part of any other relation
        anonClient = Client()
        response = anonClient.get(
            reverse('querymap:querymap') +
            "?bbox={},{},{},{}".format(*self.roi))
        self.assertEqual(response.status_code, 200)

        data = DecodeOsmdataResponse(response.streaming_content)
        nodeIdSet, wayIdSet, relationIdSet, nodeMems, wayMems, relationMems = self.find_object_ids(
            data)
        candidateIds = list(relationIdSet.difference(relationMems))

        for candidateId in candidateIds:

            #Iterate over
            idDicts = GetOsmDataIndex(data)
            nodeIdDict, wayIdDict, relationIdDict = idDicts['node'], idDicts[
                'way'], idDicts['relation']
            relationObjToMod = relationIdDict[candidateId]

            #Skip relations with zero members
            refTypeStrs = list(relationObjToMod.refTypeStrs)
            if len(refTypeStrs) == 0:
                continue

            #Do modification by appending first member as a new last member
            refTypeStrs.append(refTypeStrs[0])
            refIds = list(relationObjToMod.refIds)
            refIds.append(refIds[0])
            refRoles = list(relationObjToMod.refRoles)
            refRoles.append(refRoles[0])
            modRelation = modify_relation(self.user.id, self.user.username,
                                          relationObjToMod,
                                          zip(refTypeStrs, refIds,
                                              refRoles), {"foo": "bacon"})
            self.assertEqual(modRelation is not None, True)
            self.check_relation_in_query(modRelation, self.roi, True)
            return  #Success!

        print("No free relations in ROI for testing")