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 1 commit
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
53 changes: 53 additions & 0 deletions components/core/tests/User_tests.py
Original file line number Diff line number Diff line change
@@ -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'))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you use something like PyCharm's auto formatter to format these files.

Copy link
Author

Choose a reason for hiding this comment

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

okay i will do that!


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__":
unittest.main()

3 changes: 2 additions & 1 deletion components/core/tests/login_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ def test_correct_check_approved(self):
self.assertEqual(True, check_approved(usernamer(), passwordr()))


unittest.main()
if __name__ == "__main__":
unittest.main()
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