-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
110 lines (97 loc) · 4.04 KB
/
client_test.go
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package autoderm_go_client
import (
"net/http"
"os"
"testing"
"github.com/google/uuid"
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/require"
)
const (
fixtureSuccess = `{"success":true,"message":"completed","id":"00000000-0000-0000-0000-000007b030ce","predictions":[{"confidence":0.20118004282871116,"icd":"D18.01","name":"Angioma (Cherry angioma)","classificationId":"3e51ccc4-d4aa-11e7-a562-0242ac120003","readMoreUrl":"https://www.firstderm.com/angioma/"},{"confidence":0.15057508063238972,"icd":"D22.9","name":"Atypical Melanocytic Nevus","classificationId":"b698ea32-8f39-4bb5-82e5-082a58f013d7","readMoreUrl":"https://www.firstderm.com/mole-congenital-nevus/"},{"confidence":0.07693463345465025,"icd":"D22.9","name":"Nevus (Benign Mole)","classificationId":"3e4fd5a6-d4aa-11e7-a562-0242ac120003","readMoreUrl":"https://www.firstderm.com/mole-congenital-nevus/"},{"confidence":0.05560834131992198,"icd":"D23.9","name":"Dermatofibroma","classificationId":"3e4fdae1-d4aa-11e7-a562-0242ac120003","readMoreUrl":"https://www.firstderm.com/dermatofibroma/"},{"confidence":0.05559970467420187,"icd":"L81.0","name":"Postinflammatory Hyperpigmentation","classificationId":"3e51595d-d4aa-11e7-a562-0242ac120003","readMoreUrl":"https://www.firstderm.com/hyperpigmentation/"}]}`
fixtureFailure = `{"success":false,"message":"picture is not of skin","id":"","predictions":[]}`
)
func TestClientSuccess(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder(
http.MethodPost,
"https://autoderm.ai/v1/query?model=autoderm_v2_2&language=en&save_image=false",
httpmock.NewStringResponder(
200,
fixtureSuccess,
),
)
client := NewClient("secret_dev_team")
file, err := os.Open("skin.jpeg")
require.NoError(t, err)
defer file.Close()
response, err := client.Query("skin.jpeg", file, false)
require.NoError(t, err)
require.Equal(t, &QueryResponse{
Success: true,
Message: "completed",
ID: "00000000-0000-0000-0000-000007b030ce",
Predictions: []Prediction{
{
Confidence: 0.20118004282871116,
Icd: "D18.01",
Name: "Angioma (Cherry angioma)",
ClassificationID: uuid.MustParse("3e51ccc4-d4aa-11e7-a562-0242ac120003"),
ReadMoreURL: "https://www.firstderm.com/angioma/",
},
{
Confidence: 0.15057508063238972,
Icd: "D22.9",
Name: "Atypical Melanocytic Nevus",
ClassificationID: uuid.MustParse("b698ea32-8f39-4bb5-82e5-082a58f013d7"),
ReadMoreURL: "https://www.firstderm.com/mole-congenital-nevus/",
},
{
Confidence: 0.07693463345465025,
Icd: "D22.9",
Name: "Nevus (Benign Mole)",
ClassificationID: uuid.MustParse("3e4fd5a6-d4aa-11e7-a562-0242ac120003"),
ReadMoreURL: "https://www.firstderm.com/mole-congenital-nevus/",
},
{
Confidence: 0.05560834131992198,
Icd: "D23.9",
Name: "Dermatofibroma",
ClassificationID: uuid.MustParse("3e4fdae1-d4aa-11e7-a562-0242ac120003"),
ReadMoreURL: "https://www.firstderm.com/dermatofibroma/",
},
{
Confidence: 0.05559970467420187,
Icd: "L81.0",
Name: "Postinflammatory Hyperpigmentation",
ClassificationID: uuid.MustParse("3e51595d-d4aa-11e7-a562-0242ac120003"),
ReadMoreURL: "https://www.firstderm.com/hyperpigmentation/",
},
},
}, response)
}
func TestClientFailure(t *testing.T) {
httpmock.Activate()
defer httpmock.DeactivateAndReset()
httpmock.RegisterResponder(
http.MethodPost,
"https://autoderm.ai/v1/query?model=autoderm_v2_2&language=en&save_image=false",
httpmock.NewStringResponder(
200,
fixtureFailure,
),
)
client := NewClient("secret_dev_team")
file, err := os.Open("u8.png")
require.NoError(t, err)
defer file.Close()
response, err := client.Query("u8.png", file, false)
require.NoError(t, err)
require.Equal(t, &QueryResponse{
Success: false,
Message: "picture is not of skin",
ID: "",
Predictions: []Prediction{},
}, response)
}