0

I'm new to moto and aws so I'm trying to wrtie some simple tests cases for a simple ELB checker in aws.

I have read the moto page here:

https://github.com/spulec/moto

and I am following the boto3 guide here:

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

But I dont think I am understanding how to use moto with boto3. Below is my code and error, any help would be greatly appreciated.

# # -*- 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()

output:

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)
Justin S
  • 1,409
  • 4
  • 22
  • 38

1 Answers1

1

Ok so I got some help from a friend. The below should do the trick

# # -*- 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()
Justin S
  • 1,409
  • 4
  • 22
  • 38