def test_parametrized_cases_tests(self): """Parametrized cases read from testingCases_RF1.csv""" my_cases = JSON_FILES_PATH + "testingCases_RF1.csv" with open(my_cases, newline='', encoding='utf-8') as csvfile: param_test_cases = csv.DictReader(csvfile, delimiter=',') my_code = AccessManager() for row in param_test_cases: print("Param:" + row['ID TEST'] + row["VALID INVALID"]) if row["VALID INVALID"] == "VALID": valor = my_code.request_access_code( row["DNI"], row["NAME SURNAME"], row["ACCESS TYPE"], row["email"], int(row["VALIDITY"])) self.assertEqual(row['EXPECTED RESULT'], valor) # Check if this DNI is store in storeRequest.json generated_request = AccessRequest.create_request_from_code( valor, row["DNI"]) my_request = AccessRequest(row["DNI"], row["NAME SURNAME"], row["ACCESS TYPE"], row["email"], int(row["VALIDITY"])) self.assertDictEqual(generated_request.__dict__, my_request.__dict__) else: with self.assertRaises(AccessManagementException) as c_m: valor = my_code.request_access_code( row["DNI"], row["NAME SURNAME"], row["ACCESS TYPE"], row["email"], int(row["VALIDITY"])) self.assertEqual(c_m.exception.message, row['EXPECTED RESULT'])
def test_invalid_days_character(self): """Testing an character instead of a number for days""" my_code = AccessManager() with self.assertRaises(AccessManagementException) as c_m: my_code.request_access_code("12345678Z", "Pedro Martin", "Resident", "*****@*****.**", "a") self.assertEqual(c_m.exception.message, "days invalid")
def test_request_access_code_bad_email(self): """ doc """ my_code = AccessManager() with self.assertRaises(AccessManagementException) as c_m: my_code.request_access_code("11111111B", "Jose Lopez", "Guest", "uc3mgmail.com", 2) self.assertEqual(c_m.exception.message, "Email invalid")
def test_request_access_code_dni_bv_ten(self): a = AccessManager() with self.assertRaises(AccessManagementException) as cm: res = a.request_access_code("123456789Z", "GUEST", "JESUS GIL", "*****@*****.**", 2) self.assertEqual(cm.exception.message, "Invalid DNI. More characters than needed")
def test_request_access_code_bad_dni(self): """ doc """ my_code = AccessManager() with self.assertRaises(AccessManagementException) as c_m: my_code.request_access_code("12345678B", "Jose Lopez", "Guest", "*****@*****.**", 20) self.assertEqual(c_m.exception.message, "DNI is not valid")
def test_open_door_bad_key_is_not_found(self): #path: regex ok, key is not found my_key = AccessManager() with self.assertRaises(AccessManagementException) as cm: result = my_key.open_door("fff00d78646ed41a91d60ec2fc1ed326238e510134ca52e5d9b1de5cbdf2b8ab") self.assertEqual("key is not found or is expired", cm.exception.message)
def test_request_access_code_visitor_is_wrong(self): """ doc """ my_code = AccessManager() with self.assertRaises(AccessManagementException) as c_m: my_code.request_access_code("33333333Z", "Jose Lopez", "Visitor", "*****@*****.**", 20) self.assertEqual(c_m.exception.message, "type of visitor invalid")
def test_request_access_code_days_wrong_a(self): """ doc """ my_code = AccessManager() with self.assertRaises(AccessManagementException) as c_m: my_code.request_access_code("55555555Z", "Jose Lopez", "Guest", "*****@*****.**", "A") self.assertEqual(c_m.exception.message, "days invalid")
def test_request_invalid_name(self): a = AccessManager() with self.assertRaises(AccessManagementException) as cm: res = a.request_access_code("12345678Z", "GUEST", "J ", "*****@*****.**", 2) self.assertEqual(cm.exception.message, "Invalid name. Less than 3 characters")
def test_request_name_not_blank(self): a = AccessManager() with self.assertRaises(AccessManagementException) as cm: res = a.request_access_code("12345678Z", "GUEST", "JESUSGIL", "*****@*****.**", 2) self.assertEqual(cm.exception.message, "Invalid name. Blank space not found")
def test_request_access_code_dni_eight_characters(self): a = AccessManager() with self.assertRaises(AccessManagementException) as cm: res = a.request_access_code("1234567Z", "GUEST", "JESUS GIL", "*****@*****.**", 2) self.assertEqual(cm.exception.message, "Invalid DNI. Less than 9 characters found")
def test_request_access_code_dni_only_string(self): a = AccessManager() with self.assertRaises(AccessManagementException) as cm: res = a.request_access_code("ABCDEFGHI", "GUEST", "JESUS GIL", "*****@*****.**", 2) self.assertEqual(cm.exception.message, "Invalid DNI. Only string inserted")
def test_request_access_code_dni_2_letters(self): """ doc""" my_code = AccessManager() with self.assertRaises(AccessManagementException) as c_m: my_code.request_access_code("12345678BB", "Jose Lopez", "Guest", "*****@*****.**", 20) self.assertEqual(c_m.exception.message, "dni invalid")
def test_request_access_code_dni_float(self): a = AccessManager() with self.assertRaises(AccessManagementException) as cm: res = a.request_access_code("12345678.5V", "GUEST", "JESUS GIL", "*****@*****.**", 2) self.assertEqual(cm.exception.message, "Invalid DNI. Float numbers inserted")
def test_get_access_key_bad_access_code(self): my_file = str(Path.home( )) + "/PyCharmProjects/GE3_2021/src/JsonFiles/key_bad_access_code.json" my_key = AccessManager() with self.assertRaises(AccessManagementException) as cm: key = my_key.get_access_key(my_file) self.assertEqual("access code invalid", cm.exception.message)
def test_singleton_access_manager(self): """Instance the three singletons and test they're equal Instance objects from non singleton class and test they're differet""" access_manager_1 = AccessManager() access_manager_2 = AccessManager() access_manager_3 = AccessManager() self.assertEqual(access_manager_1, access_manager_2) self.assertEqual(access_manager_2, access_manager_3) self.assertEqual(access_manager_3, access_manager_1) request_json_store_1 = RequestJsonStore() request_json_store_2 = RequestJsonStore() request_json_store_3 = RequestJsonStore() self.assertEqual(request_json_store_1, request_json_store_2) self.assertEqual(request_json_store_2, request_json_store_3) self.assertEqual(request_json_store_3, request_json_store_1) keys_json_store_1 = KeysJsonStore() keys_json_store_2 = KeysJsonStore() keys_json_store_3 = KeysJsonStore() self.assertEqual(keys_json_store_1, keys_json_store_2) self.assertEqual(keys_json_store_2, keys_json_store_3) self.assertEqual(keys_json_store_3, keys_json_store_1) #probamos ahora que dos clases sin singleton devuelven #instancias distintas. Por ejemplo con DNI dni_1 = Dni("12345678Z") dni_2 = Dni("12345678Z") self.assertNotEqual(dni_1, dni_2)
def test_get_access_key_bad_label1t(self): my_file = str(Path.home( )) + "/PyCharmProjects/GE3_2021/src/JsonFiles/key_bad_label1.json" my_key = AccessManager() with self.assertRaises(AccessManagementException) as cm: key = my_key.get_access_key(my_file) self.assertEqual("JSON Decode Error - Wrong label", cm.exception.message)
def test_get_access_key_good(self): my_file = str(Path.home() ) + "/PyCharmProjects/GE3_2021/src/JsonFiles/key_ok.json" my_key = AccessManager() key = my_key.get_access_key(my_file) self.assertEqual( "657244bdf89f067462e6a7f12b44749340f61030619f93bee391fbaf93361627", key)
def test_get_access_key_good3(self): my_file = str(Path.home( )) + "/PyCharmProjects/GE3_2021/src/JsonFiles/key_ok3_resident.json" my_key = AccessManager() key = my_key.get_access_key(my_file) self.assertEqual( "de000a04f3a9b1d15b07e38b166f00f3fb1bf46533f32ac37156faf43e47f722", key)
def test_get_access_key_wrong(self): my_file = str(Path.home( )) + "/PyCharmProjects/GE3_2021/src/JsonFiles/key_nok.json" my_key = AccessManager() with self.assertRaises(AccessManagementException) as cm: key = my_key.get_access_key(my_file) self.assertEqual("access code is not correct for this DNI", cm.exception.message)
def test_get_access_key_good2(self): my_file = str(Path.home( )) + "/PyCharmProjects/GE3_2021/src/JsonFiles/key_ok2.json" my_key = AccessManager() key = my_key.get_access_key(my_file) self.assertEqual( "49688b213220ee38ee7f2f0c9dcf394b47bb17f376ae9f53564f135c4a247691", key)
def test_open_door_bad_key_regex(self): """path: regex is not valid , key length is 63 chars""" my_key = AccessManager() with self.assertRaises(AccessManagementException) as c_m: my_key.open_door \ ("cc161c01a4bcca82e841b3446e2a3edb3539d72a3a7ec40a07d236998482906") self.assertEqual("key invalid", c_m.exception.message)
def test_open_door_bad_key_is_expired(self): """Expired key generated in the SetUpClass method""" my_key = AccessManager() with self.assertRaises(AccessManagementException) as c_m: my_key.open_door \ ("459063166d5a8e38ac493d4f523e31cca39bdc2c523d12dc08cae4a983224495") self.assertEqual("La clave recibida no existe", c_m.exception.message)
def test_open_door_bad_key_is_not_found(self): """path: regex ok, key is not found""" my_key = AccessManager() with self.assertRaises(AccessManagementException) as c_m: my_key.open_door \ ("fff00d78646ed41a91d60ec2fc1ed326238e510134ca52e5d9b1de5cbdf2b8ab") self.assertEqual("La clave recibida no existe", c_m.exception.message)
def test_parametizer_Json_decode_error(self): file1 = str( Path.home() ) + "/PyCharmProjects/GE3_2021/src/JsonFiles/key_without_final_bracket.json" file2 = str( Path.home() ) + "/PyCharmProjects/GE3_2021/src/JsonFiles/key_eliminated_comma.json" file3 = str( Path.home() ) + "/PyCharmProjects/GE3_2021/src/JsonFiles/key_bad_bracket_mail.json" param_list = [file1, file2, file3] for p1 in param_list: my_key = AccessManager() with self.assertRaises(AccessManagementException) as cm: key = my_key.get_access_key(p1) self.assertEqual("JSON Decode Error - Wrong JSON Format", cm.exception.message)
def test_request_access_code_good(self): """ doc """ my_code = AccessManager() valor = my_code.request_access_code("05270358T", "Pedro Martin", "Resident", "*****@*****.**", 0) self.assertEqual("fdf839d5e6ac1c6b7ce0625577a80568", valor) # Check if this DNI is store in storeRequest.json my_data = self.read_file() my_request = AccessRequest("05270358T", "Pedro Martin", "Resident", "*****@*****.**", 0) found = False for k in my_data: if (k["_AccessRequest__id_document"] == "05270358T"): found = True #this assert give me more information about the differences than assertEqual self.assertDictEqual(k, my_request.__dict__) # if found is False , this assert fails self.assertTrue(found)
def test_store_json_open_door_1(self): """key valid, check store in storeOpenKey.json""" my_key = AccessManager() expected_dict = { "key": "de000a04f3a9b1d15b07e38b166f00f3fb1bf46533f32ac37156faf43e47f722", "time": 1615627129.580297 } open_door_store = OpenKeyStore() open_door_store.empty_store() my_key.open_door( "de000a04f3a9b1d15b07e38b166f00f3fb1bf46533f32ac37156faf43e47f722") with open(JSON_FILES_PATH + "/storeOpenKey.json", "r", encoding="utf-8", newline="") as file: data = json.load(file) self.assertDictEqual(expected_dict, data[0])
def test_parametrized_cases_tests(self): """Parametrized cases read from testingCases_RF1.csv""" my_cases = JSON_FILES_PATH + "testingCases_RF2.csv" with open(my_cases, newline='', encoding='utf-8') as csvfile: param_test_cases = csv.DictReader(csvfile, delimiter=';') my_code = AccessManager() for row in param_test_cases: test_id = row['ID TEST'] result = row["EXPECTED RESULT"] valid = row["VALID INVALID"] file_name = JSON_FILES_PATH + row["FILE"] if valid == "VALID": print("Param:" + test_id + valid) valor = my_code.get_access_key(file_name) self.assertEqual(result, valor) else: print("Param:" + test_id + "-" + valid) with self.assertRaises(AccessManagementException) as c_m: my_code.get_access_key(file_name) self.assertEqual(c_m.exception.message, result)
def setUp(self) -> None: """Set up""" # pylint: disable=no-member requests_store = RequestJsonStore() keys_store = KeysJsonStore() revoked_store = RevokedKeysJsonStore() requests_store.empty_store() keys_store.empty_store() revoked_store.empty_store() self.my_manager = AccessManager() # introduce a key valid and not expired and guest self.my_manager = AccessManager() self.my_manager.request_access_code("05270358T", "Pedro Martin", "Resident", "*****@*****.**", 0) # introduce key valid , guest -> expiration_date = 0 self.my_manager.request_access_code("53935158C", "Marta Lopez", "Guest", "*****@*****.**", 5) # introduce a key valid and expiration date = 0 , resident self.my_manager.get_access_key(JSON_FILES_PATH + "key_ok.json") self.my_manager.get_access_key(JSON_FILES_PATH + "key_ok3_resident.json") # introduce a key expirated, I need to change expiration date before to store the key self.my_manager.request_access_code("68026939T", "Juan Perez", "Guest", "*****@*****.**", 2) # expected result 383a8eb306459919ef0dc819405f16a6 # We generate the AccessKey for this AccessRequest my_key_expirated = AccessKey.create_key_from_file( JSON_FILES_PATH + "key_ok_testing_expired.json") # We manipulate the expiration date to obtain an expired AccessKey my_key_expirated.issued_at = 12 my_key_expirated.expiration_date = 0 my_key_expirated.store_keys()
def test_parametrized_cases_tests(self): """Parametrized cases read from testingCases_RF1.csv""" my_cases = JSON_FILES_PATH + "testingCases_RF2.csv" with open(my_cases, newline='', encoding='utf-8') as csvfile: #pylint: disable=no-member param_test_cases = csv.DictReader(csvfile, delimiter=',') my_code = AccessManager() keys_store = KeysJsonStore() for row in param_test_cases: file_name = JSON_FILES_PATH + row["FILE"] print("Param:" + row['ID TEST'] + row["VALID INVALID"]) if row["VALID INVALID"] == "VALID": valor = my_code.get_access_key(file_name) self.assertEqual(row["EXPECTED RESULT"], valor) print("el valor: " + valor) generated_key = keys_store.find_item(valor) print(generated_key) self.assertIsNotNone(generated_key) else: with self.assertRaises(AccessManagementException) as c_m: my_code.get_access_key(file_name) self.assertEqual(c_m.exception.message, row["EXPECTED RESULT"])