Skip to content

Commit

Permalink
Update Sitemap default namespace (#5)
Browse files Browse the repository at this point in the history
* Update default namespace

* Update namespace registration

* Update test data

* Update test.yml

* Delete hu08__0.xml

* Pass CI testing
  • Loading branch information
webb-ben authored Jan 17, 2024
1 parent 25f1276 commit b47c55e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
run: |
git clone -b master https://github.com/internetofwater/geoconnex.us.git geoconnex.us
cd geoconnex.us
git checkout e0e1c2ba0d023bfd80f3e6d76c85c01fab35c581
git checkout 4cc92f91abbecf20650ac595d81726062ffb3894
- uses: actions/setup-python@v2
name: Setup Python ${{ matrix.python-version }}
with:
Expand Down
5 changes: 5 additions & 0 deletions sitemap_generator/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@


def write_tree(tree, file):
ET.register_namespace('', 'http://www.sitemaps.org/schemas/sitemap/0.9')
tree.write(file, **SITEMAP_ARGS)
try:
ET._namespace_map.pop('http://www.sitemaps.org/schemas/sitemap/0.9')
except KeyError:
print('No default namespace')


def get_smi():
Expand Down
3 changes: 0 additions & 3 deletions tests/data/namespaces/iow/autotest1.csv

This file was deleted.

32 changes: 24 additions & 8 deletions tests/data/namespaces/iow/links__0.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,40 @@

<?xml version='1.0' encoding='utf-8'?>
<ns0:urlset xmlns:ns0="http://www.sitemaps.org/schemas/sitemap/0.9">
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
<url>
<loc>https://geoconnex.us/iow/homepage</loc>
<lastmod>2023-09-01T05:34:10Z</lastmod>
</url><url>
<loc>https://geoconnex.us/iow/aboutus</loc>
<lastmod>2023-09-01T05:34:10Z</lastmod>
</url><url>
<loc>https://geoconnex.us/demo</loc>
<lastmod>2023-09-01T05:34:10Z</lastmod>
</url><url>
<loc>https://geoconnex.us/iow/nldi</loc>
<lastmod>2023-06-23T22:38:13Z</lastmod>
<lastmod>2023-09-01T05:34:10Z</lastmod>
</url><url>
<loc>https://geoconnex.us/iow/nldi/demo</loc>
<lastmod>2023-06-23T22:38:13Z</lastmod>
<lastmod>2023-09-01T05:34:10Z</lastmod>
</url><url>
<loc>https://geoconnex.us/iow/map</loc>
<lastmod>2023-06-23T22:38:13Z</lastmod>
<lastmod>2023-09-01T05:34:10Z</lastmod>
</url><url>
<loc>https://geoconnex.us/iow/cr-demo</loc>
<lastmod>2023-06-23T22:38:13Z</lastmod>
<lastmod>2023-09-01T05:34:10Z</lastmod>
</url><url>
<loc>https://geoconnex.us/iow/tracker</loc>
<lastmod>2023-06-23T22:38:13Z</lastmod>
<lastmod>2023-09-01T05:34:10Z</lastmod>
</url><url>
<loc>https://geoconnex.us/iow/hyriver</loc>
<lastmod>2023-06-23T22:38:13Z</lastmod>
<lastmod>2023-09-01T05:34:10Z</lastmod>
</url><url>
<loc>https://geoconnex.us/iow/principles</loc>
<lastmod>2023-06-23T22:38:13Z</lastmod>
<lastmod>2023-09-01T05:34:10Z</lastmod>
</url><url>
<loc>https://geoconnex.us/iow/api-mockups</loc>
<lastmod>2023-09-01T05:34:10Z</lastmod>
</url><url>
<loc>https://geoconnex.us/iow/guidance</loc>
<lastmod>2023-09-01T05:34:10Z</lastmod>
</url></ns0:urlset>
21 changes: 4 additions & 17 deletions tests/test_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,10 @@ def test_sitemapindex():
tree = ET.parse(sitemapindex)
root = tree.getroot()

assert all(child.tag == 'sitemap' for child in root)
assert all(URI_STEM in child.find('loc').text for child in root)

links = root.find('sitemap')
assert links.find('lastmod').text != today
assert all('sitemap' in child.tag for child in root)
for child in root:
assert URI_STEM in ''.join(child.itertext())
assert all(URI_STEM in ''.join(child.itertext()) for child in root)


def test_urlset():
Expand All @@ -81,15 +80,3 @@ def test_urlset():

namespace = url_join(URI_STEM, HANDLER.get_rel_path(urlset))
assert namespace == 'https://geoconnex.us/iow'

[urlset] = list(walk_path(SITEMAP_DIR, r'.*autotest1__0.xml'))
file_time = HANDLER.get_filetime(urlset)
tree = ET.parse(urlset)
root = tree.getroot()

assert all(child.tag == 'url' for child in root)
assert all(file_time == child.find('lastmod').text for child in root)

url = root.find('url')
lastmod = url.find('lastmod').text
assert lastmod == '2021-11-17T16:24:48Z'
2 changes: 1 addition & 1 deletion tests/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

def test_walk_path():
glob_all = list(util.walk_path(NAMESPACE, r'.*'))
assert len(glob_all) >= 3
assert len(glob_all) >= 2

glob = util.walk_path(NAMESPACE, r'.*csv')
assert len(list(glob)) < len(glob_all)
Expand Down

0 comments on commit b47c55e

Please sign in to comment.