Permalink
Browse files

[FEATURE] Validate on Wrong Commit Hash (#248)

  • Loading branch information...
MatejMecka authored and canihavesomecoffee committed Nov 22, 2018
1 parent a908ec0 commit 87d9348677e93cf66ed4c07e7877523fe1b1c697
Showing with 52 additions and 1 deletion.
  1. +3 −1 mod_customized/controllers.py
  2. +2 −0 tests/base.py
  3. +47 −0 tests/test_customized/TestControllers.py
@@ -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)
@@ -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)
@@ -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.