Ejemplo n.º 1
0
    def test_no_record_in_control_table(self, create_coll, id_gen):

        dynamodb = boto3.resource('dynamodb')
        dynamodb_client = boto3.client('dynamodb')

        #create_RVA_COLLECTION_CONTROL_TABLE(dynamodb)

        print("\n\n##test_no_record_in_control_table\n" )

        r  = dynamodb_client.delete_item(
            TableName=RVA_COLLECTION_CONTROL_TABLE,
            Key={"Identifier": {"S": "COLLECTIONS_NEW"}},
            ReturnConsumedCapacity='TOTAL'
        )

        rcc = RekognitionCollectionController(RVA_COLLECTION_CONTROL_TABLE, 'COLLECTIONS_NEW')
        collection_id = rcc.fetch_collection()

        print("COLL ID: {}".format(collection_id))

        r  = dynamodb_client.get_item(
            TableName=RVA_COLLECTION_CONTROL_TABLE,
            Key={"Identifier": {"S": "COLLECTIONS_NEW"}},
            ConsistentRead=True,
            ReturnConsumedCapacity='TOTAL'
        )

        item = r['Item']

        assert "DVA-123456" == item['Current']['S'] 
        assert "DVA-123456" == collection_id
        assert 0 == int(item['Count']['N'])
Ejemplo n.º 2
0
    def test_increment_collection_count(self, call, id_gen):
        dynamodb = boto3.resource('dynamodb')
        dynamodb_client = boto3.client('dynamodb')

        #create_RVA_COLLECTION_CONTROL_TABLE(dynamodb)
        
        dynamodb_client.update_item(
            TableName=RVA_COLLECTION_CONTROL_TABLE,
            Key={"Identifier": {"S": "COLLECTIONS_INC"}},
            UpdateExpression="SET #curr = :newvalue, #cnt = :count, #cols = :coll_id", #list_append(if_not_exists(#cols, :empty_list), :coll_id)",        
            ExpressionAttributeNames={
                '#curr': 'Current',
                '#cnt': 'Count',
                '#cols': 'CollectionIds'
            },
            ExpressionAttributeValues={
                ':newvalue': {'S': "DVA-000000"}, 
                ':count': {'N': "1234"},
                ':coll_id': {'L': [ { "S" : "DVA-000000" }, { "S" : "DVA-000001" }, { "S" : "DVA-000002" } ] }
            }
        )
        
        rcc = RekognitionCollectionController(RVA_COLLECTION_CONTROL_TABLE, 'COLLECTIONS_INC')
        r = rcc.increment_collection_count("DVA-000000", 1000)

        print("\n\UPDATE COUNT\n\n\n")
        print(r)

        self.assertEqual(2234, r, msg="Data written in DDB is wrong. Exp: {} Found: {}".format("", ""))
Ejemplo n.º 3
0
    def test_control_table_less_than_max_size(self, call):

        dynamodb = boto3.resource('dynamodb')
        dynamodb_client = boto3.client('dynamodb')

        #create_RVA_COLLECTION_CONTROL_TABLE(dynamodb)
        
        dynamodb_client.update_item(
            TableName=RVA_COLLECTION_CONTROL_TABLE,
            Key={"Identifier": {"S": "COLLECTIONS_LESS"}},
            UpdateExpression="SET #curr = :newvalue, #cnt = :count, #cols = :coll_id", #list_append(if_not_exists(#cols, :empty_list), :coll_id)",        
            ExpressionAttributeNames={
                '#curr': 'Current',
                '#cnt': 'Count',
                '#cols': 'CollectionIds'
            },
            ExpressionAttributeValues={
                ':newvalue': {'S': "DVA-123456"}, 
                ':count': {'N': "100"},
                ':coll_id': {'L': [ { "S" : "DVA-123456" } ] }
            }
        )

        rcc = RekognitionCollectionController(RVA_COLLECTION_CONTROL_TABLE, 'COLLECTIONS_LESS')
        collection_id = rcc.fetch_collection()
       
        r  = dynamodb_client.get_item(
            TableName=RVA_COLLECTION_CONTROL_TABLE,
            Key={"Identifier": {"S": "COLLECTIONS_LESS"}},
            ConsistentRead=True,
            ReturnConsumedCapacity='TOTAL'
        )

        item = r['Item']

        print("\n\n##test_control_table_less_than_max_size\n")
        print("\n\n>>>>>>\n\n\n")
        print(json.dumps(item))

        self.assertEqual("DVA-123456", item['Current']['S'], msg="Data written in DDB is wrong. Exp: {} Found: {}".format("DVA-123456", item['Current']['S']))
        self.assertEqual("DVA-123456", collection_id, msg="Data written in DDB is wrong. Exp: {} Found: {}".format("DVA-123456", collection_id))
        self.assertEqual(100, int(item['Count']['N']), msg="Data written in DDB is wrong. Exp: {} Found: {}".format(100, int(item['Count']['N'])))
Ejemplo n.º 4
0
    def test_id_generator(self):
        rcc = RekognitionCollectionController(RVA_COLLECTION_CONTROL_TABLE, '')
        rcc.set_collection_prefix("TEST")
        id = rcc.id_generator()

        assert id.startswith("TEST")
def init_RekognitionCollectionController():
    rcc = RekognitionCollectionController(RVA_COLLECTION_CONTROL,
                                          'COLLECTIONS')
    rcc.set_collection_size(RVA_COLLECTION_MAX_SIZE)

    return rcc
Ejemplo n.º 6
0
def update_collection_control(collection_id, faces_indexed):
    rcc = RekognitionCollectionController(RVA_COLLECTION_CONTROL,
                                          'COLLECTIONS')
    rcc.increment_collection_count(collection_id, faces_indexed)