test: evaluation eligibility
This commit is contained in:
@@ -1,55 +1,36 @@
|
||||
# Copyright (c) 2021, FOSS United and Contributors
|
||||
# See license.txt
|
||||
|
||||
# import frappe
|
||||
import unittest
|
||||
import frappe
|
||||
from lms.lms.doctype.lms_course.test_lms_course import new_user
|
||||
|
||||
|
||||
class TestCustomUser(unittest.TestCase):
|
||||
|
||||
def test_with_basic_username(self):
|
||||
new_user = frappe.get_doc({
|
||||
"doctype": "User",
|
||||
"email": "test_with_basic_username@example.com",
|
||||
"first_name": "Username"
|
||||
}).insert(ignore_permissions=True)
|
||||
self.assertEqual(new_user.username, "username")
|
||||
user = new_user("Username", "test_with_basic_username@example.com")
|
||||
self.assertEqual(user.username, "username")
|
||||
|
||||
def test_without_username(self):
|
||||
""" The user in this test has the same first name as the user of the test test_with_basic_username.
|
||||
In such cases frappe makes the username of the second user empty.
|
||||
The condition in lms app should override this and save a username. """
|
||||
new_user = frappe.get_doc({
|
||||
"doctype": "User",
|
||||
"email": "test-without-username@example.com",
|
||||
"first_name": "Username"
|
||||
}).insert(ignore_permissions=True)
|
||||
self.assertTrue(new_user.username)
|
||||
user = new_user("Username", "test-without-username@example.com")
|
||||
self.assertTrue(user.username)
|
||||
|
||||
def test_with_illegal_characters(self):
|
||||
new_user = frappe.get_doc({
|
||||
"doctype": "User",
|
||||
"email": "test_with_illegal_characters@example.com",
|
||||
"first_name": "Username$$"
|
||||
}).insert(ignore_permissions=True)
|
||||
self.assertEqual(new_user.username[:8], "username")
|
||||
user = new_user("Username$$", "test_with_illegal_characters@example.com")
|
||||
self.assertEqual(user.username[:8], "username")
|
||||
|
||||
def test_with_underscore_at_end(self):
|
||||
new_user = frappe.get_doc({
|
||||
"doctype": "User",
|
||||
"email": "test_with_underscore_at_end@example.com",
|
||||
"first_name": "Username___"
|
||||
}).insert(ignore_permissions=True)
|
||||
self.assertNotEqual(new_user.username[-1], "_")
|
||||
user = new_user("Username___", "test_with_underscore_at_end@example.com")
|
||||
self.assertNotEqual(user.username[-1], "_")
|
||||
|
||||
|
||||
def test_with_short_first_name(self):
|
||||
new_user = frappe.get_doc({
|
||||
"doctype": "User",
|
||||
"email": "test_with_short_first_name@example.com",
|
||||
"first_name": "USN"
|
||||
}).insert(ignore_permissions=True)
|
||||
self.assertGreaterEqual(len(new_user.username), 4)
|
||||
user = new_user("USN", "test_with_short_first_name@example.com")
|
||||
self.assertGreaterEqual(len(user.username), 4)
|
||||
|
||||
@classmethod
|
||||
def tearDownClass(cls) -> None:
|
||||
|
||||
Reference in New Issue
Block a user