def test_room(self): room1 = Room('room1') room2 = Room('room2', 'room2') add_tool(room1, room2) db.session.commit() print(room1.id) print(room2.id) self.assertEqual(room1.name, 'room1') self.assertEqual(room2.name, 'room2') self.assertEqual(room1.introduce, ' ') self.assertEqual(room2.introduce, 'room2')
def test_user_room(self): user1 = User('user1', '123456') user2 = User('user2', '123456') user3 = User('user3', '123456') room1 = Room('room1') room2 = Room('room2') add_tool(user1, user2, user3, room1, room2) db.session.commit() room1.users.append(user1) room1.users.append(user3) room2.users.append(user2) room2.users.append(user3) self.assertEqual(user1.rooms[0].name, 'room1') self.assertEqual(user2.rooms[0].name, 'room2') self.assertEqual(user3.rooms[0].name, 'room1') self.assertEqual(user3.rooms[1].name, 'room2')
def post(self): logger.info('{} post method'.format(self.__class__ )) request_json = request.json content = request_json['room'] room_name = content['name'] newroom = Room(room_name) roomid = newroom.add() return roomid, 201
def post(self): data = room_post_reqparse.parse_args() if Room.query.filter_by(name=data['name']).first() is not None: return api_abort(422, 'room name already exit') room = Room(data['name'], data['introduce']) room.owner.append(g.current_user) room.users.append(g.current_user) db.session.add(room) db.session.commit() return make_resp(room_schema(room))
def test_room_message(self): room1 = Room('room1') room2 = Room('room2') message1 = Message('message1', 1, '1') message2 = Message('message2', 1, '1') message3 = Message('message3', 2, '1') room1.messages.append(message1) room2.messages.append(message2) room2.messages.append(message3) add_tool(room1, room2) db.session.commit() print(message1.room_id) self.assertEqual(message1.room.name, 'room1') self.assertEqual(message2.room.name, 'room2') self.assertEqual(message3.room.name, 'room2') db.session.delete(room2) db.session.commit() self.assertEqual(len(Message.query.all()), 1)
from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker from chatroom.models import Room, User, Like, Message engine = create_engine('mysql://*****:*****@db:3306/chatroom2') Session = sessionmaker(bind=engine) session = Session() room = Room('room1') session.add(room) room = Room('room2') session.add(room) session.commit() msg = Message('today is rainy', 1) session.add(msg) msg = Message('cat is cute', 2) session.add(msg) session.commit() user = User('jack') session.add(user) user = User('lola') session.add(user)