class CommunityIndexingTestCase(CommunityBaseTestCase): """ Testcase for testing indexing and searching of community content. """ no_login = False SERVICES = ('security', 'indexing') def setUp(self): super(CommunityIndexingTestCase, self).setUp() self.svc = self.app.services['indexing'] self.user = User( email=u'*****@*****.**', password='******', can_login=True) self.session.add(self.user) self.community.set_membership(self.user, READER) self.c2 = Community(name=u'Other community') self.session.add(self.c2) self.user_c2 = User( email=u'*****@*****.**', password='******', can_login=True) self.session.add(self.user_c2) self.c2.set_membership(self.user_c2, READER) self.user_no_community = User( email=u'*****@*****.**', password='******', can_login=True) self.session.add(self.user_no_community) self.session.commit()
def test_mail_templates(db, app_context): # this actually tests that templates are parsed without errors, not the # rendered content user = User(email="*****@*****.**") db.session.add(user) community = Community(name="My Community") db.session.add(community) community.set_membership(user, WRITER) db.session.commit() digests = [CommunityDigest(community)] token = generate_unsubscribe_token(user) ctx = {"digests": digests, "token": token} render_template("notifications/daily-social-digest.txt", **ctx) render_template("notifications/daily-social-digest.html", **ctx)
def setUp(self): super(CommunityIndexingTestCase, self).setUp() self.svc = self.app.services['indexing'] self.user = User( email=u'*****@*****.**', password='******', can_login=True) self.session.add(self.user) self.community.set_membership(self.user, READER) self.c2 = Community(name=u'Other community') self.session.add(self.c2) self.user_c2 = User( email=u'*****@*****.**', password='******', can_login=True) self.session.add(self.user_c2) self.c2.set_membership(self.user_c2, READER) self.user_no_community = User( email=u'*****@*****.**', password='******', can_login=True) self.session.add(self.user_no_community) self.session.commit()
def test_wizard_extract_data(db, csv_file): session = db.session community = Community(name="Hp") g.community = community user1 = User(email="*****@*****.**") user2 = User(email="*****@*****.**") user3 = User(email="*****@*****.**") new_emails = [ "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", ] # creating community session.add(community) # creating users session.add(user1) session.add(user2) session.add(user3) session.flush() # add user1 to the community community.set_membership(user1, READER) session.flush() # check wizard function in case of email list existing_accounts_objects, existing_members_objects, accounts_list = wizard_extract_data( new_emails ) assert set(existing_accounts_objects) == {user2, user3} assert existing_members_objects == [user1] def sorter(x): return x["email"] assert sorted(accounts_list, key=sorter) == sorted( [ { "status": "existing", "first_name": None, "last_name": None, "role": "member", "email": "*****@*****.**", }, { "status": "existing", "first_name": None, "last_name": None, "role": "member", "email": "*****@*****.**", }, { "status": "new", "first_name": "", "last_name": "", "role": "member", "email": "*****@*****.**", }, { "status": "new", "first_name": "", "last_name": "", "role": "member", "email": "*****@*****.**", }, ], key=sorter, ) # check wizard function in case of csv file existing_accounts_objects, existing_members_objects, accounts_list = wizard_extract_data( wizard_read_csv(csv_file), is_csv=True ) assert existing_accounts_objects == { "csv_roles": { "*****@*****.**": "manager", "*****@*****.**": "member", "*****@*****.**": "member", }, "account_objects": [user2], } assert existing_members_objects == [user1] assert sorted(accounts_list, key=sorter) == sorted( [ { "status": "existing", "first_name": None, "last_name": None, "role": "member", "email": "*****@*****.**", }, { "status": "new", "first_name": "userseven", "last_name": "userseven", "role": "member", "email": "*****@*****.**", }, ], key=sorter, )
def community2(db, user2): community = Community(name="Community 2") community.set_membership(user2, READER) db.session.add(community) return community
def setUp(self): super(CommunityBaseTestCase, self).setUp() self.community = Community(name=u"My Community") self.session.add(self.community) self.session.flush()
def test_wizard_extract_data(db, csv_file): session = db.session community = Community(name="Hp") g.community = community user1 = User(email="*****@*****.**") user2 = User(email="*****@*****.**") user3 = User(email="*****@*****.**") new_emails = [ "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", "*****@*****.**", ] # creating community session.add(community) # creating users session.add(user1) session.add(user2) session.add(user3) session.flush() # add user1 to the community community.set_membership(user1, READER) session.flush() # check wizard function in case of email list existing_accounts_objects, existing_members_objects, accounts_list = wizard_extract_data( new_emails) assert set(existing_accounts_objects) == {user2, user3} assert existing_members_objects == [user1] def sorter(x): return x["email"] assert sorted(accounts_list, key=sorter) == sorted( [ { "status": "existing", "first_name": None, "last_name": None, "role": "member", "email": "*****@*****.**", }, { "status": "existing", "first_name": None, "last_name": None, "role": "member", "email": "*****@*****.**", }, { "status": "new", "first_name": "", "last_name": "", "role": "member", "email": "*****@*****.**", }, { "status": "new", "first_name": "", "last_name": "", "role": "member", "email": "*****@*****.**", }, ], key=sorter, ) # check wizard function in case of csv file existing_accounts_objects, existing_members_objects, accounts_list = wizard_extract_data( wizard_read_csv(csv_file), is_csv=True) assert existing_accounts_objects == { "csv_roles": { "*****@*****.**": "manager", "*****@*****.**": "member", "*****@*****.**": "member", }, "account_objects": [user2], } assert existing_members_objects == [user1] assert sorted(accounts_list, key=sorter) == sorted( [ { "status": "existing", "first_name": None, "last_name": None, "role": "member", "email": "*****@*****.**", }, { "status": "new", "first_name": "userseven", "last_name": "userseven", "role": "member", "email": "*****@*****.**", }, ], key=sorter, )