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/Bassa_endpoint_test.py b/components/core/tests/Bassa_endpoint_test.py index a97101e8..19371424 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'}) @@ -24,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(TestFlaskAPIUsingRequests) + unittest.TextTestRunner(verbosity=2).run(suite) + diff --git a/components/core/tests/login_test.py b/components/core/tests/login_test.py index db3849f6..78a1eb52 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())) @@ -35,4 +49,8 @@ def test_correct_check_approved(self): self.assertEqual(True, check_approved(usernamer(), passwordr())) -unittest.main() +if __name__ == "__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 new file mode 100644 index 00000000..b52a8321 --- /dev/null +++ b/components/core/tests/user_test.py @@ -0,0 +1,81 @@ +# !/usr/bin/python +# -*- coding: utf-8 -*- +from UserManager import * +import unittest +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 + 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 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_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', 'emailnormal@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__": + suite = unittest.TestLoader().loadTestsFromTestCase(Test) + unittest.TextTestRunner(verbosity=2).run(suite) + 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 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",