Skip to content

Commit

Permalink
Format Python helpers
Browse files Browse the repository at this point in the history
Also add the tooling to `package.json` scripts section and run it on CI.

I opted for creating `npm run check:all` and `npm run fix:all` rather
than running the new `npm run check:helpers` and `npm run fix:helpers`
by the regular `check` and `fix` scripts because the files are
only rarely changed.
  • Loading branch information
jtojnar committed Jul 11, 2024
1 parent dd134ff commit f75240b
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 13 deletions.
12 changes: 8 additions & 4 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
include:
- php: '7.4'
phpstan: true
cs_fixer: true
check_client: true
# These should be the same no matter the PHP version.
lint: true
- php: '8.2'
storage: mysql
- php: '8.2'
Expand Down Expand Up @@ -77,16 +77,20 @@ jobs:
run: nix-shell --run 'npm run install-dependencies'

- name: Check front-end code
if: matrix.check_client
if: matrix.lint
run: nix-shell --run 'npm run check:client'

- name: Check syntax of back-end code
run: nix-shell --run 'npm run check:server:lint'

- name: Lint back-end code
if: matrix.cs_fixer
if: matrix.lint
run: nix-shell --run 'npm run check:server:cs'

- name: Lint helper code
if: matrix.lint
run: nix-shell --run 'npm run check:helpers:cs'

- name: Run unit tests
run: nix-shell --run 'npm run test:server'

Expand Down
3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
# For building zip archive and integration tests.
python

# Python code linting.
pkgs.black

# Website generator.
pkgs.zola
] ++ dbServers.${matrix.storage};
Expand Down
6 changes: 6 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,23 @@
"scripts": {
"bump-version": "$NODE utils/bump-version.js",
"check": "npm run check:client && npm run check:server",
"check:all": "npm run check && npm run check:helpers",
"check:client": "npm run --prefix client/ check",
"check:server": "npm run check:server:lint && npm run check:server:cs && npm run test:server && npm run check:server:phpstan",
"check:server:lint": "composer run-script lint",
"check:server:phpstan": "composer run-script phpstan",
"check:server:cs": "composer run-script cs",
"check:helpers": "npm run check:helpers:cs",
"check:helpers:cs": "npm run fix:helpers:cs -- --check",
"dev": "npm run --prefix client/ dev",
"build": "npm run --prefix client/ build",
"dist": "python3 utils/create-zipball.py",
"fix": "npm run fix:client && npm run fix:server",
"fix:all": "npm run fix && npm run fix:helpers",
"fix:client": "npm run --prefix client/ fix",
"fix:server": "composer run-script fix",
"fix:helpers": "npm run fix:helpers:cs",
"fix:helpers:cs": "black utils/ tests/",
"install-dependencies": "npm run install-dependencies:client && npm run install-dependencies:server",
"install-dependencies:client": "npm install --production=false --prefix client/",
"install-dependencies:server": "composer install --dev",
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/helpers/feeds/fibonacci.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def numbers_feed(n: int) -> str:
d = od + datetime.timedelta(minutes=k)
item_pubdate = doc.createElement("pubDate")
item.appendChild(item_pubdate)
item_pubdate.appendChild(doc.createTextNode(d.strftime("%a, %d %b %Y %H:%M:%S %z")))
item_pubdate.appendChild(
doc.createTextNode(d.strftime("%a, %d %b %Y %H:%M:%S %z"))
)

return doc.toprettyxml(indent=" " * 4)
5 changes: 4 additions & 1 deletion tests/integration/helpers/selfoss_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ def run(self):
(data_dir / "thumbnails").mkdir(parents=True)
(data_dir / "favicons").mkdir(parents=True)

hashed_password = bcrypt.hashpw(self.password.encode("utf-8"), bcrypt.gensalt())
hashed_password = bcrypt.hashpw(
self.password.encode("utf-8"),
bcrypt.gensalt(),
)

# Configure selfoss using environment variables for convenience.
test_env = {
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/helpers/storage_servers.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ def start(self):
)

def stop(self):
subprocess.check_call(["mysqladmin", f"--socket={self.socket_path}", "shutdown"])
subprocess.check_call(
["mysqladmin", f"--socket={self.socket_path}", "shutdown"]
)
self.temp_dir.cleanup()

def get_config(self):
Expand Down
25 changes: 19 additions & 6 deletions tests/integration/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,33 @@ def test_basic_workflow(self):
items = selfoss_api.get_items()
assert len(items) == 0, "New selfoss instance should have no items."

fibonacci_feed_uri = f"http://{self.data_host_name}:{self.data_port}/fibonacci.xml"
fibonacci_feed_uri = (
f"http://{self.data_host_name}:{self.data_port}/fibonacci.xml"
)

try:
add_feed = selfoss_api.add_source("spouts\\rss\\feed", url=fibonacci_feed_uri)
assert "Adding source is privileged operation and should fail without login."
add_feed = selfoss_api.add_source(
"spouts\\rss\\feed",
url=fibonacci_feed_uri,
)
assert (
"Adding source is privileged operation and should fail without login."
)
except requests.exceptions.HTTPError as e:
assert e.response.status_code == 403, "Adding source should require authentication."
assert (
e.response.status_code == 403
), "Adding source should require authentication."

login = selfoss_api.login(self.selfoss_username, self.selfoss_password)
assert login["success"], f'Authentication should succeed but it failed with {login["error"]}.'
assert login[
"success"
], f'Authentication should succeed but it failed with {login["error"]}.'

add_feed = selfoss_api.add_source("spouts\\rss\\feed", url=fibonacci_feed_uri)
assert add_feed["success"], "Adding source should succeed."
assert add_feed["title"] == "20 numbers", "Source should auto-detect feed title."
assert (
add_feed["title"] == "20 numbers"
), "Source should auto-detect feed title."

refresh = selfoss_api.refresh_all()
assert refresh == "finished", "Refreshing sources should succeed."
Expand Down

0 comments on commit f75240b

Please sign in to comment.