Skip to content

Commit 5f68aba

Browse files
greenapemergify[bot]
authored andcommitted
Reinstate secrets test
1 parent 8932be4 commit 5f68aba

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

flowapi/flowapi/main.py

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
44
import uuid
55

6-
from pathlib import Path
76

87
import quart.flask_patch
98
from quart import Quart, request, current_app

flowapi/tests/unit/test_secrets.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
5+
import unittest
6+
from pathlib import Path
7+
8+
from flowapi.config import getsecret
9+
10+
11+
def test_get_secrets(monkeypatch):
12+
"""Test getting a secret from the special /run/secrets directory."""
13+
the_secret = "Shhhh"
14+
the_secret_name = "SECRET"
15+
open_mock = unittest.mock.mock_open(read_data=the_secret)
16+
monkeypatch.setattr("builtins.open", open_mock)
17+
secret = getsecret(the_secret_name, "Not the secret")
18+
assert the_secret == secret
19+
open_mock.assert_called_once_with(Path("/run/secrets") / the_secret_name, "r")
20+
21+
22+
def test_get_secrets_default(monkeypatch):
23+
"""Test getting a secret falls back to provided default with the file being there."""
24+
the_secret = "Shhhh"
25+
the_secret_name = "SECRET"
26+
secret = getsecret(the_secret_name, the_secret)
27+
assert the_secret == secret

0 commit comments

Comments
 (0)