def test_target_model(db): session = db() room = Room(title='example', type='room') session.add(room) session.commit() assert session.query(Room).count() == 1 # Test members of a room member = Member(title='example', first_name='example_first_name', last_name='example_last_name', email='*****@*****.**', access_token='access token', reference_id=2) session.add(member) room.members.append(member) room.owner = member session.commit() # Since the selectin loading is used to load relations, # the relation is already load. assert room.members[0].title == 'example' # Test administrators of a room administrator = Member(title='administrator', first_name='admin_first_name', last_name='admin_last_name', email='*****@*****.**', access_token='access token', reference_id=3) session.add(administrator) session.commit() room.administrators.append(administrator) session.commit() assert room.administrators[0].title == 'administrator' assert room.owner_id == 1
def mockup(cls): session = cls.create_session() cls.user1 = Member(email='*****@*****.**', title='user1', access_token='access token1', reference_id=2) session.add(cls.user1) cls.user2 = Member(email='*****@*****.**', title='user2', access_token='access token2', reference_id=3) cls.room1 = Room(title='room1', owner=cls.user2) session.add(cls.room1) cls.room2 = Room(title='room2', owner=cls.user2) session.add(cls.room2) room3 = Room(title='room3', owner=cls.user2) session.add(room3) room4 = Room(title='room4', owner=cls.user2) session.add(room4) room5 = Room(title='room5', owner=cls.user2) session.add(room5) room6 = Room(title='room6', owner=cls.user2) session.add(room6) room7 = Room(title='room7', owner=cls.user2) session.add(room7) session.commit()
def test_message_model(db): session = db() if exists(temp_path): shutil.rmtree(temp_path) message1 = Message( mimetype='message1', body='This is message 1', ) message2 = Message( mimetype='message2', body='This is message 2', ) message3 = Message( mimetype='message3', body='This is message 3', ) member = Member(title='member', first_name='member_first_name', last_name='member_last_name', email='*****@*****.**', access_token='access token', reference_id=1, messages=[message1, message2, message3]) room = Room(title='example', type='room', messages=[message1, message2, message3], members=[member]) session.add(room) session.commit() # Test message model. As every message should have a sender # to be send, sender_id and target_id can not be nullable assert session.query(Message).count() == 3 # Test target id of a message assert message1.target_id == 1 # Test messages of a room assert len(room.messages) == 3 assert room.messages[0].body == 'This is message 1' # Test messages of a member message1.seen_by.append(member) session.commit() assert len(message1.seen_by) == 1 # The replied_to is a many to one relationship message2.reply_to = message1 message3.reply_to = message1 session.commit() assert message2.reply_root == message1.id assert message3.reply_root == message1.id
def mockup(cls): session = cls.create_session() cls.user = Member(email='*****@*****.**', title='user', first_name='user1_first_name', last_name='user1_last_name', access_token='access token', reference_id=1) session.add(cls.user) cls.user1 = Member(email='*****@*****.**', title='user1', first_name='user1_first_name', last_name='user1_last_name', access_token='access token1', reference_id=2) session.add(cls.user1) cls.blocked1 = Member(email='*****@*****.**', title='blocked1', first_name='blocked1_first_name', last_name='blocked1_last_name', access_token='access token3', reference_id=4) cls.blocked2 = Member(email='*****@*****.**', title='blocked2', first_name='blocked2_first_name', last_name='blocked2_last_name', access_token='access token', reference_id=6) cls.room_member = Member(email='*****@*****.**', title='member', first_name='member_first_name', last_name='member_last_name', access_token='access token', reference_id=3) cls.never = Member(email='*****@*****.**', title='never', first_name='first_naver_name', last_name='last_naver_name', access_token='access token', add_to_room=False, reference_id=7) session.add(cls.never) cls.blocker = Member(email='*****@*****.**', title='blocker', first_name='blocker_first_name', last_name='blocker_last_name', access_token='access token4', reference_id=5, blocked_members=[cls.blocked1, cls.blocked2]) session.add(cls.blocker) room = Room(title='example', type='room', members=[cls.room_member]) session.add(room) session.commit()
def mockup(cls): session = cls.create_session() cls.user1 = Member(email='*****@*****.**', title='user1', first_name='user1_first_name', last_name='user1_last_name', access_token='access token1', reference_id=2) cls.user2 = Member(email='*****@*****.**', title='user2', first_name='user2_first_name', last_name='user2_last_name', access_token='access token2', reference_id=3) room1 = Room(title='room1', owner=cls.user1) session.add(room1) room2 = Room(title='room2', owner=cls.user1) session.add(room2) room3 = Room(title='room3', owner=cls.user2) session.add(room3) session.commit()
def mockup(cls): session = cls.create_session() user = Member( email='*****@*****.**', title='user', first_name='user_first_name', last_name='user_last_name', access_token='access token', reference_id=1 ) user1 = Member( email='*****@*****.**', title='user1', first_name='user1_first_name', last_name='user1_last_name', access_token='access token1', reference_id=2 ) user2 = Member( email='*****@*****.**', title='user2', first_name='user2_first_name', last_name='user2_last_name', access_token='access token2', reference_id=3 ) session.add(user2) direct = Direct(members=[user, user1]) session.add(direct) cls.room1 = Room(title='room1', members=[user]) session.add(cls.room1) room2 = Room(title='room2', members=[user1]) session.add(room2) room3 = Room(title='room3', members=[user, user1]) session.add(room3) session.commit()
def test_member_model(db): session = db() member = Member(title='example', first_name='example_first_name', last_name='example_last_name', email='*****@*****.**', access_token='access token', reference_id=4) session.add(member) session.commit() assert session.query(Member).count() == 1 assert member.add_to_room == True # Testing rooms of a member room = Room(title='example') session.add(room) member.rooms.append(room) session.commit() # Since the selectin loading is used to load relations, # the relation is already load. assert member.rooms[0].title == 'example' # Testing rooms of an administrator member.administrator_of.append(room) session.commit() assert member.administrator_of[0].title == 'example' assert member.administrator_of[0].id == 1 # Testing relationship between Member and Member ( As contactlist) contact = Member(title='contact', first_name='contact_first_name', last_name='contact_last_name', email='*****@*****.**', access_token='access token', reference_id=5) session.add(contact) member.contacts.append(contact) session.commit() assert len(member.contacts) == 1 # Testing other side of relationship session.commit() member.blocked_members.append(contact) assert len(member.blocked_members) == 1