Skip to content

Commit

Permalink
fix: add to test and refresh branches from db
Browse files Browse the repository at this point in the history
Signed-off-by: joseph-sentry <[email protected]>
  • Loading branch information
joseph-sentry committed Jan 23, 2024
1 parent 48f27a7 commit 3eeb437
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion api/public/v2/branch/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BranchDetailSerializer(BranchSerializer):

def get_head_commit(self, branch: Branch) -> CommitDetailSerializer:
_ = get_or_update_branch_head(Commit.objects, branch, branch.repository_id)

branch.refresh_from_db()
commit = (
Commit.objects.filter(
repository_id=branch.repository_id, commitid=branch.head
Expand Down
30 changes: 27 additions & 3 deletions graphs/tests/test_badge_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,21 @@ def test_branch_badge(self):
"p": 0,
"s": 1,
}
commit_3_totals = {
"C": 0,
"M": 0,
"N": 0,
"b": 0,
"c": "80.00000",
"d": 0,
"diff": [1, 2, 1, 1, 0, "50.00000", 0, 0, 0, 0, 0, 0, 0],
"f": 3,
"h": 17,
"m": 3,
"n": 20,
"p": 0,
"s": 1,
}
commit_2 = CommitFactory(
commitid="81c2b4fa3ae9ef615c8f740c5cba95d9851f9ae8s",
repository=repo,
Expand All @@ -692,6 +707,13 @@ def test_branch_badge(self):
branch_2 = BranchFactory(
repository=repo, name="branch1", head=commit_2.commitid
)
commit_3 = CommitFactory(
commitid="a1c2b4fa3ae9ef615c8f740c5cba95d9851f9ae8s",
repository=repo,
author=gh_owner,
totals=commit_3_totals,
branch="branch1",
)
# test default precision
response = self._get_branch(
kwargs={
Expand All @@ -713,14 +735,14 @@ def test_branch_badge(self):
</mask>
<g mask="url(#a)">
<path fill="#555" d="M0 0h73v20H0z" />
<path fill="#8aca02" d="M73 0h39v20H73z" />
<path fill="#efa41b" d="M73 0h39v20H73z" />
<path fill="url(#b)" d="M0 0h112v20H0z" />
</g>
<g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11">
<text x="46" y="15" fill="#010101" fill-opacity=".3">codecov</text>
<text x="46" y="14">codecov</text>
<text x="93" y="15" fill="#010101" fill-opacity=".3">95%</text>
<text x="93" y="14">95%</text>
<text x="93" y="15" fill="#010101" fill-opacity=".3">80%</text>
<text x="93" y="14">80%</text>
</g>
<svg viewBox="120 -8 60 60">
<path d="M23.013 0C10.333.009.01 10.22 0 22.762v.058l3.914 2.275.053-.036a11.291 11.291 0 0 1 8.352-1.767 10.911 10.911 0 0 1 5.5 2.726l.673.624.38-.828c.368-.802.793-1.556 1.264-2.24.19-.276.398-.554.637-.851l.393-.49-.484-.404a16.08 16.08 0 0 0-7.453-3.466 16.482 16.482 0 0 0-7.705.449C7.386 10.683 14.56 5.016 23.03 5.01c4.779 0 9.272 1.84 12.651 5.18 2.41 2.382 4.069 5.35 4.807 8.591a16.53 16.53 0 0 0-4.792-.723l-.292-.002a16.707 16.707 0 0 0-1.902.14l-.08.012c-.28.037-.524.074-.748.115-.11.019-.218.041-.327.063-.257.052-.51.108-.75.169l-.265.067a16.39 16.39 0 0 0-.926.276l-.056.018c-.682.23-1.36.511-2.016.838l-.052.026c-.29.145-.584.305-.899.49l-.069.04a15.596 15.596 0 0 0-4.061 3.466l-.145.175c-.29.36-.521.666-.723.96-.17.247-.34.513-.552.864l-.116.199c-.17.292-.32.57-.449.824l-.03.057a16.116 16.116 0 0 0-.843 2.029l-.034.102a15.65 15.65 0 0 0-.786 5.174l.003.214a21.523 21.523 0 0 0 .04.754c.009.119.02.237.032.355.014.145.032.29.049.432l.01.08c.01.067.017.133.026.197.034.242.074.48.119.72.463 2.419 1.62 4.836 3.345 6.99l.078.098.08-.095c.688-.81 2.395-3.38 2.539-4.922l.003-.029-.014-.025a10.727 10.727 0 0 1-1.226-4.956c0-5.76 4.545-10.544 10.343-10.89l.381-.014a11.403 11.403 0 0 1 6.651 1.957l.054.036 3.862-2.237.05-.03v-.056c.006-6.08-2.384-11.793-6.729-16.089C34.932 2.361 29.16 0 23.013 0" fill="#F01F7A" fill-rule="evenodd"/>
Expand All @@ -731,6 +753,8 @@ def test_branch_badge(self):
expected_badge = [line.strip() for line in expected_badge.split("\n")]
assert expected_badge == badge
assert response.status_code == status.HTTP_200_OK
branch_2.refresh_from_db()
assert branch_2.head == "a1c2b4fa3ae9ef615c8f740c5cba95d9851f9ae8s"

def test_badge_with_100_coverage(self):
gh_owner = OwnerFactory(service="github")
Expand Down
2 changes: 2 additions & 0 deletions graphs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ def get_coverage(self):
return None, coverage_range
try:
_ = get_or_update_branch_head(repo.commits, branch, repo.repoid)
branch.refresh_from_db()
commit = repo.commits.filter(commitid=branch.head).first()
except ObjectDoesNotExist:
# if commit does not exist return None coverage
Expand Down Expand Up @@ -251,6 +252,7 @@ def get_commit(self):
branch_head = get_or_update_branch_head(repo.commits, branch, repo.repoid)
if branch_head is None:
return None

Check warning on line 254 in graphs/views.py

View check run for this annotation

Codecov / codecov/patch

graphs/views.py#L254

Added line #L254 was not covered by tests
branch.refresh_from_db()
commit = repo.commits.filter(commitid=branch.head).first()

return commit

0 comments on commit 3eeb437

Please sign in to comment.