~soren/nova/lp658257

« back to all changes in this revision

Viewing changes to nova/tests/api/rackspace/fakes.py

  • Committer: Tarmac
  • Author(s): jaypipes at gmail
  • Date: 2010-10-04 22:13:42 UTC
  • mfrom: (316.6.1 cleanup-for-nosetests)
  • Revision ID: hudson@openstack.org-20101004221342-sg80df0rofke8qh1
Cleans up the unit tests that are meant to be run with nosetests

    * Renames all test modules to start with test_ so that nosetests does
    not need to be run with the --all-modules flag in order to pick them up
    * Renames test_helper to fakes and removes imports in unit tests that
    did not reference the fakes
    * Adds nose to pip-requires so that run_tests.sh -V will install nose
    into the virtualenv instead of having to manually install it after running
    into import errors :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
from nova.image import service
13
13
from nova.wsgi import Router
14
14
 
 
15
 
15
16
FLAGS = flags.FLAGS
16
17
 
 
18
 
17
19
class Context(object): 
18
20
    pass
19
21
 
 
22
 
20
23
class FakeRouter(Router):
21
24
    def __init__(self):
22
25
        pass
28
31
        res.headers['X-Test-Success'] = 'True'
29
32
        return res
30
33
 
 
34
 
31
35
def fake_auth_init(self):
32
36
    self.db = FakeAuthDatabase()
33
37
    self.context = Context()
34
38
    self.auth = FakeAuthManager()
35
39
    self.host = 'foo'
36
40
 
 
41
 
37
42
@webob.dec.wsgify
38
43
def fake_wsgi(self, req):
39
44
    req.environ['nova.context'] = dict(user=dict(id=1))
41
46
        req.environ['inst_dict'] = json.loads(req.body)
42
47
    return self.application
43
48
 
 
49
 
44
50
def stub_out_key_pair_funcs(stubs):
45
51
    def key_pair(context, user_id):
46
52
        return [dict(name='key', public_key='public_key')]
47
53
    stubs.Set(nova.db.api, 'key_pair_get_all_by_user',
48
54
        key_pair)
49
55
 
 
56
 
50
57
def stub_out_image_service(stubs):
51
58
    def fake_image_show(meh, id):
52
59
        return dict(kernelId=1, ramdiskId=1)
53
60
 
54
61
    stubs.Set(nova.image.service.LocalImageService, 'show', fake_image_show)
55
62
 
 
63
 
56
64
def stub_out_id_translator(stubs):
57
65
    class FakeTranslator(object):
58
66
        def __init__(self, id_type, service_name):
67
75
    stubs.Set(nova.api.rackspace._id_translator,
68
76
        'RackspaceAPIIdTranslator', FakeTranslator)
69
77
 
 
78
 
70
79
def stub_out_auth(stubs):
71
80
    def fake_auth_init(self, app):
72
81
        self.application = app
76
85
    stubs.Set(nova.api.rackspace.AuthMiddleware, 
77
86
        '__call__', fake_wsgi) 
78
87
 
 
88
 
79
89
def stub_out_rate_limiting(stubs):
80
90
    def fake_rate_init(self, app):
81
91
        super(nova.api.rackspace.RateLimitingMiddleware, self).__init__(app)
87
97
    stubs.Set(nova.api.rackspace.RateLimitingMiddleware,
88
98
        '__call__', fake_wsgi)
89
99
 
90
 
def stub_for_testing(stubs):
 
100
 
 
101
def stub_out_networking(stubs):
91
102
    def get_my_ip():
92
103
        return '127.0.0.1' 
93
104
    stubs.Set(nova.utils, 'get_my_ip', get_my_ip)
94
105
    FLAGS.FAKE_subdomain = 'rs'
95
106
 
 
107
 
96
108
class FakeAuthDatabase(object):
97
109
    data = {}
98
110
 
110
122
        if FakeAuthDatabase.data.has_key(token['token_hash']):
111
123
            del FakeAuthDatabase.data['token_hash']
112
124
 
 
125
 
113
126
class FakeAuthManager(object):
114
127
    auth_data = {}
115
128
 
125
138
    def get_user_from_access_key(self, key):
126
139
        return FakeAuthManager.auth_data.get(key, None)
127
140
 
 
141
 
128
142
class FakeRateLimiter(object):
129
143
    def __init__(self, application):
130
144
        self.application = application