def test_store(db): # Test non-existant member packet = ' {"t":"MESSAGE_CREATE","s":6,"op":0,"d":{"type":0,"tts":false,"timestamp":"2019-01-12T02:05:59.275000+00:00","pinned":false,"nonce":"533466598925664256","mentions":[],"mention_roles":[],"mention_everyone":false,"member":{"roles":[],"mute":false,"joined_at":"2018-12-14T14:18:16.822000+00:00","deaf":false},"id":"533466644060831764","embeds":[],"edited_timestamp":null,"content":"hello there","channel_id":"523141683379175426","author":{"username":"******","id":"181098168266653698","discriminator":"5175","avatar":"7625f24396b5fad487d5b90d36315032"},"attachments":[],"guild_id":"523141683379175424"}}' payload = Payload.from_packet(packet) message = Message.from_payload(payload) store(message, db) # Test existing member packet = ' {"t":"MESSAGE_CREATE","s":6,"op":0,"d":{"type":0,"tts":false,"timestamp":"2019-01-12T02:05:59.275000+00:00","pinned":false,"nonce":"533466598925664256","mentions":[],"mention_roles":[],"mention_everyone":false,"member":{"roles":[],"mute":false,"joined_at":"2018-12-14T14:18:16.822000+00:00","deaf":false},"id":"533466644060831764","embeds":[],"edited_timestamp":null,"content":"hello there","channel_id":"523141683379175426","author":{"username":"******","id":"181098168266653698","discriminator":"5175","avatar":"7625f24396b5fad487d5b90d36315032"},"attachments":[],"guild_id":"523141683379175424"}}' payload = Payload.from_packet(packet) message = Message.from_payload(payload) store(message, db)
def test_top(db): packet = '{"t":"MESSAGE_CREATE","s":5,"op":0,"d":{"type":0,"tts":false,"timestamp":"2019-01-12T01:42:21.512000+00:00","pinned":false,"nonce":"533460652941901824","mentions":[],"mention_roles":[],"mention_everyone":false,"member":{"roles":[],"mute":false,"joined_at":"2018-12-14T14:18:16.822000+00:00","deaf":false},"id":"533460697531809803","embeds":[],"edited_timestamp":null,"content":"!c/top/9","channel_id":"523141683379175426","author":{"username":"******","id":"181098168266653698","discriminator":"5175","avatar":"7625f24396b5fad487d5b90d36315032"},"attachments":[],"guild_id":"523141683379175424"}}' payload = Payload.from_packet(packet) message = Message.from_payload(payload) top(message, db, 5)
def test_to_payload(): payload = MockPayload({ "content": "hello", "channel_id": "my_channel_id123", "author": { "id": "1234", "username": "******", "discriminator": "#1235" }, "timestamp": datetime.datetime.now() }) message = Message.from_payload(payload) new_payload = message.to_payload() assert new_payload["content"] == payload.data["content"] assert new_payload["tts"] == False assert new_payload["embed"] == message.embed
def test_to_json(): payload = MockPayload({ "content": "hello", "channel_id": "my_channel_id123", "author": { "id": "1234", "username": "******", "discriminator": "#1235" }, "timestamp": datetime.datetime.now() }) message = Message.from_payload(payload) payload = message.to_payload() json_payload = message.to_json() reconstructed = json.loads(json_payload) assert payload == reconstructed
def test_from_payload(): payload = MockPayload({ "content": "hello", "channel_id": "my_channel_id123", "author": { "id": "1234", "username": "******", "discriminator": "#1235" }, "timestamp": datetime.datetime.now(), "mentions": [] }) message = Message.from_payload(payload) assert isinstance(message, Message) assert message.content == payload.data["content"] assert message.channel_id == payload.data["channel_id"] assert message.author_id == payload.data["author"]["id"] assert message.username == payload.data["author"]["username"] + "#" + payload.data["author"]["discriminator"] assert message.timestamp == payload.data["timestamp"]