Skip to content

Commit 694d34d

Browse files
authored
[FIX][URGENT] Fix /custom endpoint (#854)
* Fix /custom endpoint Signed-off-by: Tarun Arora <tarun.arora.030402@gmail.com> * Fix unittests for /custom endpoint Signed-off-by: Tarun Arora <tarun.arora.030402@gmail.com> --------- Signed-off-by: Tarun Arora <tarun.arora.030402@gmail.com>
1 parent 1f0fdb3 commit 694d34d

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

mod_customized/controllers.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,11 @@ def index():
5252
repository = gh.get_repo(f"{username}/{g.github['repository']}")
5353
# Only commits since last month
5454
last_month = datetime.now() - timedelta(days=30)
55-
commit_since = last_month.isoformat() + 'Z'
56-
commits = repository.get_commits(since=commit_since)
55+
commits = repository.get_commits(since=last_month)
5756
commit_arr = []
5857
for commit in commits:
59-
commit_url = commit['html_url']
60-
commit_sha = commit['sha']
58+
commit_url = commit.html_url
59+
commit_sha = commit.sha
6160
commit_option = f'<a href="{commit_url}">{commit_sha}</a>'
6261
commit_arr.append((commit_sha, commit_option))
6362
# If there are commits present, display it on webpage

tests/test_customized/test_controllers.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ def test_customize_test_creates_with_multiple_platforms(self, mock_user, mock_re
118118
def test_customize_test_creates_with_select_arr(self, mock_user, mock_repo):
119119
"""Test customize test creation with commits list."""
120120
from flask import g
121+
from github.Commit import Commit
121122

122123
import mod_customized.controllers
123124
reload(mod_customized.controllers)
@@ -128,14 +129,17 @@ def test_customize_test_creates_with_select_arr(self, mock_user, mock_repo):
128129
for i in range(num_commits):
129130
commit_hash = self.create_random_string()
130131
url = f"https://github.com/{return_git_user()}/{g.github['repository']}/commit/{commit_hash}"
131-
commits.append({'html_url': url, 'sha': commit_hash})
132+
new_commit = mock.MagicMock(Commit)
133+
new_commit.sha = commit_hash
134+
new_commit.html_url = url
135+
commits.append(new_commit)
132136
with self.app.test_client() as c:
133137
c.post('/account/login', data=self.create_login_form_data(self.user.email, self.user.password))
134138

135139
mock_repo.return_value.get_commits.return_value = commits
136140
response = c.get('/custom/')
137141
for commit in commits:
138-
self.assertIn(commit['sha'], str(response.data))
142+
self.assertIn(commit.sha, str(response.data))
139143

140144
def test_customize_regression_tests_load(self, mock_user, mock_repo):
141145
"""Test loading of the regression tests."""

0 commit comments

Comments
 (0)