class ImageTest(unittest.TestCase): aux = Aux() user_aux = UserAux() urlbase = "http://127.0.0.1:8000" def testPostAndGetImage(self): email = "*****@*****.**" self.user_aux.createUser(email) #pega id do usuario url = "/user/email/" + email res = self.aux.getFunction(self.urlbase, url) id = json.loads(res)[0]['id'] url = "/user/picture" with open("test/sample.jpg", "rb") as imageFile: str = base64.b64encode(imageFile.read()) param = {"type": "jpg", "bytecode": str, "id_user": id}; response = self.aux.postFunction(self.urlbase, url, param) self.assertEqual(response, 201) url = "/user/picture/%d" % (id) response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertTrue(len(response['url']) > 0) self.user_aux.deleteUser(email)
class TestMatch(unittest.TestCase): aux = Aux() user_aux = UserAux() urlbase = "http://127.0.0.1:8000" def testGetAll(self): url = "/matches" response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) email = "*****@*****.**" email2 = "*****@*****.**" self.user_aux.createUser(email) self.user_aux.createUser(email2) idd1 = self.user_aux.getIdByEmail(email) idd2 = self.user_aux.getIdByEmail(email2) param = {"id_user_not": idd1, "id_user_has": idd2, "id_skill": "2"} self.aux.postFunction(self.urlbase, url, param) response1 = self.aux.getFunction(self.urlbase, url) response1 = json.loads(response1) self.assertTrue(len(response) < len(response1)) ##TEM CASCADE? AO DELETAR UM USER - REFLETE NAS OUTRAS TABELAS? self.user_aux.deleteUser(email) self.user_aux.deleteUser(email2)
class UserAux: aux = Aux() urlbase = "http://127.0.0.1:8000" def createUser(self, email): self.deleteUser(email) url = "/user" json = { "name": "Teste1", "email": email, "age": "21", "password": "******" } return self.aux.postFunction(self.urlbase, url, json) def getIdByEmail(self, email): url = "/user/email/" + email res = self.aux.getFunction(self.urlbase, url) return json.loads(res)[0]['id'] def deleteUser(self, email): url = "/user/email/" + email res = self.aux.getFunction(self.urlbase, url) if res == "[]": return idd = json.loads(res)[0]['id'] url = "/user/" self.aux.deleteFunction(self.urlbase, url, idd) if __name__ == "__main__": print("MAIN")
class SkillTest(unittest.TestCase): aux = Aux() urlbase = "http://127.0.0.1:8000" def testGetSkills(self): url = "/skill" response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertTrue(response != "[]") def testGetSkillByID(self): url = "/skill/2" response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) #TO DO ##colocar nome da skill com ID 10 self.assertTrue(response[0]['name'] == "Programar em Java") def testGetSkillAutoComplete(self): name = "jav" #pega id do usuario url = "/skill/autocomplete/" + name response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) #TO DO ## Ver esse retorno self.assertTrue(response != "[]")
class UserTest(unittest.TestCase): aux = Aux() user_aux = UserAux() urlbase = "http://127.0.0.1:8000" def testPost(self): email = "*****@*****.**" self.assertEqual(self.user_aux.createUser(email), 201) self.user_aux.deleteUser(email) def testGetByEmail(self): email = "*****@*****.**" self.user_aux.createUser(email) url = "/user/email/" + email res = self.aux.getFunction(self.urlbase, url) self.assertEqual(json.loads(res)[0]['email'], email) self.user_aux.deleteUser(email) def testDelete(self): email = "*****@*****.**" self.user_aux.createUser(email) url = "/user/email/" + email res = self.aux.getFunction(self.urlbase, url) idd = json.loads(res)[0]['id'] url = "/user/" self.assertEqual(self.aux.deleteFunction(self.urlbase, url, idd), 200)
class TestUserSkill(unittest.TestCase): aux = Aux() user_aux = UserAux() urlbase = "http://127.0.0.1:8000" def testGetAll(self): email = "*****@*****.**" self.user_aux.createUser(email) idd1 = self.user_aux.getIdByEmail(email) self.createSkill(idd1) url = "/users/skills" response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertTrue(len(response) > 0) self.user_aux.deleteUser(email) def testGetSkillByUser(self): email = "*****@*****.**" self.user_aux.createUser(email) idd1 = self.user_aux.getIdByEmail(email) self.createSkill(idd1) url = "/user/%d/skills" % (idd1) response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(1, len(response)) self.user_aux.deleteUser(email) def testGetUserBySkill(self): email = "*****@*****.**" self.user_aux.createUser(email) idd1 = self.user_aux.getIdByEmail(email) self.createSkill(idd1) url = "/skill/%d/users" % (10) response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(1, len(response)) self.user_aux.deleteUser(email) def createSkill(self, idd): url = "/users/skills" param = {"id_user": idd, "id_skill": "10"} self.aux.postFunction(self.urlbase, url, param)
class FunTest(unittest.TestCase): aux = Aux() urlbase = "http://127.0.0.1:8000" def testPost(self): email = "*****@*****.**" # self.deleteUser(email) # url= "/user" # param = { "name":"Teste1","email":email,"age":"21","password":"******"} # self.assertEqual(self.aux.postFunction(self.urlbase, url, param), 201) # self.deleteUser(email) def testGetByEmail(self): email = "*****@*****.**" # self.deleteUser(email) # url= "/user" # param = { "name":"Teste","email":email,"age":"21","password":"******"} # self.aux.postFunction(self.urlbase, url, param) # url = "/user/email/" + email # res = self.aux.getFunction(self.urlbase, url) # self.assertEqual(json.loads(res)[0]['email'], email) # self.deleteUser(email) def testDelete(self): email = "*****@*****.**" # self.deleteUser(email) # url= "/user" # param = { "name":"Teste3","email":email,"age":"21","password":"******"} # self.aux.postFunction(self.urlbase, url, param) # url = "/user/email/" + email # res = self.aux.getFunction(self.urlbase, url) # idd = json.loads(res)[0]['id'] # url = "/user/" # self.assertEqual( self.aux.deleteFunction(self.urlbase, url,idd), 200) def deleteUser(self, email):
class LoginTest(unittest.TestCase): aux = Aux() user_aux = UserAux() urlbase = "http://127.0.0.1:8000" def testExistentLogin(self): email = "*****@*****.**" self.user_aux.createUser(email) #pega id do usuario url = "/login" param = {"email" : email, "password": "******"} response = self.aux.login(self.urlbase, url, param) self.assertTrue(response == 200) self.user_aux.deleteUser(email) def testNonExistentLogin(self): email = "*****@*****.**" #pega id do usuario url = "/login" param = {"email" : email, "password": "******"} response = self.aux.login(self.urlbase, url, param) self.assertTrue(response == 403) def testWrongPasswordLogin(self): email = "*****@*****.**" self.user_aux.createUser(email) #pega id do usuario url = "/login" param = {"email" : email, "password": "******"} response = self.aux.login(self.urlbase, url, param) self.assertTrue(response == 403) self.user_aux.deleteUser(email)
class UserTest(unittest.TestCase): aux = Aux() user_aux = UserAux() urlbase = "http://127.0.0.1:8000" def testGetAll(self): email = "*****@*****.**" self.user_aux.createUser(email) url = "/users/infos" response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(0, len(response)) idd = self.user_aux.getIdByEmail(email) self.createInfo(idd) url = "/users/infos" response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(1, len(response)) self.user_aux.deleteUser(email) def testPut(self): email = "*****@*****.**" self.user_aux.createUser(email) idd = self.user_aux.getIdByEmail(email) self.createInfo(idd) url = "/user/info/%d" % (idd) response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(84111111111, response[0]['whatsapp']) url = "/user/info" param = { "facebook": "http://www.facebook.com/example", "whatsapp": "84222222222", "id_user": idd } self.aux.putFunction(self.urlbase, url, param) url = "/user/info/%d" % (idd) response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(84222222222, response[0]['whatsapp']) self.user_aux.deleteUser(email) def testDelete(self): email = "*****@*****.**" self.user_aux.createUser(email) idd = self.user_aux.getIdByEmail(email) self.createInfo(idd) url = "/users/infos" response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(1, len(response)) url = "/user/info/" self.assertEqual(self.aux.deleteFunction(self.urlbase, url, idd), 200) url = "/users/infos" response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(0, len(response)) def createInfo(self, idd): url = "/user/info" param = { "facebook": "http://www.facebook.com/example", "whatsapp": "84111111111", "id_user": idd } self.aux.postFunction(self.urlbase, url, param)
class UserTest(unittest.TestCase): aux = Aux() user_aux = UserAux() urlbase = "http://127.0.0.1:8000" def testGetAll(self): email = "*****@*****.**" self.user_aux.createUser(email) url = "/users/interests" response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(0, len(response)) idd = self.user_aux.getIdByEmail(email) self.createInterest(idd) url = "/users/interests" response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(1, len(response)) self.user_aux.deleteUser(email) def testGetInterestByUser(self): email = "*****@*****.**" email2 = "*****@*****.**" self.user_aux.createUser(email) self.user_aux.createUser(email2) idd1 = self.user_aux.getIdByEmail(email) idd2 = self.user_aux.getIdByEmail(email2) self.createInterest(idd1) self.createInterest(idd2) url = "/user/%d/interests" % (idd1) response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(1, len(response)) url = "/user/%d/interests" % (idd2) response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(1, len(response)) self.user_aux.deleteUser(email) self.user_aux.deleteUser(email2) def testGetUserByInterest(self): email = "*****@*****.**" email2 = "*****@*****.**" self.user_aux.createUser(email) self.user_aux.createUser(email2) idd1 = self.user_aux.getIdByEmail(email) idd2 = self.user_aux.getIdByEmail(email2) self.createInterest(idd1) self.createInterest(idd2) url = "/interest/%d/users" % (1) response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(2, len(response)) url = "/users/interests" param = {"id_user": idd1, "id_skill": "2"} self.aux.postFunction(self.urlbase, url, param) url = "/users/interests" param = {"id_user": idd2, "id_skill": "3"} self.aux.postFunction(self.urlbase, url, param) url = "/interest/%d/users" % (2) response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(1, len(response)) url = "/interest/%d/users" % (3) response = self.aux.getFunction(self.urlbase, url) response = json.loads(response) self.assertEqual(1, len(response)) self.user_aux.deleteUser(email) self.user_aux.deleteUser(email2) def createInterest(self, idd): url = "/users/interests" param = {"id_user": idd, "id_skill": "1"} self.aux.postFunction(self.urlbase, url, param)