Skip to content
This repository was archived by the owner on Jun 13, 2025. It is now read-only.

Commit 1d85bc8

Browse files
committed
add new test and use constant
1 parent 4187f39 commit 1d85bc8

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

codecov_auth/commands/owner/interactors/set_yaml_on_owner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
ValidationError,
1414
)
1515
from codecov.db import sync_to_async
16+
from codecov_auth.constants import OWNER_YAML_TO_STRING_KEY
1617
from codecov_auth.helpers import current_user_part_of_org
1718
from codecov_auth.models import Owner
1819

@@ -56,6 +57,6 @@ def execute(self, username: str, yaml_input: str) -> Owner:
5657
self.authorize()
5758
self.owner.yaml = self.convert_yaml_to_dict(yaml_input)
5859
if self.owner.yaml:
59-
self.owner.yaml["to_string"] = yaml_input
60+
self.owner.yaml[OWNER_YAML_TO_STRING_KEY] = yaml_input
6061
self.owner.save()
6162
return self.owner

codecov_auth/commands/owner/interactors/tests/test_set_yaml_on_owner.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,16 @@
3535
bot: foo: bar
3636
"""
3737

38+
good_yaml_with_comments = """
39+
# comment 1
40+
codecov: # comment 2
41+
42+
43+
bot: 'codecov'
44+
# comment 3
45+
#comment 4
46+
"""
47+
3848

3949
class SetYamlOnOwnerInteractorTest(TransactionTestCase):
4050
def setUp(self):
@@ -113,3 +123,23 @@ async def test_yaml_syntax_error(self):
113123
str(e.value)
114124
== "Syntax error at line 3, column 13: mapping values are not allowed here"
115125
)
126+
127+
async def test_yaml_has_comments(self):
128+
owner_updated = await self.execute(
129+
self.current_owner, self.org.username, good_yaml_with_comments
130+
)
131+
# check the interactor returns the right owner
132+
assert owner_updated.ownerid == self.org.ownerid
133+
assert owner_updated.yaml == {
134+
"codecov": {
135+
"bot": "codecov",
136+
},
137+
"to_string": "\n"
138+
"# comment 1\n"
139+
"codecov: # comment 2\n"
140+
"\n"
141+
"\n"
142+
" bot: 'codecov'\n"
143+
"# comment 3\n"
144+
" #comment 4\n",
145+
}

codecov_auth/constants.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
GITLAB_BASE_URL = "https://gitlab.com"
44
GRAVATAR_BASE_URL = "https://www.gravatar.com"
55
AVATARIO_BASE_URL = "https://avatars.io"
6+
OWNER_YAML_TO_STRING_KEY = "to_string"

graphql_api/types/owner/owner.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import services.activation as activation
1212
import timeseries.helpers as timeseries_helpers
1313
from codecov.db import sync_to_async
14+
from codecov_auth.constants import OWNER_YAML_TO_STRING_KEY
1415
from codecov_auth.helpers import current_user_part_of_org
1516
from codecov_auth.models import (
1617
SERVICE_GITHUB,
@@ -94,7 +95,7 @@ def resolve_yaml(owner: Owner, info: GraphQLResolveInfo) -> Optional[str]:
9495
current_owner = info.context["request"].current_owner
9596
if not current_user_part_of_org(current_owner, owner):
9697
return None
97-
return owner.yaml.get("to_string", yaml.dump(owner.yaml))
98+
return owner.yaml.get(OWNER_YAML_TO_STRING_KEY, yaml.dump(owner.yaml))
9899

99100

100101
@owner_bindable.field("plan")

0 commit comments

Comments
 (0)