Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
cb-util
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Christoph Alt
cb-util
Commits
38e34e7c
Commit
38e34e7c
authored
9 months ago
by
Christoph Alt
Browse files
Options
Downloads
Patches
Plain Diff
fixed the test for load_config even if a .env file is present
parent
5afc9119
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/test_dashboard_upload.py
+12
-6
12 additions, 6 deletions
tests/test_dashboard_upload.py
with
12 additions
and
6 deletions
tests/test_dashboard_upload.py
+
12
−
6
View file @
38e34e7c
...
...
@@ -4,19 +4,25 @@ from dashboards.upload import load_config_from_env
from
unittest.mock
import
patch
import
os
def
test_load_config_from_env
():
# Case 1: Test if function raises exception for missing GRAFANA_API_KEY
with
pytest
.
raises
(
ValueError
)
as
e
:
load_config_from_env
(
env_path
=
"
.env
"
)
assert
str
(
e
.
value
)
==
"
GRAFANA_API_KEY is None or not defined in the .env file
"
load_config_from_env
(
env_path
=
""
)
assert
str
(
e
.
value
)
==
"
GRAFANA_API_KEY is None or not defined in the .env file
"
# Case 2: Test if function raises exception for missing GRAFANA_SERVER
with
patch
.
dict
(
os
.
environ
,
{
"
GRAFANA_API_KEY
"
:
"
api_key
"
}):
with
pytest
.
raises
(
ValueError
)
as
e
:
load_config_from_env
(
env_path
=
"
.env
"
)
assert
str
(
e
.
value
)
==
"
GRAFANA_SERVER is None or not defined in the .env file
"
load_config_from_env
(
env_path
=
""
)
assert
str
(
e
.
value
)
==
"
GRAFANA_SERVER is None or not defined in the .env file
"
# Case 3: Test if function returns expected values when both variables are defined
with
patch
.
dict
(
os
.
environ
,
{
"
GRAFANA_API_KEY
"
:
"
api_key
"
,
"
GRAFANA_SERVER
"
:
"
server_url
"
}):
with
patch
.
dict
(
os
.
environ
,
{
"
GRAFANA_API_KEY
"
:
"
api_key
"
,
"
GRAFANA_SERVER
"
:
"
server_url
"
}
):
result
=
load_config_from_env
(
env_path
=
"
.env
"
)
assert
result
==
(
"
server_url
"
,
"
api_key
"
)
\ No newline at end of file
assert
result
==
(
"
server_url
"
,
"
api_key
"
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment