def test_exception_handling_when_duplicate_username( self, mock_username, mock_yubikey, mock_stdout): """Regression test for duplicate username logic in manage.py""" # Inserting the user for the first time should succeed return_value = manage._add_user() self.assertEqual(return_value, 0) self.assertIn('successfully added', sys.stdout.getvalue()) # Inserting the user for a second time should fail return_value = manage._add_user() self.assertEqual(return_value, 1) self.assertIn('ERROR: That username is already taken!', sys.stdout.getvalue())
def test_exception_handling_when_duplicate_username(self, mock_username, mock_yubikey, mock_stdout): """Regression test for duplicate username logic in manage.py""" # Inserting the user for the first time should succeed return_value = manage._add_user() self.assertEqual(return_value, 0) self.assertIn('successfully added', sys.stdout.getvalue()) # Inserting the user for a second time should fail return_value = manage._add_user() self.assertEqual(return_value, 1) self.assertIn('ERROR: That username is already taken!', sys.stdout.getvalue())
def test_delete_user(self, mock_username, mock_yubikey, mock_user_to_delete, mock_user_del_confirm): return_value = manage._add_user() self.assertEqual(return_value, 0) return_value = manage.delete_user(args=None) self.assertEqual(return_value, 0)
def test_handle_invalid_secret(self, mock_username, mock_yubikey, mock_htop, mock_stdout): """Regression test for bad secret logic in manage.py""" # We will try to provide one invalid and one valid secret return_value = manage._add_user() self.assertEqual(return_value, 0) self.assertIn('Try again.', sys.stdout.getvalue()) self.assertIn('successfully added', sys.stdout.getvalue())
def test_exception_handling_when_duplicate_username(journalist_app, config, mocker, capsys): """Regression test for duplicate username logic in manage.py""" mocker.patch("manage._get_username", return_value='foo-bar-baz') mocker.patch("manage._get_first_name", return_value='') mocker.patch("manage._get_last_name", return_value='') mocker.patch("manage._get_yubikey_usage", return_value=False) with journalist_app.app_context() as context: # Inserting the user for the first time should succeed return_value = manage._add_user(context=context) out, err = capsys.readouterr() assert return_value == 0 assert 'successfully added' in out # Inserting the user for a second time should fail return_value = manage._add_user() out, err = capsys.readouterr() assert return_value == 1 assert 'ERROR: That username is already taken!' in out
def test_delete_user(journalist_app, config, mocker): mocker.patch("manage._get_username", return_value='test-user-56789') mocker.patch("manage._get_first_name", return_value='') mocker.patch("manage._get_last_name", return_value='') mocker.patch("manage._get_yubikey_usage", return_value=False) mocker.patch("manage._get_username_to_delete", return_value='test-user-56789') mocker.patch('manage._get_delete_confirmation', return_value=True) with journalist_app.app_context() as context: return_value = manage._add_user(context=context) assert return_value == 0 return_value = manage.delete_user(args=None) assert return_value == 0
def test_handle_invalid_secret(journalist_app, config, mocker, capsys): """Regression test for bad secret logic in manage.py""" mocker.patch("manage._get_username", return_value='ntoll'), mocker.patch("manage._get_first_name", return_value=''), mocker.patch("manage._get_last_name", return_value=''), mocker.patch("manage._get_yubikey_usage", return_value=True), mocker.patch("manage.obtain_input", side_effect=YUBIKEY_HOTP), with journalist_app.app_context() as context: # We will try to provide one invalid and one valid secret return_value = manage._add_user(context=context) out, err = capsys.readouterr() assert return_value == 0 assert 'Try again.' in out assert 'successfully added' in out