Permalink
Browse files

[FIX] Regression test delete (#252)

* Fixed regression test delete

* Update TestControllers.py

* .

* Trying current test with previous model

* Trying current test with previous model

* Update TestControllers.py

* Update TestControllers.py

* Update models.py

* Update models.py

* Trying wrong model. Hopefully it fails the tests

* Trying right model. Hopefully it passes the tests

* Removed an extra print statement

* Added a comment

* Update TestControllers.py
  • Loading branch information...
T1duS authored and canihavesomecoffee committed Dec 14, 2018
1 parent 64e4427 commit a3fd4704b4386bb021b8fc4b4f0f49a2667b63a0
Showing with 36 additions and 21 deletions.
  1. +1 −1 mod_customized/models.py
  2. +17 −5 tests/base.py
  3. +18 −15 tests/test_regression/TestControllers.py
@@ -45,7 +45,7 @@ class CustomizedTest(Base):
id = Column(Integer, primary_key=True)
test_id = Column(Integer, ForeignKey(Test.id, onupdate="CASCADE", ondelete="RESTRICT"))
test = relationship('Test', back_populates='customized_tests')
regression_id = Column(Integer, ForeignKey(RegressionTest.id, onupdate='CASCADE', ondelete='RESTRICT'))
regression_id = Column(Integer, ForeignKey(RegressionTest.id, onupdate='CASCADE', ondelete='CASCADE'))
regression_test = relationship('RegressionTest', uselist=False)

def __init__(self, test_id, regression_id):
@@ -59,7 +59,7 @@ def load_config(file):

def MockRequests(url, data=None, timeout=None):
if url == "https://api.github.com/repos/test/test_repo/commits/abcdef":
return MockResponse({}, 200)
return MockResponse({}, 200)
elif url == "https://api.github.com/user":
return MockResponse({"login": "test"}, 200)
elif "https://api.github.com/user" in url:
@@ -108,6 +108,7 @@ def setUp(self):
self.app.preprocess_request()
g.db = create_session(
self.app.config['DATABASE_URI'], drop_tables=True)
g.db.execute('pragma foreign_keys=on') # Enable Foreign for unit tests
commit_name_linux = 'fetch_commit_' + TestPlatform.linux.value
commit_name_windows = 'fetch_commit_' + TestPlatform.windows.value
general_data = [GeneralData('last_commit', '1978060bf7d2edd119736ba3ba88341f3bec3323'),
@@ -122,13 +123,19 @@ def setUp(self):
repo=g.github['repository'])
fork = Fork(fork_url)
g.db.add(fork)
g.db.commit()
dummy_user = User(signup_information['existing_user_name'], signup_information['existing_user_role'],
signup_information['existing_user_email'], signup_information['existing_user_pwd'])
g.db.add(dummy_user)
g.db.commit()
test = [
Test(TestPlatform.linux, TestType.pull_request,
1, 'master', '1978060bf7d2edd119736ba3ba88341f3bec3323', 1),
Test(TestPlatform.linux, TestType.pull_request,
2, 'master', 'abcdefgh', 1)
1, 'master', 'abcdefgh', 1)
]
g.db.add_all(test)
g.db.commit()
categories = [
Category('Broken', 'Samples that are broken'),
Category('DVB', 'Samples that contain DVB subtitles'),
@@ -137,29 +144,35 @@ def setUp(self):
Category('General', 'General regression samples')
]
g.db.add_all(categories)
g.db.commit()
samples = [
Sample('sample1', 'ts', 'sample1'),
Sample('sample2', 'ts', 'sample2')
]
g.db.add_all(samples)
g.db.commit()
upload = [
Upload(1, 1, 1, Platform.windows),
Upload(1, 2, 1, Platform.linux)
]
g.db.add_all(upload)
g.db.commit()
regression_tests = [
RegressionTest(1, '-autoprogram -out=ttxt -latin1 -2',
InputType.file, OutputType.file, 3, 10),
RegressionTest(2, '-autoprogram -out=ttxt -latin1 -ucla',
InputType.file, OutputType.file, 1, 10)
]
g.db.add_all(regression_tests)
g.db.commit()
categories[0].regression_tests.append(regression_tests[0])
categories[2].regression_tests.append(regression_tests[1])
regression_test_outputs = [
RegressionTestOutput(1, 'sample_out1', '.srt', ''),
RegressionTestOutput(2, 'sample_out2', '.srt', '')
]
g.db.add_all(regression_test_outputs)
g.db.commit()
test_result_progress = [
TestProgress(1, TestStatus.preparation, "Test 1 preperation"),
TestProgress(1, TestStatus.building, "Test 1 building"),
@@ -171,23 +184,22 @@ def setUp(self):
TestProgress(2, TestStatus.completed, "Test 2 completed")
]
g.db.add_all(test_result_progress)
g.db.commit()
test_results = [
TestResult(1, 1, 200, 0, 0),
TestResult(1, 2, 601, 0, 0),
TestResult(2, 1, 200, 200, 0),
TestResult(2, 2, 601, 0, 0)
]
g.db.add_all(test_results)
g.db.commit()
test_result_files = [
TestResultFile(1, 1, 1, 'sample_out1'),
TestResultFile(1, 2, 2, 'sample_out2'),
TestResultFile(2, 1, 1, 'sample_out1'),
TestResultFile(2, 2, 2, 'sample_out2', 'out2')
]
g.db.add_all(test_result_files)
dummy_user = User(signup_information['existing_user_name'], signup_information['existing_user_role'],
signup_information['existing_user_email'], signup_information['existing_user_pwd'])
g.db.add(dummy_user)
g.db.commit()
forbidden_mime = ForbiddenMimeType('application/javascript')
forbidden_ext = [
@@ -1,6 +1,8 @@
from tests.base import BaseTestCase
from mod_auth.models import Role
from mod_regression.models import RegressionTest, Category, InputType, OutputType
from mod_customized.models import CustomizedTest
from mod_test.models import Test
from mod_sample.models import Sample
from flask import g

@@ -52,14 +54,13 @@ def test_delete_if_will_throw_404(self):

def test_delete(self):
"""
Check it will delete the test
:return:
Check it will delete RegressionTest as well as the Customized test
linked with it
"""
# Create Valid Entry
from mod_regression.models import InputType, OutputType

test = RegressionTest(1, '-autoprogram -out=ttxt -latin1 -2', InputType.file, OutputType.file, 3, 10)
g.db.add(test)
# Add customized test linked with regression test
customized_test = CustomizedTest(test_id=1, regression_id=1)
g.db.add(customized_test)
g.db.commit()

# Create Account to Delete Test
@@ -71,14 +72,16 @@ def test_delete(self):
response = c.post(
'/account/login', data=self.create_login_form_data(self.user.email, self.user.password))
response_regression = c.get('/regression/test/1/delete')
self.assertEqual(response_regression.status_code, 200)
self.assertEqual(response_regression.status_code, 200)
response = c.post(
'/regression/test/1/delete', data=dict(
hidden='yes',
submit=True
)
)
self.assertEqual(response.status_code, 302) # 302 is for Redirection
self.assertEqual(RegressionTest.query.filter(RegressionTest.id==1).first(), None)
self.assertEqual(CustomizedTest.query.filter(CustomizedTest.regression_id==1).first(), None)

def test_add_category(self):
"""
@@ -155,7 +158,7 @@ def test_edit_wrong_category(self):
g.db.commit()
response_regression = c.post('regression/category/1729/edit',data=dict(category_name="Sheldon", category_description="That's my spot", submit=True))
self.assertEqual(response_regression.status_code, 404)

def test_add_test(self):
"""
Check it will add a regression test
@@ -237,7 +240,7 @@ def test_category_delete(self):
submit=True
)
)
self.assertEqual(response.status_code, 302) # 302 Is for Redirection,
self.assertEqual(response.status_code, 302) # 302 Is for Redirection,

def test_edit_test(self):
"""
@@ -357,7 +360,7 @@ def test_if_test_regression_view_throws_a_not_found_error(self):
"""
Check if the test doesn't exist and will throw an error 404
"""
response = self.app.test_client().get('regression/test/1337/view')
response = self.app.test_client().get('regression/test/1337/view')
self.assertEqual(response.status_code, 404)

def test_if_test_toggle_view_throws_a_not_found_error(self):
@@ -370,13 +373,13 @@ def test_if_test_toggle_view_throws_a_not_found_error(self):
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.get('regression/test/1337/toggle')

response = c.get('regression/test/1337/toggle')
self.assertEqual(response.status_code, 404)

def test_sample_view(self):
"""
Test if it'll return a valid sample
Test if it'll return a valid sample
"""
response = self.app.test_client().get('/regression/sample/1')
sample = Sample.query.filter(Sample.id == 1).first()
@@ -385,7 +388,7 @@ def test_sample_view(self):

def test_sample_view_nonexistent(self):
"""
Test if it'll return a valid sample
Test if it'll return a valid sample
"""
response = self.app.test_client().get('/regression/sample/13423423')
self.assertEqual(response.status_code, 404)

0 comments on commit a3fd470

Please sign in to comment.