Exemplo n.º 1
0
 def test_successful_create(self, create_nvme):
     ''' creating nvme and testing idempotency '''
     set_module_args(self.set_default_args())
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = self.server
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     create_nvme.assert_called_with()
     # to reset na_helper from remembering the previous 'changed' value
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('nvme')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
Exemplo n.º 2
0
 def test_successful_modify(self, modify_nvme):
     ''' modifying nvme and testing idempotency '''
     data = self.set_default_args()
     data['status_admin'] = False
     set_module_args(data)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('nvme')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert exc.value.args[0]['changed']
     modify_nvme.assert_called_with()
     # to reset na_helper from remembering the previous 'changed' value
     data = self.set_default_args()
     set_module_args(data)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('nvme')
     with pytest.raises(AnsibleExitJson) as exc:
         my_obj.apply()
     assert not exc.value.args[0]['changed']
Exemplo n.º 3
0
 def test_if_all_methods_catch_exception(self):
     module_args = {}
     module_args.update(self.set_default_args())
     set_module_args(module_args)
     my_obj = my_module()
     if not self.onbox:
         my_obj.server = MockONTAPConnection('nvme_fail')
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.get_nvme()
     assert 'Error fetching nvme info:' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.create_nvme()
     assert 'Error creating nvme' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.delete_nvme()
     assert 'Error deleting nvme' in exc.value.args[0]['msg']
     with pytest.raises(AnsibleFailJson) as exc:
         my_obj.modify_nvme()
     assert 'Error modifying nvme' in exc.value.args[0]['msg']
Exemplo n.º 4
0
 def test_ensure_get_called_existing(self):
     ''' test get_nvme()  for existing nvme'''
     set_module_args(self.set_default_args())
     my_obj = my_module()
     my_obj.server = MockONTAPConnection(kind='nvme')
     assert my_obj.get_nvme()
Exemplo n.º 5
0
 def test_ensure_get_called(self):
     ''' test get_nvme()  for non-existent nvme'''
     set_module_args(self.set_default_args())
     my_obj = my_module()
     my_obj.server = self.server
     assert my_obj.get_nvme() is None
Exemplo n.º 6
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'])