Skip to content

Commit

Permalink
fix: integration test (#97)
Browse files Browse the repository at this point in the history
* fix: create admin api key

* fix: revert to discourse from charmhub

* fix: typo

* fix: user & api key creation flow

* fix: upgrade discourse charm

* fix: remove unlist parameter(user level api failure)

* fix: update assert to pass returned content

* fix: set hostname for successful redirect

* fix: static test dependency update to bandit w/ toml

* fix: lint fixes

* test: wait for idle for longer

* test: give enough timeout for asset compile

* fix: deploy and wait for idle before getting status

* debug

* fix: parse raw content

* fix: lint fixes

* fix: wait for idle not active status

* fix: content in paragraph tag

* fix: backwards compatibility fix for e2e

* fix: infinte wait fix

* fix: set config after relations

* fix: reorder deploy flow

* fix: wait for ip

* fix: revert

* chore: revert back to main operator workflow

* chore: pin juju version & move to dev-requirements.txt

* chore: remove pre_run

* chore: add timeouts to requests

* test: separate out response parsing

* chore: revert content assertions

* fix: doc imperative mood fix

* test: fixturize admin API headers

* test: consistency fixes

* chore: remove unnecessary fstring

* fix: fixture reference
  • Loading branch information
yanksyoon authored Mar 24, 2023
1 parent ea4412d commit 046a6c0
Show file tree
Hide file tree
Showing 14 changed files with 353 additions and 178 deletions.
1 change: 0 additions & 1 deletion .github/workflows/integration_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ jobs:
uses: canonical/operator-workflows/.github/workflows/integration_test.yaml@main
secrets: inherit
with:
pre-run-script: tests/integration/pre_run.sh
modules: '["discourse", "reconcile", "migrate"]'
1 change: 1 addition & 0 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
factory_boy>=3.2,<3.3
juju==3.0.4
24 changes: 22 additions & 2 deletions src/discourse.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from .exceptions import DiscourseError, InputError

_URL_PATH_PREFIX = "/t/"
_POST_SPLIT_LINE = "\n\n-------------------------\n\n"


class _DiscourseTopicInfo(typing.NamedTuple):
Expand Down Expand Up @@ -345,6 +346,25 @@ def _get_requests_session() -> requests.Session: # pragma: no cover
session.mount("https://", adapter)
return session

@staticmethod
def _parse_raw_content(content: str) -> str:
"""Parse raw topic content returned from discourse /raw/{topic_id} API endpoint.
Args:
content: Raw content returned by discourse API.
Returns:
Original topic content.
"""
# Discourse version 2.6.0, the content of a topc is returned as raw string.
if not content.endswith(_POST_SPLIT_LINE):
return content

# Discourse version 2.8.14, the posts are split by _POST_SPLIT_LINE.
posts = content.split(_POST_SPLIT_LINE)
post_metadata_removed = posts[0].splitlines(keepends=True)[2:]
return "".join(post_metadata_removed)

def retrieve_topic(self, url: str) -> str:
"""Retrieve the topic content.
Expand Down Expand Up @@ -379,7 +399,8 @@ def retrieve_topic(self, url: str) -> str:
) as exc:
raise DiscourseError(f"Error retrieving the topic, {url=!r}") from exc

return response.content.decode("utf-8")
content = response.content.decode("utf-8")
return self._parse_raw_content(content)

def create_topic(self, title: str, content: str) -> str:
"""Create a new topic.
Expand All @@ -401,7 +422,6 @@ def create_topic(self, title: str, content: str) -> str:
category_id=self._category_id,
tags=self._tags,
content=content,
unlist_topic=True,
)
except pydiscourse.exceptions.DiscourseError as discourse_error:
raise DiscourseError(
Expand Down
4 changes: 3 additions & 1 deletion src/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ def get(path: Path) -> types_.Metadata:
raise InputError(f"Invalid value for name key: {name}, expected a string value")

docs = metadata.get(METADATA_DOCS_KEY)
if not isinstance(docs, str | None) or (METADATA_DOCS_KEY in metadata and docs is None):
if not (isinstance(docs, str) or docs is None) or (
METADATA_DOCS_KEY in metadata and docs is None
):
raise InputError(f"Invalid value for docs key: {docs}, expected a string value")

return types_.Metadata(name=name, docs=docs)
2 changes: 1 addition & 1 deletion src/migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _create_document_meta(row: types_.TableRow, path: Path) -> types_.DocumentMe
path: Relative path to where the document should reside.
Raises:
MigrationError: if the table row that was passed in does not cantain a link to document.
MigrationError: if the table row that was passed in does not contain a link to document.
Returns:
Information required to migrate document.
Expand Down
Loading

0 comments on commit 046a6c0

Please sign in to comment.