File size: 1,120 Bytes
058f1d9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
from .fixture import app_client
import json
import time

def test_training_endpoint(app_client):
	"""

	Checks whether the training endpoint correctly receives, starts

	and clears a training task instance.



	Given:

	- Launched training instance



	When:

	- State polled multiple times



	Then:

	- Expect state returned on first poll and instance gone on second poll

	"""
	response = app_client.post("/train/start")
	assert response.status_code == 200
	output : dict = json.loads(response.content)
	assert len(output.keys()) == 1
	assert output["message"] == "Model training was scheduled and will begin shortly."

	time.sleep(5)

	response = app_client.post("/train/get_state")
	assert response.status_code == 200
	output : dict = json.loads(response.content)
	assert len(output.keys()) == 2
	assert output["done"]
	assert not output["error"]

	time.sleep(1)

	response = app_client.post("/train/get_state")
	assert response.status_code == 200
	output : dict = json.loads(response.content)
	assert len(output.keys()) == 1
	assert output["message"] == "No training instance running!"