def test_validate_text_label(self): user_id = utils.create_user_id() user = UserCreate( user_id=user_id, name="Elizabeth", surname="Henderson", date_of_birth=datetime.date(1977, 4, 14), country="London", ) crud.user.create(db_session=db_session, user_in=user) image_path = ( os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/resources/sample_uk_identity_card.png") with open(image_path, "rb") as imageFile: image_str = base64.b64encode(imageFile.read()).decode("utf-8") image_in = ImageCreate(user_id=user_id, image_str=image_str, image_type=ImageType.identity) crud.image.create(db_session=db_session, image_in=image_in) user = crud.user.get(db_session=db_session, user_id=user_id) (file_path, face_image_path) = verification_utils.create_image_file( user_id=user_id, image_type=ImageType.identity) texts = verification_utils.get_texts(user_id=user_id) doc_text_label = verification_utils.get_doc(texts, language="en_core_web_sm") user_text_label = verification_utils.create_user_text_label(user) text_validation_point = verification_utils.validate_text_label( doc_text_label, user_text_label) self.assertEqual(text_validation_point, 0.5)
def test_point_on_recognition_succeed(self): user_id = utils.create_user_id() user = UserCreate( user_id=user_id, name="Elizabeth", surname="Henderson", date_of_birth=datetime.date(1977, 4, 14), country="London", ) crud.user.create(db_session=db_session, user_in=user) image_path = ( os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/resources/sample_uk_identity_card.png") with open(image_path, "rb") as imageFile: image_str = base64.b64encode(imageFile.read()).decode("utf-8") image_in = ImageCreate(user_id=user_id, image_str=image_str, image_type=ImageType.identity) crud.image.create(db_session=db_session, image_in=image_in) user = crud.user.get(db_session=db_session, user_id=user_id) (file_path, face_image_path) = verification_utils.create_image_file( user_id=user_id, image_type=ImageType.identity) names = verification_utils.recognize_face(user_id=user_id) face_validation_point = verification_utils.point_on_recognition( names, user_id) self.assertEqual(face_validation_point, 0.25)
def test_create_image(self): user_id = utils.create_user_id() user_in = UserCreate( user_id=user_id, name="name", surname="surname", date_of_birth=date(1990, 10, 10), country="Turkey", ) crud.user.create(db_session, user_in=user_in) image_path = (os.path.dirname(os.path.dirname(__file__)) + "/resources/sample_uk_identity_card.png") with open(image_path, "rb") as imageFile: image_str = base64.b64encode(imageFile.read()).decode("utf-8") image_in = ImageCreate(user_id=user_id, image_str=image_str, image_type=ImageType.identity.value) crud.image.create(db_session, image_in=image_in) image_out = crud.image.get(db_session, user_id=user_id, image_type=image_in.image_type) self.assertIsNotNone(image_out) self.assertEqual(image_out.user_id, user_id) self.assertEqual(image_out.image_str, image_str) self.assertEqual(image_out.image_type, ImageType.identity.value)
def mutate(self, info, country, date_of_birth, name, surname): user_id = utils.create_user_id() user_in = UserCreate( user_id=user_id, name=name, surname=surname, date_of_birth=date_of_birth, country=country, ) user = crud.user.create(db_session, user_in=user_in) ok = True return CreateUser(user=user, ok=ok)
def test_create_user(self): user_id = utils.create_user_id() user_in = UserCreate( user_id=user_id, name="name", surname="surname", date_of_birth=date(1990, 10, 10), country="Turkey", ) crud.user.create(db_session, user_in=user_in) user_out = crud.user.get(db_session, user_id=user_id) self.assertIsNotNone(user_out) self.assertEqual(user_out.user_id, user_in.user_id) self.assertEqual(user_out.name, user_in.name) self.assertEqual(user_out.surname, user_in.surname) self.assertEqual(user_out.country, user_in.country)
def test_validate_text_label_simple(self): user_id = utils.create_user_id() user = UserCreate( user_id=user_id, name="Elizabeth", surname="Henderson", date_of_birth=datetime.date(1977, 4, 14), country="London", ) user_text_label = verification_utils.create_user_text_label(user) doc_text_label = [ ("1234567", "DATE"), ("Card Identity National Henderso", "ORG"), ("Elizabeth", "PERSON"), ("British", "NORP"), ("London", "GPE"), ("11-08", "DATE"), ] text_validation_point = verification_utils.validate_text_label( doc_text_label, user_text_label) self.assertEqual(text_validation_point, 0.50)
def db_create_rows(self): user_id = utils.create_user_id() user = UserCreate( user_id=user_id, name="name", surname="surname", date_of_birth=datetime.date(1990, 10, 10), country="country", ) crud.user.create(db_session=db_session, user_in=user) image_path = ( os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + "/resources/sample_uk_identity_card.png") with open(image_path, "rb") as imageFile: image_str = base64.b64encode(imageFile.read()).decode("utf-8") image_in = ImageCreate(user_id=user_id, image_str=image_str, image_type=ImageType.identity) crud.image.create(db_session=db_session, image_in=image_in) return user_id