Esempio n. 1
0
def test_reko(isfile_mock, exist_mock):
    exist_mock.return_value = True
    client = boto3.client('rekognition')
    stubber = Stubber(client)
    ep = {
        'Image': {
            'S3Object': {
                'Bucket': 'mybucket',
                'Name': 'mykey'
            }
        },
        'CollectionId': 'Test',
        'ExternalImageId': 'mykey'
    }
    stubber.add_response(method='index_faces',
                         service_response={},
                         expected_params=ep)
    stubber.activate()
    with patch.object(FaceManager, 'upload_to_s3', return_value='mykey'):
        with stubber:
            fm = FaceManager(Path="./test.txt", Bucket="mybucket")
            fm.upload_face(Path="./file.txt",
                           Collection="Test",
                           Person='x',
                           RekognitionStub=client)
Esempio n. 2
0
def upload_face(obj):
    try:
        error_if_missing(obj, 'person')
        error_if_missing(obj, 'path')
        error_if_missing(obj, 'collection')
        person = obj.person
        path = obj.path
        collection = obj.collection
        fm = FaceManager(Bucket='face-db-pollexy')
        fm.upload_face(Path=path, Person=person, Collection=collection)
    except Exception as exc:
        click.echo("Error: %s" % str(exc))
        exit(2)
Esempio n. 3
0
def upload_face_with_no_collection_throws_error():
    with pytest.raises(Exception) as exc:
        fm = FaceManager(Bucket="test")
        fm.upload_face(Path="./file.txt")
    assert 'Missing parameter: Collection' in str(exc.value)
Esempio n. 4
0
def upload_face_with_missing_path_throws_error(isfile_mock):
    isfile_mock.return_value = False
    with pytest.raises(Exception) as exc:
        fm = FaceManager(Bucket="test")
        fm.upload_face(Path="./file.txt")
    assert 'File not found: ./file.txt' in str(exc.value)
Esempio n. 5
0
def upload_face_with_no_path_throws_error():
    with pytest.raises(Exception) as exc:
        fm = FaceManager(Bucket="test")
        fm.upload_face()
    assert 'Missing parameter: Path' in str(exc.value)