def root_user_fixture(): """ Create a root user for some tests""" user_id, email, token = _signup_root_user() yield user_id, email, token # Start cleaning up print("cleaning root_user_fixture") delete_user(email)
def test_delete_user(self): user = UserFactory() found = User.query.filter_by(email=user.email).first() self.assertIsNotNone(found) self.assertEqual(found.email, user.email) delete_user(user.email) deluser = User.query.filter_by(email=user.email).first() self.assertIsNone(deluser)
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_delete_non_existent_user(self, mock_user_to_delete, mock_user_del_confirm, mock_stdout): return_value = manage.delete_user(args=None) self.assertEqual(return_value, 0) self.assertIn('ERROR: That user was not found!', sys.stdout.getvalue())
def test_delete_non_existent_user(journalist_app, config, mocker, capsys): mocker.patch("manage._get_username_to_delete", return_value='does-not-exist') mocker.patch('manage._get_delete_confirmation', return_value=True) with journalist_app.app_context() as context: return_value = manage.delete_user(args=None, context=context) out, err = capsys.readouterr() assert return_value == 0 assert 'ERROR: That user was not found!' 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