-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathpetstore_test_storeapi.jl
73 lines (62 loc) · 2.34 KB
/
petstore_test_storeapi.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
68
69
70
71
72
73
module TestStoreApi
using ..PetStoreClient
using Test
using Dates
using TimeZones
using OpenAPI
using OpenAPI.Clients
import OpenAPI.Clients: Client
function test(uri)
@info("StoreApi")
client = Client(uri)
api = StoreApi(client)
@info("StoreApi - get_inventory")
inventory, http_resp = get_inventory(api)
@test http_resp.status == 200
@test isa(inventory, Dict{String,Int64})
@test !isempty(inventory)
@info("StoreApi - place_order")
@test_throws OpenAPI.ValidationException Order(; id=5, petId=10, quantity=2, shipDate=DateTime(2017, 03, 12), status="invalid_status", complete=false)
order = Order(; id=5, petId=10, quantity=2, shipDate=ZonedDateTime(DateTime(2017, 03, 12), localzone()), status="placed", complete=false)
neworder, http_resp = place_order(api, order)
@test http_resp.status == 200
@test neworder.id == 5
@info("StoreApi - get_order_by_id")
@test_throws OpenAPI.ValidationException get_order_by_id(api, Int64(0))
order, http_resp = get_order_by_id(api, Int64(5))
@test http_resp.status == 200
@test isa(order, Order)
@test order.id == 5
@test isa(order.shipDate, ZonedDateTime)
@info("StoreApi - get_order_by_id (async)")
response_channel = Channel{Order}(1)
@test_throws OpenAPI.ValidationException get_order_by_id(api, response_channel, Int64(0))
@sync begin
@async begin
resp, http_resp = get_order_by_id(api, response_channel, Int64(5))
@test (200 <= http_resp.status <= 206)
@test resp === response_channel
end
@async begin
order = take!(response_channel)
@test isa(order, Order)
@test order.id == 5
end
end
# a closed channel is equivalent of cancellation of the call,
# no error should be thrown, but response can be nothing if call was interrupted immediately
@test !isopen(response_channel)
# open a new channel to use
response_channel = Channel{Order}(1)
try
resp, http_resp = get_order_by_id(api, response_channel, Int64(5))
@test (200 <= http_resp.status <= 206)
catch ex
@test isa(ex, OpenAPI.InvocationException)
end
@info("StoreApi - delete_order")
api_return, http_resp = delete_order(api, Int64(5))
@test api_return === nothing
nothing
end
end # module TestStoreApi