예제 #1
0
    def test_update_passwordmatch_nomatch_field(self, fields, mock_get):
        """ password that doesnt need updating """
        value = [{
            "Password": "******",
            "Title": "bar",
            "UserName": "******",
            "GenericField1": "123",
            "PasswordID": 999
        }]
        mock_get.return_value = mock.Mock(status_code=200, json=lambda: value)

        module = mock.Mock()
        module.exit_json = mock.MagicMock()
        url = "http://passwordstate"
        api_key = "abc123xyz"

        api = PasswordState(module, url, api_key)
        password = Password(api, '123', {
            'id': None,
            'field': 'GenericField1',
            'field_id': '123'
        })

        password.update(fields)

        module.exit_json.assert_called_with(changed=True)
예제 #2
0
    def test_init(self):
        """ test constructor """
        module = mock.Mock()
        url = "http://passwordstate"
        api_key = "abc123xyz"
        passwordstate = PasswordState(module, url, api_key)

        self.assertEqual(passwordstate.module, module)
        self.assertEqual(passwordstate.url, url)
        self.assertEqual(passwordstate.api_key, api_key)
예제 #3
0
    def test_update_newpassword_withtitle(self, mock_urlopen):
        """ password that doesnt need updating """
        mock_urlopen.return_value.read.return_value = '[]'

        module = mock.Mock()
        module.exit_json = mock.MagicMock()
        url = "http://passwordstate"
        api_key = "abc123xyz"

        api = PasswordState(module, url, api_key)
        password = Password(api, '123',
                            {'id': None, 'field': 'GenericField1', 'field_id': '123'})

        fields = {'password': '******', 'Title': 'mytitle'}
        password.update(fields)

        module.exit_json.assert_called_with(changed=True)
예제 #4
0
    def test_update_passwordmatch_nomatch_id(self, fields, mock_urlopen):
        """ password that doesnt need updating """
        value = '[{"Password": "******", "Title": "bar", ' \
                '"UserName": "******", "GenericField1": "123", ' \
                '"PasswordID": 999}]'
        mock_urlopen.return_value.read.return_value = value

        module = mock.Mock()
        module.exit_json = mock.MagicMock()
        url = "http://passwordstate"
        api_key = "abc123xyz"

        api = PasswordState(module, url, api_key)
        password = Password(api, '123',
                            {'id': '999', 'field': None, 'field_id': None})

        password.update(fields)

        module.exit_json.assert_called_with(changed=True)
예제 #5
0
    def test_update_newpassword_notitle(self, mock_get):
        """ password that doesnt need updating """
        mock_get.return_value = mock.Mock(status_code=200, json=lambda: [])

        module = mock.Mock()
        module.fail_json = mock.MagicMock()
        url = "http://passwordstate"
        api_key = "abc123xyz"

        api = PasswordState(module, url, api_key)
        password = Password(api, '123', {
            'id': None,
            'field': 'GenericField1',
            'field_id': '123'
        })

        fields = {'password': '******'}
        password.update(fields)

        module.fail_json.assert_called_with(
            msg='Title is required when creating passwords')