Skip to content

Commit

Permalink
[FEATURE] Validate on Wrong Commit Hash (#248)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatejMecka authored and canihavesomecoffee committed Nov 22, 2018
1 parent a908ec0 commit 87d9348
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
4 changes: 3 additions & 1 deletion mod_customized/controllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ def index():
)
# Show error if github fails to recognize commit
response = requests.get(api_url)
if response.status_code == 404:
if response.status_code == 500:
fork_test_form.commit_hash.errors.append('Error contacting Github')
elif response.status_code != 200:
fork_test_form.commit_hash.errors.append('Wrong Commit Hash')
else:
add_test_to_kvm(username, commit_hash, platforms, regression_tests)
Expand Down
2 changes: 2 additions & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ def MockRequests(url, data=None, timeout=None):
'user': {'login': 'test_user'},
'created_at': '2011-04-14T16:00:49Z',
'state': 'open'}, 201)
elif url == "https://api.github.com/repos/test/test_repo/commits/mockWillReturn500":
return MockResponse({}, 500)
else:
return MockResponse({}, 404)

Expand Down
47 changes: 47 additions & 0 deletions tests/test_customized/TestControllers.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,3 +178,50 @@ def test_customize_test_creates_with_customize_regression_tests(self, mock_user,
regression_tests = test.get_customized_regressiontests()
self.assertIn(2, regression_tests)
self.assertNotIn(1, regression_tests)

def test_customize_test_github_server_error(self, mock_user, mock_git, mock_requests):
"""
Test in case github ever returns a 500 error
"""

import mod_customized.controllers
reload(mod_customized.controllers)

self.create_user_with_role(
self.user.name, self.user.email, self.user.password, Role.tester)

with self.app.test_client() as c:
response_login = c.post('/account/login',
data=self.create_login_form_data(self.user.email, self.user.password))

# Base.py: MockRequests
response = c.post('/custom/',
data=self.create_customize_form('mockWillReturn500', ['linux'],
regression_test=[2]), follow_redirects=True)

# Validate if View Works
self.assertEqual(response.status_code, 200)
self.assertIn("Error contacting Github", str(response.data))

def test_customize_test_wrong_commit_hash(self, mock_user, mock_git, mock_requests):
"""
Test in case if a wrong hash is submitted
"""

import mod_customized.controllers
reload(mod_customized.controllers)

self.create_user_with_role(
self.user.name, self.user.email, self.user.password, Role.tester)

with self.app.test_client() as c:
response_login = c.post('/account/login',
data=self.create_login_form_data(self.user.email, self.user.password))

response = c.post('/custom/',
data=self.create_customize_form('SomeoneSendMeCleanAirPlease', ['linux'],
regression_test=[2]), follow_redirects=True)

# Validate if View Works
self.assertEqual(response.status_code, 200)
self.assertIn("Wrong Commit Hash", str(response.data))

0 comments on commit 87d9348

Please sign in to comment.