2016-06-15 3 views
0

私はモトとawsには新しいので、私はawsで簡単なELBチェッカーのいくつかの簡単なテストケースを作ろうとしています。moto with boto3 - モックを作ることができないELB

私はここモトページ読んだ:

https://github.com/spulec/moto

を、私はここにboto3ガイド次午前:

https://boto3.readthedocs.io/en/latest/reference/services/elb.html

しかし、私は、私はモトを使用する方法を理解していと思ういけませんboto3で。以下は私のコードとエラーですが、どんな助けでも大歓迎です。

# # -*- coding: utf-8 -*- 

from .context import elb_tools 

from nose.tools import set_trace; 
import unittest 

from moto.elb import mock_elb 
import boto3 



class TestElbTools(unittest.TestCase): 
    """Basic test cases.""" 

    def setUp(self): 
     pass 

    @mock_elb 
    def test_check_elb_has_attached_instances(self): 
     empty_elb = mock_elb 
     mock_elb.describe_load_balancers() 

if __name__ == '__main__': 
    unittest.main() 

出力:

D:\dev\git_repos\platform-health>nosetests 
E 
====================================================================== 
ERROR: test_check_elb_has_attached_instances (test_orphan_elb_finder.test_elb_tools.TestElbTools) 
---------------------------------------------------------------------- 
Traceback (most recent call last): 
    File "d:\apps\python\python27\lib\site-packages\moto\core\models.py", line 71, in wrapper 
    result = func(*args, **kwargs) 
    File "D:\dev\git_repos\platform-health\tests\unit_tests\test_orphan_elb_finder\test_elb_tools.py", line 22, in test_check_elb_has_attached_instances 
    mock_elb.describe_load_balancers() 
AttributeError: 'function' object has no attribute 'describe_load_balancers' 

---------------------------------------------------------------------- 
Ran 1 test in 0.561s 

FAILED (errors=1) 

答えて

0

[OK]をので、私は友人からいくつかの助けを得ました。以下はトリックを行う必要があります

# # -*- coding: utf-8 -*- 

from .context import elb_tools 

from nose.tools import set_trace; 
import unittest 

from moto.elb import mock_elb 
import boto3 

class TestElbTools(unittest.TestCase): 
    """Basic test cases.""" 

    def setUp(self): 
     #pass 
     self.region = 'ap-southeast-2' 

    @mock_elb 
    def test_check_elb_has_attached_instances(self): 
     elb_client = boto3.client('elb', region_name=self.region) 
     set_trace() 
     elb_client.describe_load_balancers() 

if __name__ == '__main__': 
    unittest.main() 
関連する問題