Example #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)
Example #2
0
def match_face(obj):
    try:
        error_if_missing(obj, 'path')
        error_if_missing(obj, 'collection')
        path = obj.path
        collection = obj.collection
        fm = FaceManager(Bucket='face-db-pollexy')
        response = fm.match_face(Path=path, Collection=collection)
        print response
    except Exception as exc:
        click.echo("Error: %s" % str(exc))
        exit(2)
Example #3
0
def test_throw_error_if_bucket_does_not_exist(file_data_mock, exist_mock):
    exist_mock.return_value = True
    test_bucket = "test_data"
    file_data_mock.return_value = test_bucket
    s3 = boto3.client('s3')
    resource = boto3.resource('s3')
    s3.create_bucket(Bucket=test_bucket)
    fm = FaceManager(Bucket=test_bucket)
    fm.upload_to_s3('./test.txt', 'calvin')
    bucket = resource.Bucket(test_bucket)
    for obj_sum in bucket.objects.all():
        obj = resource.Object(obj_sum.bucket_name, obj_sum.key)
Example #4
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)
Example #5
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)
Example #6
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)
Example #7
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)
Example #8
0
def test_creating_fm_with_no_bucket_throws_error():
    with pytest.raises(Exception) as exc:
        FaceManager()
    assert 'Missing parameter: Bucket' in str(exc.value)
Example #9
0
def test_creating_fm_sets_bucket(exist_mock):
    exist_mock.return_value = True
    fm = FaceManager(Bucket="test")
    assert fm.bucket == "test"