diff --git a/community/community/doctype/community_member/community_member.py b/community/community/doctype/community_member/community_member.py index 5c0b6c69..51ec1095 100644 --- a/community/community/doctype/community_member/community_member.py +++ b/community/community/doctype/community_member/community_member.py @@ -32,12 +32,13 @@ class CommunityMember(Document): return f"" def create_member_from_user(doc, method): + username = doc.username if ( doc.username and username_exists(doc.username)) or not doc.username: username = create_username_from_email(doc.email) - if len(doc.username) < 4: + elif len(doc.username) < 4: username = adjust_username(doc.username) - if username_exists(username): - username = username + str(random.randint(0,9)) + if username_exists(username): + username = username + str(random.randint(0,9)) member = frappe.get_doc({ "doctype": "Community Member", diff --git a/community/community/doctype/community_member/test_community_member.py b/community/community/doctype/community_member/test_community_member.py index 71f79bb8..f3c109d6 100644 --- a/community/community/doctype/community_member/test_community_member.py +++ b/community/community/doctype/community_member/test_community_member.py @@ -7,11 +7,14 @@ import frappe import unittest class TestCommunityMember(unittest.TestCase): - - def test_member_created_from_user(self): - user = new_user("Test User", "test_user@example.com") - member = frappe.get_doc("Community Member", {"email": "test_user@example.com"}) - self.assertEqual(user.full_name, member.full_name) - self.assertEqual(member.owner, user.email) - self.assertEqual(user.username, member.username) - self.assertEqual(member.username, member.route) + + def test_member_created_from_user(self): + user = new_user("Test User", "test_user@example.com") + self.assertTrue(frappe.db.exists("Community Member", dict(username=user.username))) + member = frappe.get_doc("Community Member", {"email": "test_user@example.com"}) + self.assertEqual(user.full_name, member.full_name) + self.assertEqual(member.owner, user.email) + self.assertEqual(user.username, member.username) + self.assertEqual(member.username, member.route) + frappe.delete_doc("User", user.name) + \ No newline at end of file diff --git a/community/lms/doctype/lms_course/test_lms_course.py b/community/lms/doctype/lms_course/test_lms_course.py index fd2b1ecf..fe0c209d 100644 --- a/community/lms/doctype/lms_course/test_lms_course.py +++ b/community/lms/doctype/lms_course/test_lms_course.py @@ -11,7 +11,6 @@ class TestLMSCourse(unittest.TestCase): frappe.db.sql('delete from `tabLMS Course Mentor Mapping`') frappe.db.sql('delete from `tabLMS Course`') frappe.db.sql('delete from `tabCommunity Member`') - frappe.db.sql('delete from `tabUser` where email like "%@example.com"') def new_course(self, title): doc = frappe.get_doc({ @@ -27,7 +26,6 @@ class TestLMSCourse(unittest.TestCase): assert course.slug == "test-course" assert course.get_mentors() == [] - # disabled this test as it is failing def _test_add_mentors(self): course = self.new_course("Test Course") assert course.get_mentors() == [] @@ -38,6 +36,7 @@ class TestLMSCourse(unittest.TestCase): mentors = course.get_mentors() mentors_data = [dict(email=mentor.email, batch_count=mentor.batch_count) for mentor in mentors] assert mentors_data == [{"email": "tester@example.com", "batch_count": 0}] + frappe.delete_doc("User", user.name) def new_user(name, email): doc = frappe.get_doc(dict(