-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpetstore_test_petapi.jl
67 lines (53 loc) · 2.06 KB
/
petstore_test_petapi.jl
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
module TestPetApi
using ..PetStoreClient
using Test
using OpenAPI
using OpenAPI.Clients
import OpenAPI.Clients: Client
function test(uri)
@info("PetApi")
client = Client(uri)
api = PetApi(client)
tag1 = Tag(;id=10, name="juliacat")
tag2 = Tag(;id=11, name="white")
cat = Category(;id=10, name="cat")
@test_throws OpenAPI.ValidationException Pet(;id=10, category=cat, name="felix", photoUrls=nothing, tags=[tag1, tag2], status="invalid-status")
pet = Pet(;id=10, category=cat, name="felix", photoUrls=nothing, tags=[tag1,tag2], status="pending")
@info("PetApi - add_pet")
api_return, http_resp = add_pet(api, pet)
@test api_return === nothing
@test http_resp.status == 200
@info("PetApi - update_pet")
pet.status = "available"
api_return, http_resp = update_pet(api, pet)
@test api_return === nothing
@test http_resp.status == 200
# @info("PetApi - updatePetWithForm")
# @test updatePetWithForm(api, 10; in_name="meow") === nothing
@info("PetApi - get_pet_by_id")
pet10, http_resp = get_pet_by_id(api, Int64(10))
@test http_resp.status == 200
@test pet10.id == 10
@info("PetApi - find_pets_by_status")
unsold = ["available", "pending"]
pets, http_resp = find_pets_by_status(api, unsold)
@test http_resp.status == 200
@test isa(pets, Vector{Pet})
@info("PetApi - find_pets_by_status", npets=length(pets))
for p in pets
@test p.status in unsold
end
@info("PetApi - deletePet")
api_return, http_resp = delete_pet(api, Int64(10))
@test http_resp.status == 200
@test api_return === nothing
# does not work yet. issue: https://github.com/JuliaWeb/Requests.jl/issues/139
#@info("PetApi - upload_file")
#img = joinpath(dirname(@__FILE__), "cat.png")
#resp, http_resp = upload_file(api, 10; additionalMetadata="juliacat pic", file=img)
#@test isa(resp, ApiResponse)
#@test resp.code == 200
#@info("PetApi - upload_file", typ=get_field(resp, "type"), message=get_field(resp, "message"))
nothing
end
end # module TestPetApi