nitrpg: add nitunits
[nit.git] / contrib / nitrpg / src / test_helper.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014-2015 Alexandre Terrasa <alexandre@moz-code.org>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Test tools for NitRPG.
18 module test_helper is test_suite
19
20 import test_suite
21 import game
22 import github::cache
23
24 # Used to factorize test treatments.
25 abstract class NitrpgTestHelper
26 super TestSuite
27
28 # Github API client
29 var api: GithubAPI do
30 var api = new GithubAPI(get_github_oauth)
31 api.enable_cache = true
32 return api
33 end
34
35 # Mongo API client
36 var mongo = new MongoClient("mongodb://localhost:27017/")
37
38 # Load a new test database by with a name
39 fun load_db(name: String): MongoDb do return mongo.database(name)
40
41 # Load a repo by its name.
42 fun load_repo(name: String): Repo do
43 var repo = api.load_repo(name)
44 assert repo != null
45 return repo
46 end
47
48 # Load a game by its name.
49 fun load_game(name: String, db: MongoDb): Game do
50 var game = new Game(api, load_repo(name))
51 game.db_name = db.name
52 return game
53 end
54 end