Skip to content

Commit b806829

Browse files
fix basic auth
1 parent 4291fcb commit b806829

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

core/pioreactor/mureq.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,10 @@ def _prepare_outgoing_headers(
345345
) -> HTTPMessage:
346346
from pioreactor.config import config
347347

348-
DEFAULT_AUTH = f'Basic {config.get("ui_basic_auth", "api_key", fallback="")}'
348+
if config.get("ui_basic_auth", "api_key", fallback=""):
349+
default_auth = f'Basic {config.get("ui_basic_auth", "api_key", fallback="")}'
350+
else:
351+
default_auth = ""
349352

350353
if headers is None:
351354
headers = HTTPMessage()
@@ -359,7 +362,8 @@ def _prepare_outgoing_headers(
359362
new_headers[k] = v
360363
headers = new_headers
361364
_setdefault_header(headers, "User-Agent", DEFAULT_UA)
362-
_setdefault_header(headers, "Authorization", DEFAULT_AUTH)
365+
if default_auth:
366+
_setdefault_header(headers, "Authorization", default_auth)
363367
return headers
364368

365369

core/tests/test_dosing_automation.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,9 @@ def test_AltMediaFractionCalculator() -> None:
10041004
timestamp=default_datetime_for_pioreactor(1),
10051005
source_of_event="test",
10061006
)
1007-
assert ac.update(add_alt_media_event, 0.0, current_volume_ml) == round(1 / (current_volume_ml + 1), 10)
1007+
assert round(ac.update(add_alt_media_event, 0.0, current_volume_ml), 10) == round(
1008+
1 / (current_volume_ml + 1), 10
1009+
)
10081010

10091011
alt_media_added = 2.0
10101012
add_alt_media_event = DosingEvent(

core/tests/test_execute_experiment_profile.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
from pioreactor.experiment_profiles.profile_struct import Stop
2626
from pioreactor.experiment_profiles.profile_struct import Update
2727
from pioreactor.experiment_profiles.profile_struct import When
28+
from pioreactor.mureq import HTTPErrorStatus
2829
from pioreactor.pubsub import collect_all_logs_of_level
2930
from pioreactor.pubsub import publish
3031
from pioreactor.pubsub import subscribe_and_callback
@@ -752,12 +753,14 @@ def test_profiles_in_github_repo() -> None:
752753
# Set the API endpoint URL
753754
owner = "Pioreactor"
754755
repo = "experiment_profile_examples"
755-
path = "" # Top level directory
756-
api_url = f"https://api.github.com/repos/{owner}/{repo}/contents/{path}"
756+
api_url = f"https://api.github.com/repos/{owner}/{repo}/contents"
757757

758-
# Make a GET request to the GitHub API
759758
response = get(api_url)
760-
response.raise_for_status() # Will raise an HTTPError if the HTTP request returned an unsuccessful status code
759+
try:
760+
response.raise_for_status()
761+
except HTTPErrorStatus as e:
762+
# raise HTTPErrorStatus(f"HTTP error: Failed to fetch repository contents from {api_url}: saw {str(e)}")
763+
raise e
761764

762765
# Check for YAML files
763766
yaml_files = [

0 commit comments

Comments
 (0)