class TestNode(TestCase): def setUp(self): self.bare = Node(0, 52, 0) self.named = Node(0, 52, 0, True, 'jnrowe', utils.Timestamp(2008, 1, 25)) self.tagged = Node(0, 52, 0, tags={'key': 'value'}) def test___repr__(self): expect(repr(self.bare)) == \ 'Node(0, 52.0, 0.0, False, None, None, None)' expect(repr(self.named)) == \ ("Node(0, 52.0, 0.0, True, 'jnrowe', " 'Timestamp(2008, 1, 25, 0, 0), None)') expect(repr(self.tagged)) == \ "Node(0, 52.0, 0.0, False, None, None, {'key': 'value'})" def test___str__(self): expect(str(self.bare)) == """Node 0 (52°00'00"N, 000°00'00"E)""" expect(str(self.named)) == \ ("""Node 0 (52°00'00"N, 000°00'00"E) [visible, user: jnrowe, """ 'timestamp: 2008-01-25T00:00:00+00:00]') expect(str(self.tagged)) == \ """Node 0 (52°00'00"N, 000°00'00"E) [key: value]""" def test_toosm(self): xml_str_compare('<node id="0" lat="52.0" lon="0.0" visible="false"/>', etree.tostring(self.bare.toosm())) xml_str_compare( '<node id="0" lat="52.0" lon="0.0" timestamp="2008-01-25T00:00:00+00:00" user="******" visible="true"/>', etree.tostring(self.named.toosm())) xml_str_compare( '<node id="0" lat="52.0" lon="0.0" visible="false"><tag k="key" v="value"/></node>', etree.tostring(self.tagged.toosm())) def test_get_area_url(self): expect(self.bare.get_area_url(3)) == \ 'http://api.openstreetmap.org/api/0.5/map?bbox=%s,%s,%s,%s' \ % (-0.04384973831146972, 51.97300340214557, 0.04384973831146972, 52.02699659785445) expect(self.bare.get_area_url(12)) == \ 'http://api.openstreetmap.org/api/0.5/map?bbox=%s,%s,%s,%s' \ % (-0.1753986342770412, 51.892013608582225, 0.1753986342770412, 52.10798639141778) def test_fetch_area_osm(self): # FIXME: The following test is skipped, because the Osm object doesn't # support a reliable way __repr__ method. #expect(Home.fetch_area_osm(3) pass
class TestNode: def setup(self): self.bare = Node(0, 52, 0) self.named = Node(0, 52, 0, True, 'jnrowe', utils.Timestamp(2008, 1, 25)) self.tagged = Node(0, 52, 0, tags={'key': 'value'}) @mark.parametrize('node, result', [ ('bare', 'Node(0, 52.0, 0.0, False, None, None, None)'), ('named', "Node(0, 52.0, 0.0, True, 'jnrowe', " "Timestamp(2008, 1, 25, 0, 0), None)"), ('tagged', "Node(0, 52.0, 0.0, False, None, None, {'key': 'value'})"), ]) def test___repr__(self, node, result): assert repr(getattr(self, node)) == result @mark.parametrize('node, result', [ ('bare', """Node 0 (52°00'00"N, 000°00'00"E)"""), ('named', """Node 0 (52°00'00"N, 000°00'00"E) [visible, user: jnrowe, """ 'timestamp: 2008-01-25T00:00:00+00:00]'), ('tagged', """Node 0 (52°00'00"N, 000°00'00"E) [key: value]"""), ]) def test___str__(self, node, result): assert str(getattr(self, node)) == result @mark.parametrize('node, result', [ ('bare', '<node id="0" lat="52.0" lon="0.0" visible="false"/>'), ('named', '<node id="0" lat="52.0" lon="0.0" ' 'timestamp="2008-01-25T00:00:00+00:00" user="******" ' 'visible="true"/>'), ('tagged', '<node id="0" lat="52.0" lon="0.0" visible="false">' '<tag k="key" v="value"/>' '</node>'), ]) def test_toosm(self, node, result): xml_str_compare(result, etree.tostring(getattr(self, node).toosm())) @mark.parametrize('size, results', [ (3, (-0.04384973831146972, 51.97300340214557, 0.04384973831146972, 52.02699659785445)), (12, (-0.1753986342770412, 51.892013608582225, 0.1753986342770412, 52.10798639141778)), ]) def test_get_area_url(self, size, results): assert self.bare.get_area_url(size) == \ 'http://api.openstreetmap.org/api/0.5/map?bbox=%s,%s,%s,%s' \ % results def test_fetch_area_osm(self): # FIXME: The following test is skipped, because the Osm object doesn't # support a reliable way __repr__ method. # assert Home.fetch_area_osm(3 pass
def setup(self): self.bare = Node(0, 52, 0) self.named = Node(0, 52, 0, True, 'jnrowe', utils.Timestamp(2008, 1, 25)) self.tagged = Node(0, 52, 0, tags={'key': 'value'})