# Format, lint, test
# ---------------------------------------
+# LINT_LOCS := ntclient/ tests/ setup.py
+CHANGED_FILES_RST ?= $(shell git diff origin/master --name-only --diff-filter=MACRU \*.rst)
+CHANGED_FILES_PY ?= $(shell git diff origin/master --name-only --diff-filter=MACRU \*.py)
+
.PHONY: format
format: _venv ## Format with isort & black
ifneq ($(CHANGED_FILES_PY),)
$(info No changed Python files, skipping.)
endif
-
-# LINT_LOCS := ntclient/ tests/ setup.py
-CHANGED_FILES_RST ?= $(shell git diff origin/master --name-only --diff-filter=MACRU \*.rst)
-CHANGED_FILES_PY ?= $(shell git diff origin/master --name-only --diff-filter=MACRU \*.py)
-
.PHONY: lint
lint: _venv ## Lint code and documentation
ifneq ($(CHANGED_FILES_RST),)
TODO: return object: metadata, command, status, errors, etc?
"""
+ rows = sql_result.fetchall()
+ headers = [x[0] for x in (sql_result.description if sql_result.description else [])]
+
return (
- # rows
- sql_result.fetchall(),
- # headers
- [x[0] for x in sql_result.description],
- # row_count
+ rows,
+ headers,
sql_result.rowcount,
- # last_row_id
sql_result.lastrowid,
)
if values:
if isinstance(values, list):
cur.executemany(query, values)
- else: # tuple
+ elif isinstance(values, tuple):
cur.execute(query, values)
+ else:
+ raise TypeError("'values' must be a list or tuple!")
+
else:
cur.execute(query)
# TODO: try all of these; cache (save in prefs.json) the one which works first
URLS_API = (
- "https://api.nutra.tk",
+ # "https://api.nutra.tk",
"https://api.dev.nutra.tk",
"http://216.218.228.93", # dev
"http://216.218.216.163", # prod
def submit_bugs() -> int:
"""Submit bug reports to developer, return n_submitted."""
-
+ # TODO: mock sql_nt() for testing
# Gather bugs for submission
rows, _, _, _ = sql_nt("SELECT * FROM bug WHERE submitted = 0")
api_client = ntclient.services.api.ApiClient()
# Distinguish bug which are unique vs. duplicates (someone else submitted)
if _res.status_code == 201:
- sql_nt("UPDATE bug SET submitted = 1 WHERE id = %s", bug.id)
+ sql_nt("UPDATE bug SET submitted = 1 WHERE id = ?", (bug["id"],))
elif _res.status_code == 204:
- sql_nt("UPDATE bug SET submitted = 2 WHERE id = %s", bug.id)
+ sql_nt("UPDATE bug SET submitted = 2 WHERE id = ?", (bug["id"],))
else:
print("WARN: unknown status [{0}]".format(_res.status_code))
continue
@author: shane
"""
import unittest
+from unittest.mock import MagicMock, patch
import pytest
"""Tests the functions for listing bugs"""
bugs.list_bugs()
- @unittest.expectedFailure
- @pytest.mark.xfail(reason="Work in progress, need to get mocks working")
- def test_bug_report(self) -> None:
+ @patch("ntclient.services.api.cache_mirrors", return_value="https://someurl.com")
+ @patch(
+ "ntclient.services.api.ApiClient.post",
+ return_value=MagicMock(status_code=201),
+ )
+ # pylint: disable=unused-argument
+ def test_bug_report(self, *args: MagicMock) -> None:
"""Tests the functions for submitting bugs"""
bugs.submit_bugs()