Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add User tests for UserManager.py #868

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/core/UserManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
19 changes: 18 additions & 1 deletion components/core/tests/Bassa_endpoint_test.py
Original file line number Diff line number Diff line change
@@ -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, */*',
Expand All @@ -17,11 +21,24 @@
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'})
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)

20 changes: 19 additions & 1 deletion components/core/tests/login_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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()))
Expand All @@ -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)


Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unwanted new line.

81 changes: 81 additions & 0 deletions components/core/tests/user_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# !/usr/bin/python
# -*- coding: utf-8 -*-
from UserManager import *
import unittest
import Models


import unittest

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate import statement. Same as in line no:4.

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', '[email protected]', '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', '[email protected]', '12345678', '0')))

def test_correct_regular_user_register(self):
self.assertEqual("success", add_regular_user(user=User('reg', '[email protected]', '12345678', '0')))

def test_incorrect_regular_register_after_regular_user_register(self):
self.assertEqual("username taken",
add_regular_user(user=User('reg', '[email protected]', '12345678', '0')))

def test_update_user(self):
self.assertEqual("success", update_user(user=User('updated_user', '[email protected]', '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)

1 change: 1 addition & 0 deletions minio-py
Submodule minio-py added at d09af8
10 changes: 7 additions & 3 deletions ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,11 @@
}
],
"dependencies": {
"jasmine-core": "^2.5.2"
"fsevents": "^2.1.2",
"gyp": "^0.5.0",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why did the package.json changed for python tests?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these have come during the setup of the frontend. these packages were somewhat required to complete the setup otherwise a few errors were flashing. any suggestions are most welcome.

"jasmine-core": "^2.5.2",
"natives": "^1.1.6",
"node-gyp": "^5.0.7"
},
"homepage": "http://www.scorelab.org/Bassa/",
"devDependencies": {
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down