def test_invalid_channel_invite(): ''' Testing if channel_invite functions return expected outputs if an incorrect u_id and channel_id. ''' data = { "users": [{ "email": "*****@*****.**", "password": hashPassword("validPassword"), "name_first": "validFirst", "name_last": "validLast", "handle": "validFirstvalidLast", "u_id": 1234, "resetCode": None, "is_admin": 1, "img_url": None}, {"u_id": 5678}], "tokens": ["validToken"], "channels": [{ "channel_id": 5000, "members": [1234], }], } with pytest.raises(errors.AccessError): userIsInChannel(data, 5000, 5678)
def channelDetails(): data = getData() token = request.args.get('token') checkTokenValidity(token, data) u_id = getUserFromToken(token) channel_id = int(request.args.get('channel_id')) userIsInChannel(data, channel_id, u_id) return sendSuccess(getDetails(data, channel_id))
def validate_message(data, message, channelid, token, u_id): if channelid in data['channels']: pass else: raise ValueError("invalid token") u_id = getUserFromToken(token) userIsInChannel(data, channelid, u_id) if len(message) > 1000: raise ValueError( "ValueError when:Message is more than 1000 characters")
def channelInvite(): data = getData() token = request.form.get('token') checkTokenValidity(token, data) channel_id, u_id = (request.form[x] for x in ('channel_id', 'u_id')) userIsInChannel(data, int(channel_id), getUserFromToken(token)) if validUser(data, int(u_id)) is False: raise ValueError('The invitee is an invalid user.') addUserToChannel(data, int(channel_id), int(u_id)) return sendSuccess({})
def validate_messageLater(data, message, channelid, token, timeSend, Realtime): if channelid in data['channels']: pass else: raise ValueError("invalid token") u_id = getUserFromToken(token) userIsInChannel(data, channelid, u_id) #value error: Time sent is a time in the past #Value Error time sent is in past if len(message) > 1000: raise ValueError( "ValueError when:Message is more than 1000 characters")
def validate_remove(data, token, messageId): if token in data['tokens']: pass else: raise ValueError("invalid token") u_id = getUserFromToken(token) userIsInChannel(data, channel_id, getUserFromToken(token)) exists = False for channel in data['channels']: for message in channel['messages']: if message['u_id'] == u_id: if message['message_id'] == messageId: exists = True if exists == False: raise ValueError("Invalid IDs")
def channelMessages(): data = getData() token = request.args.get('token') checkTokenValidity(token, data) u_id = getUserFromToken(token) channel_id = request.form.get('channel_id') start = request.form.get('start') userIsInChannel(data, channel_id, u_id) # TODO return sendSuccess({ #'messages': messages, 'start': start, #'end': end, })
def channelDetails(): data = getData() token = request.args.get('token') checkTokenValidity(token, data) u_id = getUserFromToken(token) channel_id = request.form.get('channel_id') userIsInChannel(data, channel_id, u_id) for channel in data['channels']: if channel_id == channel['channel_id']: name = channel['name'] owner_members = channel['owners'] all_members = channel['members'] return sendSuccess({ 'name': name, 'owner_members': owner_members, 'all_members': all_members, })
def unpinMessage(data, token, messageId): if not messageExists(data, messageId): raise ValueError("That message does not exist") u_id = getUserFromToken(token) # Check whether user has the permission to pin for user in data['users']: if user['u_id'] == u_id: if not auth_user['is_admin'] == 2: raise ValueError( 'The authorised user is not an admin or owner') if not isPinned(data, messageId): raise ValueError('That message is not yet pinned') #get the channels id for channel in data['channels']: for message in channel['messages']: if messageId == message['message_id']: cId = channel['channel_id'] userIsInChannel(data, cId, u_id) #end of error checking message['is_pinned'] = 0
def standup_send(data, token, channel_id, message): u_id = getUserFromToken(token) if channelExists(data, channel_id) is False: return ValueError("Channel ID is not a valid channel.") if userIsInChannel(data, channel_id, u_id) is False: return AccessError if len(message) > 1000: return ValueError ("Message exceeds 1000 char limit.") if standupActive(data, channel_id, u_id): #do seomthing else: raise ValueError ("An active standup is not currently running in this channel.")
def standup_send(data, token, channel_id, message): u_id = getUserFromToken(token) if channelExists(data, channel_id) is False: return ValueError("Channel ID is not a valid channel.") if userIsInChannel(data, channel_id, u_id) is False: return AccessError if len(message) > 1000: return ValueError("Message exceeds 1000 char limit.") if standupStillActive(data, channel_id, u_id): alteredMessage = u_id + ":" + message data['channels']['channel_id']['standup_messages'] += alteredMessage else: raise ValueError( "An active standup is not currently running in this channel.")
def standupStartFunc(data, token, channel_id): u_id = getUserFromToken(token) now = datetime.datetime.now() finish = now + datetime.timedelta(minutes = 15) checkTokenValidity(token, data) userIsInChannel(data, channel_id, u_id) if channelExists(data, channel_id) is False: raise ValueError('Channel ID is not a valid channel.') if standupNotActive(data, channel_id, u_id) is True: for channel in data['channels']: if str(channel_id) == channel['channel_id']: channel['standup_active'] = True channel['standup_end'] = finish else: raise ValueError ('A standup is already running in this channel.') ##sets timer to end standup at 'finish' time/posts the standup message standupEnd (data, channel_id, token, finish) return { 'time_finish': finish, }
def standupSendFunc(data, token, channel_id, message): u_id = getUserFromToken(token) if channelExists(data, channel_id) is False: raise ValueError("Channel ID is not a valid channel.") if userIsInChannel(data, channel_id, u_id) is False: return AccessError("User is not in the channel.") if len(message) > 1000: raise ValueError ("Message exceeds 1000 char limit.") if standupStillActive(data, channel_id, u_id): alteredMessage = str(u_id) + ":" + message for channel in data['channels']: if channel == channel_id: channel['standup_message'].append(alteredMessage) else: raise ValueError ("An active standup is not currently running in this channel.")
def channelMessages(): data = getData() token = request.args.get('token') checkTokenValidity(token, data) u_id = getUserFromToken(token) channel_id, start = (request.args[x] for x in ('channel_id', 'start')) channel_id = int(channel_id) start = int(start) userIsInChannel(data, channel_id, u_id) for channel in data['channels']: if channel_id == channel['channel_id']: tempMessages = channel['messages'][::-1] if start > len(tempMessages): raise ValueError('Start is greater than the total number of messages.') return sendSuccess({ 'messages': returnMessages(tempMessages, start), 'start': int(start), 'end': int(endFunc(tempMessages, start)), })
def standup_start(data, token, channel_id): now = datetime.datetime.now() finish = now + datetime.timedelta(minutes = 15) if channelExists(data, channel_id) is False: return ValueError("Channel ID is not a valid channel.") if userIsInChannel(data, channel_id, u_id) is False: return AccessError if standupActive(data, channel_id, u_id) is False: data['channel_id']['standup_active'] = True data['channel_id']['standup_end'] = finish else: raise ValueError ("A standup is already running in this channel.") ##sets timer to end standup at 'finish' time/posts the standup message standupEnd (data, channel_id, u_id, finish) return { 'time_finish': finish, }