Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/osmium/replication/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,16 +483,26 @@ def get_state_url(self, seq: Optional[int]) -> str:
i.e. the state file in the root directory of the replication
service.
"""
# Canonicalize the baseurl
# Try to avoid calling `example.com/area-updates//state.txt`
baseurl_wo_slash = self.baseurl
while baseurl_wo_slash[-1] == "/":
baseurl_wo_slash = baseurl_wo_slash[:-1]

if seq is None:
return self.baseurl + '/state.txt'
return baseurl_wo_slash + '/state.txt'

return '%s/%03i/%03i/%03i.state.txt' % \
(self.baseurl, seq / 1000000, (seq % 1000000) / 1000, seq % 1000)
(baseurl_wo_slash, seq / 1000000, (seq % 1000000) / 1000, seq % 1000)

def get_diff_url(self, seq: int) -> str:
""" Returns the URL to the diff file for the given sequence id.
"""
baseurl_wo_slash = self.baseurl
while baseurl_wo_slash[-1] == "/":
baseurl_wo_slash = baseurl_wo_slash[:-1]

return '%s/%03i/%03i/%03i.%s' % \
(self.baseurl,
(baseurl_wo_slash,
seq / 1000000, (seq % 1000000) / 1000, seq % 1000,
self.diff_type)
46 changes: 30 additions & 16 deletions test/test_replication.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,42 @@
pytestmark = [pytest.mark.thread_unsafe, pytest.mark.iterations(1)]


@pytest.mark.parametrize("inp,outp", [
(None, 'https://text.org/state.txt'),
(1, 'https://text.org/000/000/001.state.txt'),
(999, 'https://text.org/000/000/999.state.txt'),
(1000, 'https://text.org/000/001/000.state.txt'),
(573923, 'https://text.org/000/573/923.state.txt'),
(3290012, 'https://text.org/003/290/012.state.txt'),
@pytest.mark.parametrize("baseurl,inp,outp", [
("https://text.org", None, 'https://text.org/state.txt'),
("https://text.org", 1, 'https://text.org/000/000/001.state.txt'),
("https://text.org", 999, 'https://text.org/000/000/999.state.txt'),
("https://text.org", 1000, 'https://text.org/000/001/000.state.txt'),
("https://text.org", 573923, 'https://text.org/000/573/923.state.txt'),
("https://text.org", 3290012, 'https://text.org/003/290/012.state.txt'),

("https://text.org/", None, 'https://text.org/state.txt'),
("https://text.org/", 1, 'https://text.org/000/000/001.state.txt'),
("https://text.org//", None, 'https://text.org/state.txt'),
("https://text.org//", 1, 'https://text.org/000/000/001.state.txt'),

("https://text.org/area-updates", None, 'https://text.org/area-updates/state.txt'),
("https://text.org/area-updates", 3290012, 'https://text.org/area-updates/003/290/012.state.txt'),
("https://text.org/area-updates/", None, 'https://text.org/area-updates/state.txt'),
("https://text.org/area-updates/", 3290012, 'https://text.org/area-updates/003/290/012.state.txt'),
("https://text.org/area-updates//", None, 'https://text.org/area-updates/state.txt'),
("https://text.org/area-updates//", 3290012, 'https://text.org/area-updates/003/290/012.state.txt'),
])
def test_get_state_url(inp, outp):
svr = rserv.ReplicationServer("https://text.org")
def test_get_state_url(baseurl, inp, outp):
svr = rserv.ReplicationServer(baseurl)

assert outp == svr.get_state_url(inp)


@pytest.mark.parametrize("inp,outp", [
(1, 'https://who.is/me//000/000/001.osc.gz'),
(500, 'https://who.is/me//000/000/500.osc.gz'),
(83750, 'https://who.is/me//000/083/750.osc.gz'),
(999999999, 'https://who.is/me//999/999/999.osc.gz'),
@pytest.mark.parametrize("baseurl,inp,outp", [
("https://who.is/me/", 1, 'https://who.is/me//sdfsdf000/000/001.osc.gz'),
("https://who.is/me/", 500, 'https://who.is/me/000/000/500.osc.gz'),
("https://who.is/me/", 83750, 'https://who.is/me/000/083/750.osc.gz'),
("https://who.is/me/", 999999999, 'https://who.is/me/999/999/999.osc.gz'),

("https://who.is/me", 999999999, 'https://who.is/me/999/999/999.osc.gz'),
])
def test_get_diff_url(inp, outp):
svr = rserv.ReplicationServer("https://who.is/me/")
def test_get_diff_url(baseurl, inp, outp):
svr = rserv.ReplicationServer(baseurl)

assert outp, svr.get_diff_url(inp)

Expand Down
Loading