test_flask.py 2.66 KB
import os, time, requests, ipdb, json, threading

URL = "http://192.168.15.75:5000/"
TESTPHONE = "5493415959169"
TESTMAIL = "sujetodeprueba0110@gmail.com"
FOLDER = "testfolder/"
SENDING_TIME = 40 # aumentar a medida que se vuelva necesario

def wpp1(phone):
  id = requests.post(url = URL + "data", files = {
    'wpmsg' : open(FOLDER + "wptext","rb"),
    'wpimage' : open(FOLDER + "wpimage","rb"),
    'wpmedia' : open(FOLDER + "wpmedia","rb"),
    'wplink' : open(FOLDER + "wplink","rb")
  })
  assert int(id.text) > 0 , id.text + "no es mayor a 0"
  state = requests.post(url = URL + "msg", params = {
    'id' : id.text,
    'serv' : "wpp1",
    'dest' : phone,
    'type' : json.dumps({
      'wptext' : 'text',
      'wpimage' : 'image',
      'wpmedia' : 'document',
      'wplink' : 'link'
    })
  })
  assert state.text == "queued" , "'" + state.text + "' no es igual a 'queued'"
  time.sleep(SENDING_TIME) 
  state = requests.post(url = URL + "cons", params = {
    'id' : id.text
  })
  assert (state.text == "delivered") , "'" + state.text + "' no es igual a 'delivered'"

def mail(mail):
  id = requests.post(url = URL + "data", files = {
    'mailmsg' : open(FOLDER + "mailtext","rb"),
    'mailimage' : open(FOLDER + "mailimage","rb"),
    'maildocument' : open(FOLDER + "maildocument","rb")
  })
  assert int(id.text) > 0 , id.text + "no es mayor a 0"
  state = requests.post(url = URL + "msg", params = {
    'id' : id.text,
    'serv' : "mail",
    'dest' : mail,
    'type' : json.dumps({
      'mailtext' : 'text',
      'mailimage' : 'image',
      'maildocument' : 'document'
    })
  })
  assert state.text == "queued" , "'" + state.text + "' no es igual a 'queued'"
  time.sleep(SENDING_TIME) 
  state = requests.post(url = URL + "cons", params = {
    'id' : id.text
  })
  assert (state.text == "delivered") , "'" + state.text + "' no es igual a 'delivered'"

def errors():
  # service not valid
  # service unable to send type
  # trying to set type of unexistent file
  # trying to user unexistent table
  # ill-formed comparator
  # data doesn't pass the checks

def main():
  if os.path.exists("messages.db"):
    os.remove("messages.db")

  try:
    os.system("python3 deploy.py &")
    time.sleep(3)
  
    threads = []
    threads.append(threading.Thread(target = wpp1, args = (TESTPHONE,)))
    threads.append(threading.Thread(target = encryption, args = (TESTPHONE,)))
    threads.append(threading.Thread(target = mail, args = (TESTMAIL,)))

    for thread in threads:
      thread.start()

    for thread in threads:
      thread.join()

  except Exception as exp:
    print(type(exp))
    print(exp.args)
  finally:
    os.system("killall python3")


if __name__ == "__main__":
  main()