1
|
|
|
import os |
2
|
|
|
import unittest |
3
|
|
|
import backend.fcmutils as utils |
4
|
|
|
#from backend.fcmapp import ApplicationService |
5
|
|
|
from domain.mining import AvailablePool |
6
|
|
|
from domain.rep import MinerRepository, PoolRepository, LoginRepository, RuleParametersRepository |
7
|
|
|
from messaging.schema import AvailablePoolSchema |
8
|
|
|
|
9
|
|
|
class TestApp(unittest.TestCase): |
10
|
|
|
def test_app_json_serialize(self): |
11
|
|
|
pool = AvailablePool('S9', None, 'url', 'user', 'x', 0) |
12
|
|
|
strpool = utils.jsonserialize(AvailablePoolSchema(), pool) |
13
|
|
|
self.assertTrue(isinstance(strpool, str)) |
14
|
|
|
self.assertFalse(strpool.startswith('[')) |
15
|
|
|
|
16
|
|
|
def test_rep_miner_repository(self): |
17
|
|
|
homedirectory = os.path.dirname(__file__) |
18
|
|
|
config = os.path.join(homedirectory, '../backend/config/miners.conf') |
19
|
|
|
rep = MinerRepository() |
20
|
|
|
miners = rep.readminers(config) |
21
|
|
|
self.assertTrue(miners) |
22
|
|
|
miner = rep.getminerbyname(miners[0].name, config) |
23
|
|
|
self.assertTrue(miner) |
24
|
|
|
|
25
|
|
|
def test_rep_pool_repository(self): |
26
|
|
|
homedirectory = os.path.dirname(__file__) |
27
|
|
|
config = os.path.join(homedirectory, '../backend/config/pools.conf') |
28
|
|
|
rep = PoolRepository() |
29
|
|
|
pools = rep.readpools(config) |
30
|
|
|
self.assertTrue(pools) |
31
|
|
|
#todo: rep.add |
32
|
|
|
|
33
|
|
|
def test_rep_login_repository(self): |
34
|
|
|
homedirectory = os.path.dirname(__file__) |
35
|
|
|
config = os.path.join(homedirectory, '../backend/config/ftp.conf') |
36
|
|
|
rep = LoginRepository() |
37
|
|
|
login = rep.readlogins(config) |
38
|
|
|
self.assertTrue(login) |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
def test_rep_rules_repository(self): |
42
|
|
|
homedirectory = os.path.dirname(__file__) |
43
|
|
|
config = os.path.join(homedirectory, '../backend/config/rules.conf') |
44
|
|
|
rep = RuleParametersRepository() |
45
|
|
|
rules = rep.readrules(config) |
46
|
|
|
self.assertTrue(rules) |
47
|
|
|
|
48
|
|
|
|
49
|
|
|
#def test_app_knownpools(self): |
50
|
|
|
# app = ApplicationService(component='test') |
51
|
|
|
# app.startup() |
52
|
|
|
# pools = app.pools.knownpools() |
53
|
|
|
# self.assertTrue(len(pools) > 0) |
54
|
|
|
# for pool in pools: |
55
|
|
|
# self.assertTrue(isinstance(pool, AvailablePool)) |
56
|
|
|
|
57
|
|
|
#def test_app_no_dupe_miners(self): |
58
|
|
|
# app = ApplicationService(component='test') |
59
|
|
|
# app.cache.purge() |
60
|
|
|
# app.startup() |
61
|
|
|
# original_miners = app.knownminers() |
62
|
|
|
# miner = Miner("unittest", None, "", "unitip", "unitport", "", "") |
63
|
|
|
# #add the test miner |
64
|
|
|
# app.updateknownminer(miner) |
65
|
|
|
# miners_withtest = app.knownminers() |
66
|
|
|
# #put same in cache should not increase count |
67
|
|
|
# app.updateknownminer(miner) |
68
|
|
|
# miners_afterputtingtwice = app.knownminers() |
69
|
|
|
# self.assertTrue(len(miners_withtest) == len(miners_afterputtingtwice)) |
70
|
|
|
|
71
|
|
|
#def test_app_update_miner(self): |
72
|
|
|
# app = ApplicationService(component='test') |
73
|
|
|
# app.cache.purge() |
74
|
|
|
# app.startup() |
75
|
|
|
# original_miners = app.knownminers() |
76
|
|
|
# miner = Miner("unittest", None, "", "unitip", "unitport", "", "") |
77
|
|
|
# #add the test miner |
78
|
|
|
# app.updateknownminer(miner) |
79
|
|
|
# miners_withtest = app.knownminers() |
80
|
|
|
# #put same in cache should not increase count |
81
|
|
|
# #this simulates a miner getting queries and minerid has changed |
82
|
|
|
# miner_updated = Miner("unittest", None, "", "unitip", "unitport", "", "") |
83
|
|
|
# miner_updated.minerid="unittest_unique" |
84
|
|
|
# app.updateknownminer(miner_updated) |
85
|
|
|
# miners_afterputtingtwice = app.knownminers() |
86
|
|
|
# self.assertTrue(len(miners_withtest) == len(miners_afterputtingtwice)) |
87
|
|
|
# miner_from_cache = app.getknownminer(miner_updated) |
88
|
|
|
# self.assertIsNotNone(miner_from_cache) |
89
|
|
|
|
90
|
|
|
if __name__ == '__main__': |
91
|
|
|
unittest.main() |
92
|
|
|
|