File size: 2,036 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
from .fixture import app_client
import json

def test_inference_endpoint(app_client):
	"""

	Tests the output of the inference endpoint of the application.

	

	Given:

		- Payload with valid list of messages

	When:

		- POST Request sent to inference endpoint

	Then:

		- Expect message to be classified as positive

	"""
	response = app_client.post(
		"/inference",
		headers={
			"Content-Type": "application/json",
   		},
		json={
			"messages": [
				"BTC is going to skyrocket!",
			],
		}
	)

	assert response.status_code == 200
	output = json.loads(response.content)
	assert isinstance(output, list)
	assert len(output) == 1
	assert output[0]["positive"] > output[0]["negative"] and output[0]["positive"] > output[0]["neutral"]


def test_inference_endpoint_with_wrong_payload(app_client):
	"""

	Tests the output of the inference endpoint of the application with an

	invalid payload.

	This should yield a 422 status error as FastAPI will not be able

	to translate the payload into the InferenceRequest model.

	

	Given:

		- Payload with wrong message key

	When:

		- POST Request sent to inference endpoint

	Then:

		- Expect 422 status code

	"""
	response = app_client.post(
		"/inference",
		headers={
			"Content-Type": "application/json",
   		},
		json={
			"msgs": [
				"BTC is going to skyrocket!",
			],
		}
	)

	assert response.status_code == 422 # Unprocessable entity

def test_inference_endpoint_with_no_prompt(app_client):
	"""

	Tests the output of the inference endpoint of the application

	when a valid payload is provided but with no actual messages.

	

	Given:

		- Payload without any messages

	When:

		- POST Request sent to inference endpoint

	Then:

		- Expect no error and correct format

	"""
	response = app_client.post(
		"/inference",
		headers={
			"Content-Type": "application/json",
   		},
		json={
			"messages": [],
		}
	)

	assert response.status_code == 200
	output = json.loads(response.content)
	assert output == None