def test_list_users(self): ''' Test if it return a list of users based off of rabbitmqctl user_list. ''' mock_run = MagicMock(return_value='saltstack') with patch.dict(rabbitmq.__salt__, {'cmd.run': mock_run}): self.assertDictEqual(rabbitmq.list_users(), {})
def test_list_users(self): ''' Test if it return a list of users based off of rabbitmqctl user_list. ''' mock_run = MagicMock(return_value='Listing users ...\nguest\t[administrator]\n') with patch.dict(rabbitmq.__salt__, {'cmd.run': mock_run}): self.assertDictEqual(rabbitmq.list_users(), {'guest': set(['administrator'])})
def test_list_users_rabbitmq3(self): ''' Test if it return a list of users based off of rabbitmqctl user_list. ''' mock_run = MagicMock(return_value={'retcode': 0, 'stdout': 'Listing users ...\nguest\t[administrator user]\n', 'stderr': ''}) with patch.dict(rabbitmq.__salt__, {'cmd.run_all': mock_run}): self.assertDictEqual(rabbitmq.list_users(), {'guest': ['administrator', 'user']})
def test_list_users_rabbitmq3(self): ''' Test if it return a list of users based off of rabbitmqctl user_list. ''' mock_run = MagicMock(return_value={ 'retcode': 0, 'stdout': 'guest\t[administrator user]\r\nother\t[a b]\r\n', 'stderr': '' }) with patch.dict(rabbitmq.__salt__, {'cmd.run_all': mock_run}): self.assertDictEqual(rabbitmq.list_users(), {'guest': ['administrator', 'user'], 'other': ['a', 'b']})
def test_list_users_with_warning(self): ''' Test if having a leading WARNING returns the user_list anyway. ''' rtn_val = '\n'.join([ 'WARNING: ignoring /etc/rabbitmq/rabbitmq.conf -- location has moved to /etc/rabbitmq/rabbitmq-env.conf', 'Listing users ...', 'guest\t[administrator]\n', ]) mock_run = MagicMock(return_value=rtn_val) with patch.dict(rabbitmq.__salt__, {'cmd.run': mock_run}): self.assertDictEqual(rabbitmq.list_users(), {'guest': set(['administrator'])})
def test_list_users_with_warning_rabbitmq3(self): ''' Test if having a leading WARNING returns the user_list anyway. ''' rtn_stdout = '\n'.join([ 'WARNING: ignoring /etc/rabbitmq/rabbitmq.conf -- location has moved to /etc/rabbitmq/rabbitmq-env.conf', 'Listing users ...', 'guest\t[administrator user]\n', ]) mock_run = MagicMock(return_value={'retcode': 0, 'stdout': rtn_stdout, 'stderr': ''}) with patch.dict(rabbitmq.__salt__, {'cmd.run_all': mock_run}): self.assertDictEqual(rabbitmq.list_users(), {'guest': ['administrator', 'user']})
def test_list_users_rabbitmq2(self): ''' Test if it return a list of users based off of rabbitmqctl user_list. ''' mock_run = MagicMock(return_value={ 'retcode': 0, 'stdout': 'Listing users ...\nguest\t[administrator, user]\njustAnAdmin\t[administrator]\n', 'stderr': '', }) with patch.dict(rabbitmq.__salt__, {'cmd.run_all': mock_run}): self.assertDictEqual(rabbitmq.list_users(), {'guest': ['administrator', 'user'], 'justAnAdmin': ['administrator']})
def test_list_users_rabbitmq3(): """ Test if it return a list of users based off of rabbitmqctl user_list. """ mock_run = MagicMock( return_value={ "retcode": 0, "stdout": "guest\t[administrator user]\r\nother\t[a b]\r\n", "stderr": "", }) with patch.dict(rabbitmq.__salt__, {"cmd.run_all": mock_run}): assert rabbitmq.list_users() == { "guest": ["administrator", "user"], "other": ["a", "b"], }
def test_list_users_with_warning_rabbitmq3(): """ Test if having a leading WARNING returns the user_list anyway. """ rtn_stdout = "\n".join([ "WARNING: ignoring /etc/rabbitmq/rabbitmq.conf -- location has moved to /etc/rabbitmq/rabbitmq-env.conf", "Listing users ...", "guest\t[administrator user]\n", ]) mock_run = MagicMock(return_value={ "retcode": 0, "stdout": rtn_stdout, "stderr": "" }) with patch.dict(rabbitmq.__salt__, {"cmd.run_all": mock_run}): assert rabbitmq.list_users() == {"guest": ["administrator", "user"]}
def test_list_users_rabbitmq2(): """ Test if it return a list of users based off of rabbitmqctl user_list. """ mock_run = MagicMock( return_value={ "retcode": 0, "stdout": "Listing users ...\nguest\t[administrator, user]\njustAnAdmin\t[administrator]\n", "stderr": "", }) with patch.dict(rabbitmq.__salt__, {"cmd.run_all": mock_run}): assert rabbitmq.list_users() == { "guest": ["administrator", "user"], "justAnAdmin": ["administrator"], }