Example #1
0
 def test_ensure_get_called_existing(self):
     ''' test get_subnet for existing subnet'''
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     my_obj.server = MockONTAPConnection(kind='subnet', data=data)
     assert my_obj.get_subnet() is not None
Example #2
0
    def test_successful_delete(self, delete_subnet, mock_ems_log):
        ''' deleting subnet and testing idempotency '''
        data = self.set_default_args()
        data['state'] = 'absent'
        set_module_args(data)
        my_obj = my_module()
        my_obj.server = MockONTAPConnection(kind='subnet', data=data)
        with pytest.raises(AnsibleExitJson) as exc:
            my_obj.apply()
        assert exc.value.args[0]['changed']
        delete_subnet.assert_called_with()

        # to reset na_helper from remembering the previous 'changed' value
        my_obj = my_module()
        my_obj.server = self.server
        with pytest.raises(AnsibleExitJson) as exc:
            my_obj.apply()
        assert not exc.value.args[0]['changed']
Example #3
0
 def test_successful_modify(self, mock_ems_log):
     ''' modifying subnet and testing idempotency '''
     data = self.set_default_args()
     data.update({'ip_ranges': ['10.0.0.10-10.0.0.25', '10.0.0.30']})
     set_module_args(data)
     my_obj = my_module()
     my_obj.server = MockONTAPConnection(kind='subnet',
                                         data=self.set_default_args())
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
Example #4
0
 def test_successful_rename(self, rename_subnet, mock_ems_log):
     ''' renaming subnet '''
     data = self.set_default_args()
     data.update({'from_name': data['name'], 'name': 'new_test_subnet'})
     set_module_args(data)
     my_obj = my_module()
     my_obj.server = MockONTAPConnection(kind='subnet',
                                         data=self.set_default_args())
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
Example #5
0
 def test_fail_broadcast_domain_modify(self, mock_ems_log):
     ''' test that boradcast_domain is not alterable '''
     data = self.set_default_args()
     data.update({'broadcast_domain': 'Test'})
     set_module_args(data)
     my_obj = my_module()
     my_obj.server = MockONTAPConnection(kind='subnet',
                                         data=self.set_default_args())
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.apply()
     assert 'cannot modify broadcast_domain parameter' in exc.value.args[0][
         'msg']
Example #6
0
 def test_if_all_methods_catch_exception(self, mock_ems_log):
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     my_obj.server = MockONTAPConnection(kind='subnet_fail', data=data)
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.create_subnet()
     assert 'Error creating subnet' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.delete_subnet()
     assert 'Error deleting subnet' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.modify_subnet()
     assert 'Error modifying subnet' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.rename_subnet()
     assert 'Error renaming subnet' in exc.value.args[0]['msg']
Example #7
0
 def test_ensure_get_called(self):
     ''' test get_subnet for non-existent subnet'''
     set_module_args(self.set_default_args())
     my_obj = my_module()
     my_obj.server = self.server
     assert my_obj.get_subnet() is None
Example #8
0
 def test_module_fail_when_required_args_missing(self):
     ''' required arguments are reported as errors '''
     with pytest.raises(AnsibleFailJson) as exc:
         set_module_args({})
         my_module()
     print('Info: %s' % exc.value.args[0]['msg'])