2025-01-20 14:02:18 +08:00
|
|
|
import json
|
|
|
|
|
|
2025-01-17 14:23:52 +08:00
|
|
|
import allure
|
|
|
|
|
|
|
|
|
|
from src.steps.common import StepsCommon
|
|
|
|
|
|
|
|
|
|
|
2025-01-17 19:27:43 +08:00
|
|
|
def prepare_dispersal_request(data, app_id, index):
|
2025-01-17 15:04:02 +08:00
|
|
|
data_bytes = data.encode("utf-8")
|
2025-01-17 19:49:53 +08:00
|
|
|
dispersal_data = {"data": list(data_bytes), "metadata": {"app_id": app_id, "index": index}}
|
2025-01-17 14:23:52 +08:00
|
|
|
return dispersal_data
|
|
|
|
|
|
|
|
|
|
|
2025-01-17 19:27:43 +08:00
|
|
|
def prepare_get_range_request(app_id, start_index, end_index):
|
|
|
|
|
query_data = {"app_id": app_id, "range": {"start": start_index, "end": end_index}}
|
|
|
|
|
return query_data
|
|
|
|
|
|
|
|
|
|
|
2025-01-17 14:23:52 +08:00
|
|
|
class StepsDataAvailability(StepsCommon):
|
|
|
|
|
|
|
|
|
|
@allure.step
|
2025-01-17 19:27:43 +08:00
|
|
|
def disperse_data(self, data, app_id, index):
|
2025-01-17 19:49:53 +08:00
|
|
|
request = prepare_dispersal_request(data, app_id, index)
|
2025-01-17 19:27:43 +08:00
|
|
|
try:
|
|
|
|
|
self.node3.send_dispersal_request(request)
|
|
|
|
|
except Exception as ex:
|
|
|
|
|
assert "Bad Request" in str(ex) or "Internal Server Error" in str(ex)
|
|
|
|
|
|
|
|
|
|
@allure.step
|
|
|
|
|
def get_data_range(self, app_id, start, end):
|
2025-01-20 14:02:18 +08:00
|
|
|
response_bytes = []
|
2025-01-17 19:27:43 +08:00
|
|
|
query = prepare_get_range_request(app_id, start, end)
|
2025-01-17 14:23:52 +08:00
|
|
|
try:
|
2025-01-20 14:02:18 +08:00
|
|
|
response_bytes = self.node2.send_get_data_range_request(query)
|
2025-01-17 14:23:52 +08:00
|
|
|
except Exception as ex:
|
|
|
|
|
assert "Bad Request" in str(ex) or "Internal Server Error" in str(ex)
|
2025-01-20 13:48:12 +08:00
|
|
|
|
2025-01-20 14:14:59 +08:00
|
|
|
# Extract data as a string for each index in the received order
|
|
|
|
|
parsed_data = []
|
|
|
|
|
for item in response_bytes.content:
|
2025-01-20 14:23:59 +08:00
|
|
|
parsed_data.append(item)
|
2025-01-20 14:14:59 +08:00
|
|
|
return parsed_data
|