1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 module test_wallet
is test
21 # Tokens mocked as valid
23 # All other tokens will be considered as bad credentials.
24 var valid_tokens
= ["t1", "t2"]
26 # Mock so it returns the response from a file
28 # See `update_responses_cache`.
29 redef fun get_auth_user
do
30 if not valid_tokens
.has
(auth
) then
32 last_error
= new GithubAPIError("""{
33 "message":"Bad credentials",
34 "documentation_url":"https://developer.github.com/v3"
41 return new User("test")
45 class TestGithubWallet
48 fun test_get_next_token
is test
do
49 var wallet
= new GithubWallet(["t1", "t2", "t3"])
52 for i
in [1..3] do assert wallet
.get_next_token
== "t{i}"
56 fun test_get_api_only_bad
is test
do
57 var wallet
= new GithubWallet(["bad1", "bad2"])
58 assert wallet
.api
.auth
== "bad2"
59 assert wallet
.api
.auth
== "bad2"
62 fun test_get_api
is test
do
63 var wallet
= new GithubWallet(["bad1", "t1", "t2", "bad2"])
64 assert wallet
.api
.auth
== "t1"
65 assert wallet
.api
.auth
== "t2"
66 assert wallet
.api
.auth
== "t1"
67 assert wallet
.api
.auth
== "t2"