def test_batch_upload( large_upload_collection: UploadCollection, fake_session: HexpySession, caplog: CaptureFixture, ) -> None: """Test more than 1000 items are uploaded in batches""" responses.add(responses.POST, HexpySession.ROOT + "content/upload", json={}, status=200) client = ContentUploadAPI(fake_session) with caplog.at_level(logging.INFO): response = client.upload(document_type=123456789, items=large_upload_collection, request_usage=True) assert (caplog.records[0].msg == "More than 1000 items found. Uploading in batches of 1000.") assert response == { "Batch 0": {}, "Batch 1": {}, "Batch 2": {}, "Batch 3": {} }
def test_rate_limiting_window( caplog: CaptureFixture, base_func: Callable[[str], JSONDict] ) -> None: """Test sliding window when rate limit not exceeded.""" modified_func = rate_limited(base_func, max_calls=10, period=1) with caplog.at_level(logging.INFO): for _ in range(12): modified_func() time.sleep(0.2) assert len(caplog.records) == 0
def test_rate_limiting( caplog: CaptureFixture, base_func: Callable[[str], JSONDict] ) -> None: """Test function rate limiting""" modified_func = rate_limited(base_func, max_calls=10, period=1) with caplog.at_level(logging.INFO): for _ in range(12): modified_func() assert caplog.records[0].msg == "Rate Limit Reached. (Sleeping for 6 seconds)"
def test_batch_train( large_train_collection: TrainCollection, fake_session: HexpySession, caplog: CaptureFixture, ) -> None: """Test more than 1000 items are trained in batches""" responses.add(responses.POST, HexpySession.ROOT + "monitor/train", json={}, status=200) client = MonitorAPI(fake_session) with caplog.at_level(logging.INFO): response = client.train_monitor(monitor_id=123456789, items=large_train_collection) assert ( caplog.records[0].msg == "More than 1000 training items found. Uploading in batches of 1000." ) assert response == {"Batch 0": {}, "Batch 1": {}, "Batch 2": {}}