From d592f53f7ac1ae26c566647734884d155f7f3b9d Mon Sep 17 00:00:00 2001 From: the catalyst Date: Wed, 22 Jan 2020 13:34:34 +0530 Subject: [PATCH 1/6] add User tests for UserManager.py --- components/core/UserManager.py | 4 +-- components/core/tests/User_tests.py | 53 +++++++++++++++++++++++++++++ components/core/tests/login_test.py | 3 +- ui/package.json | 10 ++++-- 4 files changed, 64 insertions(+), 6 deletions(-) create mode 100644 components/core/tests/User_tests.py diff --git a/components/core/UserManager.py b/components/core/UserManager.py index 74d5fe0e..b52d24b3 100644 --- a/components/core/UserManager.py +++ b/components/core/UserManager.py @@ -38,7 +38,7 @@ def check_user_name(username): if db is not None: cursor = db.cursor() sql = "SELECT * FROM user WHERE user_name=%s;" - cursor.execute(sql, (username)) + cursor.execute(sql, (username,)) data = cursor.fetchone() db.close() if data == None: @@ -95,7 +95,7 @@ def remove_user(username): cursor = db.cursor() sql = "DELETE from user WHERE user_name=%s;" try: - cursor.execute(sql, (username)) + cursor.execute(sql, (username,)) db.commit() except MySQLdb.Error as e: db.rollback() diff --git a/components/core/tests/User_tests.py b/components/core/tests/User_tests.py new file mode 100644 index 00000000..c46686b9 --- /dev/null +++ b/components/core/tests/User_tests.py @@ -0,0 +1,53 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +from UserManager import * +import unittest +import Models + +class User: + def __init__(self,userName,email,password,auth): + self.userName = userName + self.email = email + self.password = password + self.auth = auth + def userName(self): + return self.userName + def password(self): + return self.password + def email(self): + return self.email + def auth(self): + return self.auth + +class Test(unittest.TestCase): + + def test_check_existing_username(self): + self.assertEqual(True,check_user_name('rand')) + + def test_correct_register(self): + self.assertEqual("success", add_user(user = User('normal_user','emailnormal@email.com','12345678','0'))) + + def test_get_user(self): + self.assertIsInstance(get_user('normal_user'),Models.User) + + def test_incorrect_regular_register_before_regular_user_register(self): + self.assertEqual("username taken", add_regular_user(user = User('normal_user','emailnormal@email.com','12345678','0'))) + + def test_correct_regular_user_register(self): + self.assertEqual("success", add_regular_user(user = User('reg','emailregular@email.com','12345678','0'))) + + def test_incorrect_regular_register_after_regular_user_register(self): + self.assertEqual("username taken", add_regular_user(user = User('reg','emailregular@email.com','12345678','0'))) + + def test_update_user(self): + self.assertEqual("success",update_user(user = User('updated_user','emailregular@email.com','12345678','0'),username = "normal_user")) + + def test_remove_user(self): + self.assertEqual("success", remove_user('updated_user')) + + def test_remove_regular_user(self): + self.assertEqual("success", remove_user('reg')) + +if __name__ == "__main__": + unittest.main() + diff --git a/components/core/tests/login_test.py b/components/core/tests/login_test.py index db3849f6..851f65ff 100644 --- a/components/core/tests/login_test.py +++ b/components/core/tests/login_test.py @@ -35,4 +35,5 @@ def test_correct_check_approved(self): self.assertEqual(True, check_approved(usernamer(), passwordr())) -unittest.main() +if __name__ == "__main__": + unittest.main() diff --git a/ui/package.json b/ui/package.json index c4638552..02257ffd 100644 --- a/ui/package.json +++ b/ui/package.json @@ -42,7 +42,11 @@ } ], "dependencies": { - "jasmine-core": "^2.5.2" + "fsevents": "^2.1.2", + "gyp": "^0.5.0", + "jasmine-core": "^2.5.2", + "natives": "^1.1.6", + "node-gyp": "^5.0.7" }, "homepage": "http://www.scorelab.org/Bassa/", "devDependencies": { @@ -78,7 +82,7 @@ "gulp-rev": "~2.0.1", "gulp-rev-replace": "~0.3.1", "gulp-ruby-sass": "~0.7.1", - "gulp-sass": "^2.3.2", + "gulp-sass": "^3.1.0", "gulp-size": "~1.1.0", "gulp-uglify": "3.0.0", "gulp-uglify-es": "^1.0.4", @@ -96,7 +100,7 @@ "karma-jasmine-html-reporter": "^0.2.2", "karma-spec-reporter": "0.0.26", "main-bower-files": "~2.4.0", - "node-sass": "^4.5.0", + "node-sass": "^4.13.0", "postcss": "^5.1.2", "prettier": "^1.2.2", "protractor": "~1.4.0", From f3b8d503f96283211ab067d49ec565f7a041d735 Mon Sep 17 00:00:00 2001 From: the catalyst Date: Wed, 22 Jan 2020 19:37:27 +0530 Subject: [PATCH 2/6] reformatted code --- components/core/tests/User_tests.py | 37 ++++++++++++++++++----------- minio-py | 1 + 2 files changed, 24 insertions(+), 14 deletions(-) create mode 160000 minio-py diff --git a/components/core/tests/User_tests.py b/components/core/tests/User_tests.py index c46686b9..c9fc10ab 100644 --- a/components/core/tests/User_tests.py +++ b/components/core/tests/User_tests.py @@ -1,53 +1,62 @@ -#!/usr/bin/python +# !/usr/bin/python # -*- coding: utf-8 -*- from UserManager import * import unittest import Models + class User: - def __init__(self,userName,email,password,auth): + def __init__(self, userName, email, password, auth): self.userName = userName self.email = email self.password = password self.auth = auth + def userName(self): return self.userName + def password(self): return self.password + def email(self): return self.email + def auth(self): return self.auth + class Test(unittest.TestCase): def test_check_existing_username(self): - self.assertEqual(True,check_user_name('rand')) + self.assertEqual(True, check_user_name('rand')) def test_correct_register(self): - self.assertEqual("success", add_user(user = User('normal_user','emailnormal@email.com','12345678','0'))) + self.assertEqual("success", add_user(user=User('normal_user', 'emailnormal@email.com', '12345678', '0'))) def test_get_user(self): - self.assertIsInstance(get_user('normal_user'),Models.User) - + self.assertIsInstance(get_user('normal_user'), Models.User) + def test_incorrect_regular_register_before_regular_user_register(self): - self.assertEqual("username taken", add_regular_user(user = User('normal_user','emailnormal@email.com','12345678','0'))) + self.assertEqual("username taken", + add_regular_user(user=User('normal_user', 'emailnormal@email.com', '12345678', '0'))) def test_correct_regular_user_register(self): - self.assertEqual("success", add_regular_user(user = User('reg','emailregular@email.com','12345678','0'))) + self.assertEqual("success", add_regular_user(user=User('reg', 'emailregular@email.com', '12345678', '0'))) def test_incorrect_regular_register_after_regular_user_register(self): - self.assertEqual("username taken", add_regular_user(user = User('reg','emailregular@email.com','12345678','0'))) + self.assertEqual("username taken", + add_regular_user(user=User('reg', 'emailregular@email.com', '12345678', '0'))) def test_update_user(self): - self.assertEqual("success",update_user(user = User('updated_user','emailregular@email.com','12345678','0'),username = "normal_user")) + self.assertEqual("success", update_user(user=User('updated_user', 'emailregular@email.com', '12345678', '0'), + username="normal_user")) def test_remove_user(self): - self.assertEqual("success", remove_user('updated_user')) + self.assertEqual("success", remove_user('updated_user')) def test_remove_regular_user(self): - self.assertEqual("success", remove_user('reg')) - + self.assertEqual("success", remove_user('reg')) + + if __name__ == "__main__": unittest.main() - diff --git a/minio-py b/minio-py new file mode 160000 index 00000000..d09af8f3 --- /dev/null +++ b/minio-py @@ -0,0 +1 @@ +Subproject commit d09af8f32bb49a2f3fc8e687048746cdfa356c94 From 613ee6cf66c1be2593216b05842b11a9a5408a73 Mon Sep 17 00:00:00 2001 From: the catalyst Date: Thu, 30 Jan 2020 17:24:52 +0530 Subject: [PATCH 3/6] add testing.mysqld module to create mock database for testing --- components/core/tests/User_tests.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/components/core/tests/User_tests.py b/components/core/tests/User_tests.py index c9fc10ab..72b2f6df 100644 --- a/components/core/tests/User_tests.py +++ b/components/core/tests/User_tests.py @@ -5,6 +5,13 @@ import Models +import unittest +import testing.mysqld + +# Generate Mysqld class which shares the generated database +Mysqld = testing.mysqld.MysqldFactory(cache_initialized_db=True) + + class User: def __init__(self, userName, email, password, auth): self.userName = userName @@ -26,6 +33,16 @@ def auth(self): class Test(unittest.TestCase): + def setUp(self): + # Use the generated Mysqld class instead of testing.mysqld.Mysqld + self.mysqld = Mysqld() + + def tearDown(self): + self.mysqld.stop() + + def tearDownModule(self): + # clear cached database at end of tests + Mysqld.clear_cache() def test_check_existing_username(self): self.assertEqual(True, check_user_name('rand')) @@ -48,7 +65,7 @@ def test_incorrect_regular_register_after_regular_user_register(self): add_regular_user(user=User('reg', 'emailregular@email.com', '12345678', '0'))) def test_update_user(self): - self.assertEqual("success", update_user(user=User('updated_user', 'emailregular@email.com', '12345678', '0'), + self.assertEqual("success", update_user(user=User('updated_user', 'emailnormal@email.com', '12345678', '0'), username="normal_user")) def test_remove_user(self): From 38843f823d5443ff8c3cec5923c3d223d389c7ba Mon Sep 17 00:00:00 2001 From: the catalyst Date: Fri, 31 Jan 2020 19:12:22 +0530 Subject: [PATCH 4/6] add testing.mysqld to existing tests and change name of file to user_test.py --- components/core/tests/Bassa_endpoint_test.py | 15 +++++++++++++++ components/core/tests/login_test.py | 14 ++++++++++++++ .../core/tests/{User_tests.py => user_test.py} | 10 +++++----- 3 files changed, 34 insertions(+), 5 deletions(-) rename components/core/tests/{User_tests.py => user_test.py} (89%) diff --git a/components/core/tests/Bassa_endpoint_test.py b/components/core/tests/Bassa_endpoint_test.py index a97101e8..01773c19 100644 --- a/components/core/tests/Bassa_endpoint_test.py +++ b/components/core/tests/Bassa_endpoint_test.py @@ -1,6 +1,10 @@ import unittest import requests +import testing.mysqld +# Generate MYSQLD class which shares the generated database +MYSQLD = testing.mysqld.MysqldFactory(cache_initialized_db=True) + headers = { 'Host': 'localhost:5000', 'Accept': 'application/json, text/plain, */*', @@ -17,6 +21,17 @@ incorrect_string="user_name="+incorrect_username+"&password="+incorrect_password payload = {''} class TestFlaskAPIUsingRequests(unittest.TestCase): + def setUp(self): + # Use the generated MYSQLD class instead of testing.mysqld + self.mysqld = MYSQLD() + + def tearDown(self): + self.mysqld.stop() + + def tearDownModule(self): + # clear cached database at end of tests + MYSQLD.clear_cache() + def test_api_login_returns_auth_level(self): resp = requests.post('http://localhost:5000/api/login',correct_string,headers=headers) self.assertEqual(resp.json(),{u'auth': u'0'}) diff --git a/components/core/tests/login_test.py b/components/core/tests/login_test.py index 851f65ff..933f301a 100644 --- a/components/core/tests/login_test.py +++ b/components/core/tests/login_test.py @@ -3,6 +3,10 @@ from UserManager import * import unittest +import testing.mysqld +# Generate MYSQLD class which shares the generated database +MYSQLD = testing.mysqld.MysqldFactory(cache_initialized_db=True) + def username(): return 'admin' @@ -21,6 +25,16 @@ def passwordr(): class Test(unittest.TestCase): + def setUp(self): + # Use the generated MYSQLD class instead of testing.mysqld + self.mysqld = MYSQLD() + + def tearDown(self): + self.mysqld.stop() + + def tearDownModule(self): + # clear cached database at end of tests + MYSQLD.clear_cache() def test_incorrect_login(self): self.assertEqual(False, user_login(username(), password())) diff --git a/components/core/tests/User_tests.py b/components/core/tests/user_test.py similarity index 89% rename from components/core/tests/User_tests.py rename to components/core/tests/user_test.py index 72b2f6df..4ad400b7 100644 --- a/components/core/tests/User_tests.py +++ b/components/core/tests/user_test.py @@ -8,8 +8,8 @@ import unittest import testing.mysqld -# Generate Mysqld class which shares the generated database -Mysqld = testing.mysqld.MysqldFactory(cache_initialized_db=True) +# Generate MYSQLD class which shares the generated database +MYSQLD = testing.mysqld.MysqldFactory(cache_initialized_db=True) class User: @@ -34,15 +34,15 @@ def auth(self): class Test(unittest.TestCase): def setUp(self): - # Use the generated Mysqld class instead of testing.mysqld.Mysqld - self.mysqld = Mysqld() + # Use the generated MYSQLD class instead of testing.mysqld + self.mysqld = MYSQLD() def tearDown(self): self.mysqld.stop() def tearDownModule(self): # clear cached database at end of tests - Mysqld.clear_cache() + MYSQLD.clear_cache() def test_check_existing_username(self): self.assertEqual(True, check_user_name('rand')) From 44c033dd23fa3b980b73fabd6a173db2453ef806 Mon Sep 17 00:00:00 2001 From: the catalyst Date: Wed, 5 Feb 2020 00:34:30 +0530 Subject: [PATCH 5/6] refined test running message --- components/core/tests/Bassa_endpoint_test.py | 4 +++- components/core/tests/login_test.py | 5 ++++- components/core/tests/user_test.py | 4 +++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/components/core/tests/Bassa_endpoint_test.py b/components/core/tests/Bassa_endpoint_test.py index 01773c19..0da5bd6f 100644 --- a/components/core/tests/Bassa_endpoint_test.py +++ b/components/core/tests/Bassa_endpoint_test.py @@ -39,4 +39,6 @@ def test_api_login_incorrectly_return_403(self): resp = requests.post('http://localhost:5000/api/login',incorrect_string,headers=headers) self.assertEqual(resp.status_code,403) if __name__ == "__main__": - unittest.main() + suite = unittest.TestLoader().loadTestsFromTestCase(Test) + unittest.TextTestRunner(verbosity=2).run(suite) + diff --git a/components/core/tests/login_test.py b/components/core/tests/login_test.py index 933f301a..78a1eb52 100644 --- a/components/core/tests/login_test.py +++ b/components/core/tests/login_test.py @@ -50,4 +50,7 @@ def test_correct_check_approved(self): if __name__ == "__main__": - unittest.main() + suite = unittest.TestLoader().loadTestsFromTestCase(Test) + unittest.TextTestRunner(verbosity=2).run(suite) + + diff --git a/components/core/tests/user_test.py b/components/core/tests/user_test.py index 4ad400b7..b52a8321 100644 --- a/components/core/tests/user_test.py +++ b/components/core/tests/user_test.py @@ -76,4 +76,6 @@ def test_remove_regular_user(self): if __name__ == "__main__": - unittest.main() + suite = unittest.TestLoader().loadTestsFromTestCase(Test) + unittest.TextTestRunner(verbosity=2).run(suite) + From 14807b2aa0aded37b29feccb06019411ea9db82f Mon Sep 17 00:00:00 2001 From: Aditya Bhatnagar <43586052+carpecodeum@users.noreply.github.com> Date: Wed, 5 Feb 2020 15:56:18 +0530 Subject: [PATCH 6/6] fixed error in naming loadfromtestcase --- components/core/tests/Bassa_endpoint_test.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/core/tests/Bassa_endpoint_test.py b/components/core/tests/Bassa_endpoint_test.py index 0da5bd6f..19371424 100644 --- a/components/core/tests/Bassa_endpoint_test.py +++ b/components/core/tests/Bassa_endpoint_test.py @@ -39,6 +39,6 @@ def test_api_login_incorrectly_return_403(self): resp = requests.post('http://localhost:5000/api/login',incorrect_string,headers=headers) self.assertEqual(resp.status_code,403) if __name__ == "__main__": - suite = unittest.TestLoader().loadTestsFromTestCase(Test) + suite = unittest.TestLoader().loadTestsFromTestCase(TestFlaskAPIUsingRequests) unittest.TextTestRunner(verbosity=2).run(suite)