|
| 1 | +# module PlotlyV2Tests |
| 2 | + |
| 3 | +using Base.Test, Requests |
| 4 | + |
| 5 | +M = PlotlyV2 # simplify name |
| 6 | + |
| 7 | +@testset "utils" begin |
| 8 | + @test M.basic_auth("foo", "pass") == "Basic Zm9vOnBhc3M=" |
| 9 | +end |
| 10 | + |
| 11 | +@testset "api" begin |
| 12 | + @testset "search" begin |
| 13 | + @test 200 == statuscode(M.search_list_raw("public:false flow")) |
| 14 | + end |
| 15 | + |
| 16 | + @testset "files" begin |
| 17 | + # TODO: untested: file_content, file_drop_reference |
| 18 | + # NOTE: Not allowed to test these ones: file_copy, file_permanent_delete |
| 19 | + |
| 20 | + # TODO: come back to this and change to a plot once I have a plot here!! |
| 21 | + fid = "sglyon:257" # plot `_jl_testing/myplot` |
| 22 | + |
| 23 | + get_fid_funcs = [ |
| 24 | + M.file_retrieve_raw, M.file_path_raw, M.file_image_raw, |
| 25 | + M.file_sources_raw |
| 26 | + ] |
| 27 | + for func in get_fid_funcs |
| 28 | + @test 200 == statuscode(func(fid)) |
| 29 | + end |
| 30 | + |
| 31 | + res_star_raw = M.file_star_raw(fid) |
| 32 | + @test 200 == statuscode(res_star_raw) |
| 33 | + res = Requests.json(res_star_raw) |
| 34 | + @test length(res["stars"]["results"]) > 0 |
| 35 | + @test 204 == statuscode(M.file_remove_star(fid)) |
| 36 | + |
| 37 | + @test 200 == statuscode(M.file_lookup_raw("_jl_testing/mygrid")) |
| 38 | + res = M.file_lookup("_jl_testing/mygrid") |
| 39 | + @test res["filename"] == "mygrid" |
| 40 | + |
| 41 | + @test 200 == statuscode(M.file_trash_raw(fid)) |
| 42 | + @test 200 == statuscode(M.file_restore_raw(fid)) |
| 43 | + @test 200 == statuscode(M.file_partial_update_raw(fid, world_readable=true)) |
| 44 | + @test 200 == statuscode(M.file_update_raw(fid, world_readable=false)) |
| 45 | + end |
| 46 | + |
| 47 | + @testset "grids" begin |
| 48 | + # TODO: need to test grid_put_col, grid_post_col, grid_drop_reference, |
| 49 | + # grid_permanent_delete, grid_upload |
| 50 | + |
| 51 | + fid = "sglyon:251" |
| 52 | + uid1 = "d6434f" |
| 53 | + uid2 = "8c7b60" |
| 54 | + |
| 55 | + res_retrieve = PlotlyV2.grid_retrieve_raw(fid) |
| 56 | + res_retrieve.headers["Content-Type"] |
| 57 | + @test 200 == statuscode(res_retrieve) |
| 58 | + json_retrieve = Requests.json(res_retrieve) |
| 59 | + |
| 60 | + @test 200 == statuscode(M.grid_content_raw(fid)) |
| 61 | + |
| 62 | + data = Dict( |
| 63 | + :cols => Dict( |
| 64 | + "first column" => Dict("data" => ["a", "b", "c"], "order" => 0), |
| 65 | + "second column" => Dict("data" => 1:3, "order" => 1), |
| 66 | + ) |
| 67 | + ) |
| 68 | + del_fn = join(rand('a':'z', 10), "") |
| 69 | + res = PlotlyV2.grid_create_raw(data, parent_path="_jl_testing", filename=del_fn) |
| 70 | + json_delete = Requests.json(res) |
| 71 | + fid_delete = json_delete["file"]["fid"] |
| 72 | + uid1_delete = json_delete["file"]["cols"][1]["uid"] |
| 73 | + uid2_delete = json_delete["file"]["cols"][2]["uid"] |
| 74 | + @test statuscode(res) == 201 |
| 75 | + |
| 76 | + @test 201 == statuscode(M.grid_row(fid_delete, rand(2, 2))) |
| 77 | + |
| 78 | + # new_col1 = [Dict("data" => ["d", "e", "f"])] |
| 79 | + # res_put_col = M.grid_put_col_raw(fid_delete, new_col1, uid1_delete) |
| 80 | + |
| 81 | + # cols_post = [Dict("name" => "third column", "data" => 4:6)] |
| 82 | + # M.grid_post_col(fid_delete, cols_post) |
| 83 | + |
| 84 | + res2 = M.grid_destroy(fid_delete) |
| 85 | + @test statuscode(res2) == 204 |
| 86 | + |
| 87 | + |
| 88 | + res_col = M.grid_get_col_raw(fid, uid1) |
| 89 | + @test 200 == statuscode(res_col) |
| 90 | + col_json = Requests.json(res_col) |
| 91 | + @test col_json["cols"][1]["data"] == ["a", "b", "c"] |
| 92 | + |
| 93 | + res_col = M.grid_get_col_raw(fid, uid1, uid2) |
| 94 | + @test 200 == statuscode(res_col) |
| 95 | + col_json = Requests.json(res_col) |
| 96 | + @test col_json["cols"][1]["data"] == ["a", "b", "c"] |
| 97 | + @test col_json["cols"][2]["data"] == [1, 2, 3] |
| 98 | + |
| 99 | + @test 200 == statuscode(M.grid_trash_raw(fid)) |
| 100 | + @test 200 == statuscode(M.grid_restore_raw(fid)) |
| 101 | + @test 200 == statuscode(M.grid_partial_update_raw(fid, world_readable=true)) |
| 102 | + @test 200 == statuscode(M.grid_update_raw(fid, world_readable=false)) |
| 103 | + |
| 104 | + |
| 105 | + res_lookup = M.grid_lookup_raw("_jl_testing/mygrid") |
| 106 | + @test 200 == statuscode(res_lookup) |
| 107 | + lookup_json = Requests.json(res_lookup) |
| 108 | + @test lookup_json["filename"] == "mygrid" |
| 109 | + end |
| 110 | + |
| 111 | + @testset "plots" begin |
| 112 | + @test 200 == statuscode(M.plot_list_raw()) |
| 113 | + @test 200 == statuscode(M.plot_feed_raw()) |
| 114 | + |
| 115 | + fid = "sglyon:257" |
| 116 | + |
| 117 | + # test plot_create |
| 118 | + figure = Dict( |
| 119 | + "data" => [Dict( |
| 120 | + "type" => "bar", "xsrc" => "sglyon:251:d6434f", "ysrc" => "sglyon:251:8c7b60" |
| 121 | + )] |
| 122 | + ) |
| 123 | + del_fn = join(rand('a':'z', 10), "") |
| 124 | + res_del = M.plot_create_raw(figure, parent_path="_jl_testing", filename=del_fn) |
| 125 | + @test 201 == statuscode(res_create) |
| 126 | + del_json = Requests.json(res_del) |
| 127 | + del_fid = del_json["file"]["fid"] |
| 128 | + |
| 129 | + res_update = M.plot_update_raw(del_fid, world_readable=true) |
| 130 | + @test 200 == statuscode(res_update) |
| 131 | + @test Requests.json(res_update)["world_readable"] == true |
| 132 | + |
| 133 | + res_p_update = M.plot_partial_update_raw(del_fid, world_readable=false) |
| 134 | + @test 200 == statuscode(res_p_update) |
| 135 | + @test Requests.json(res_p_update)["world_readable"] == false |
| 136 | + |
| 137 | + M.file_trash(del_fid) |
| 138 | + |
| 139 | + res_detail = M.plot_detail_raw(fid) |
| 140 | + @test 200 == statuscode(res_detail) |
| 141 | + @test Requests.json(res_detail)["filename"] == "myplot" |
| 142 | + |
| 143 | + res_content = M.plot_content_raw(fid) |
| 144 | + @test 200 == statuscode(res_content) |
| 145 | + @test Requests.json(res_content) == figure |
| 146 | + end |
| 147 | + |
| 148 | + @testset "extras" begin |
| 149 | + # TODO |
| 150 | + end |
| 151 | + @testset "folders" begin |
| 152 | + # TODO |
| 153 | + end |
| 154 | + @testset "images" begin |
| 155 | + # TODO |
| 156 | + end |
| 157 | + @testset "comments" begin |
| 158 | + # TODO |
| 159 | + end |
| 160 | + @testset "plot-schema" begin |
| 161 | + # TODO |
| 162 | + end |
| 163 | +end |
| 164 | + |
| 165 | +# end |
0 commit comments