Example #1
0
    def test_put_blob_record_success(self):
        project_name = 'put'
        topic_name = 'success'
        records = []
        data = None
        with open(os.path.join(_TESTS_PATH, '../resources/datahub.png'),
                  'rb') as f:
            data = f.read()
        record0 = BlobRecord(blob_data=data)
        record0.shard_id = '0'
        records.append(record0)

        record1 = BlobRecord(blob_data=data)
        record1.hash_key = '4FFFFFFFFFFFFFFD7FFFFFFFFFFFFFFD'
        records.append(record1)

        record2 = BlobRecord(blob_data=data)
        record2.partition_key = 'TestPartitionKey'
        records.append(record2)

        def check(request):
            assert request.method == 'POST'
            assert request.url == 'http://endpoint/projects/put/topics/success/shards'
            content = json.loads(request.body)
            assert content['Action'] == 'pub'
            assert len(content['Records']) == 3
            assert base64.b64decode(content['Records'][0]['Data']) == data
            assert base64.b64decode(content['Records'][1]['Data']) == data
            assert base64.b64decode(content['Records'][2]['Data']) == data

        with HTTMock(gen_mock_api(check)):
            put_result = dh.put_records(project_name, topic_name, records)

        assert put_result.failed_record_count == 0
        assert put_result.failed_records == []
Example #2
0
    def test_put_blob_record_pb_success(self):
        project_name = 'put'
        topic_name = 'success'
        records = []
        data = None
        with open(os.path.join(_TESTS_PATH, '../resources/datahub.png'),
                  'rb') as f:
            data = f.read()
        record0 = BlobRecord(blob_data=data)
        record0.shard_id = '0'
        records.append(record0)

        record1 = BlobRecord(blob_data=data)
        record1.hash_key = '4FFFFFFFFFFFFFFD7FFFFFFFFFFFFFFD'
        records.append(record1)

        record2 = BlobRecord(blob_data=data)
        record2.partition_key = 'TestPartitionKey'
        records.append(record2)

        def check(request):
            assert request.method == 'POST'
            assert request.url == 'http://endpoint/projects/put/topics/success/shards'
            crc, compute_crc, pb_str = unwrap_pb_frame(request.body)
            pb_put_record_request = PutRecordsRequest()
            pb_put_record_request.ParseFromString(pb_str)
            for pb_record in pb_put_record_request.records:
                assert pb_record.data.data[0].value == data

        with HTTMock(gen_pb_mock_api(check)):
            put_result = dh2.put_records(project_name, topic_name, records)

        assert put_result.failed_record_count == 0
        assert put_result.failed_records == []
Example #3
0
    def test_put_blob_record_success(self):
        project_name = 'put'
        topic_name = 'success'
        records = []
        data = None
        with open(os.path.join(_TESTS_PATH, '../resources/datahub.png'), 'rb') as f:
            data = f.read()
        record0 = BlobRecord(blob_data=data)
        record0.shard_id = '0'
        records.append(record0)

        record1 = BlobRecord(blob_data=data)
        record1.hash_key = '4FFFFFFFFFFFFFFD7FFFFFFFFFFFFFFD'
        records.append(record1)

        record2 = BlobRecord(blob_data=data)
        record2.partition_key = 'TestPartitionKey'
        records.append(record2)

        with HTTMock(datahub_api_mock):
            put_result = dh.put_records(project_name, topic_name, records)

        assert put_result.failed_record_count == 0
        assert put_result.failed_records == []