Skip to content

Commit

Permalink
fix: super + CKAN_SITE_URL reference + tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nickumia-reisys committed Jul 25, 2023
1 parent f99bbb4 commit 639bbd4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 16 deletions.
10 changes: 5 additions & 5 deletions ckanext/geodatagov/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def write_sitemap_header(self, index=False) -> None:
class SitemapData(Sitemap):

def __init__(self, file_num: str, start: int, page_size: int) -> None:
super(SitemapIndex, self).__init__(file_num, start, page_size)
super().__init__(file_num, start, page_size)
self.filename_s3 = f"sitemap/sitemap-{file_num}.xml"

def write_pkgs(self, package_query: GeoPackageSearchQuery) -> None:
Expand All @@ -98,7 +98,7 @@ def write_sitemap_footer(self) -> None:
class SitemapIndex(Sitemap):

def __init__(self, file_num: str, start: int, page_size: int) -> None:
super(SitemapIndex, self).__init__(file_num, start, page_size)
super().__init__(file_num, start, page_size)
self.filename_s3 = "sitemap.xml"

def write_table_of_contents(self, number_of_sitemaps):
Expand All @@ -114,7 +114,7 @@ def write_table_of_contents(self, number_of_sitemaps):
for file_num in range(number_of_sitemaps):
# add sitemaps to sitemap index file
self.write_xml("<sitemap>")
loc = f"{CKAN_SITE_URL}/sitemap/sitemap-{file_num}.xml"
loc = f"{config.get('ckan.site_url')}/sitemap/sitemap-{file_num}.xml"
self.write_xml(f"<loc>{loc}</loc>")
self.write_xml(f"<lastmod>{current_time}</lastmod>")
self.write_xml("</sitemap>")
Expand Down Expand Up @@ -276,8 +276,8 @@ def sitemap_to_s3(upload_to_s3: bool, page_size: int, max_per_page: int):
get_s3()
upload_sitemap_file(sitemap)
else:
log.info("Skip upload and finish.")
print(f"Done locally: Sitemap {file_num}\n{json.dumps(sitemap.to_json(), indent=4)}")
log.info(f"Skip upload and return local copy of sitemap {file_num}.")
print(json.dumps(sitemap.to_json(), indent=4))


def _normalize_type(_type):
Expand Down
16 changes: 5 additions & 11 deletions ckanext/geodatagov/tests/test_sitemap_creation.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,20 +53,14 @@ def test_cli_output(cli_result: Result) -> None:
# the example output I have only has one element in it,
# this and _handle_cli_output will need to be updated for examples with more elements
# checks only one list element in output string
assert cli_result.output.count("[") == 1
assert cli_result.output.count("]") == 1
assert cli_result.output.count("file_num") == 2

@staticmethod
def _handle_cli_output(cli_result: Result) -> list:
"""Parses cli output Result to an interable file_list"""

file_list = [
eval(
cli_result.output[
cli_result.output.index("[") + 1: cli_result.output.index("]") - 1
].strip()
)
]
file_list = cli_result.output.split("}\"\n")
file_list = list(set([f + "}\"" for f in file_list]) - {'}\"'})

return file_list

Expand All @@ -79,7 +73,7 @@ def test_create_sitemap(self, cli_result):
datasets = 0
for site_file in file_list:
# site_file is dumped as string
site_file = eval(site_file)
site_file = eval(eval(site_file))

files += 1
""" expected something like
Expand Down Expand Up @@ -132,7 +126,7 @@ def test_create_sitemap(self, cli_result):
else:
raise Exception("Unexpected tag")

assert files == 1
assert files == 2
assert datasets >= 4 # at least this four
assert dataset1_found
assert dataset2_found
Expand Down

0 comments on commit 639bbd4

Please sign in to comment.