diff --git a/tests/test_progit_flask_ui_app.py b/tests/test_progit_flask_ui_app.py index 517941d..beddd76 100644 --- a/tests/test_progit_flask_ui_app.py +++ b/tests/test_progit_flask_ui_app.py @@ -279,6 +279,98 @@ class PagureFlaskApptests(tests.Modeltests): """ self.assertEqual(output.data, exp) + @patch('pagure.ui.app.admin_session_timedout') + def test_remove_user_email(self, ast): + """ Test the remove_user_email endpoint. """ + ast.return_value = False + self.test_new_project() + + user = tests.FakeUser() + with tests.user_set(pagure.APP, user): + output = self.app.post('/settings/email/drop') + self.assertEqual(output.status_code, 404) + self.assertTrue('

Page not found (404)

' in output.data) + + user.username = 'foo' + with tests.user_set(pagure.APP, user): + output = self.app.post('/settings/') + self.assertEqual(output.status_code, 200) + self.assertTrue("

foo's settings

" in output.data) + self.assertTrue( + '' + in output.data) + + csrf_token = output.data.split( + 'name="csrf_token" type="hidden" value="')[1].split('">')[0] + + data = { + 'email': 'foo@pingou.com', + } + + output = self.app.post( + '/settings/email/drop', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertTrue("

foo's settings

" in output.data) + self.assertIn( + '
  • You must always have at least one email
  • ', + output.data) + + user.username = 'pingou' + with tests.user_set(pagure.APP, user): + output = self.app.post('/settings/') + self.assertEqual(output.status_code, 200) + self.assertTrue("

    pingou's settings

    " in output.data) + self.assertTrue( + '' + in output.data) + + csrf_token = output.data.split( + 'name="csrf_token" type="hidden" value="')[1].split('">')[0] + + data = { + 'email': 'foo@pingou.com', + } + + output = self.app.post( + '/settings/email/drop', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertTrue("

    pingou's settings

    " in output.data) + self.assertEqual(output.data.count('foo@pingou.com'), 4) + + data = { + 'csrf_token': csrf_token, + 'email': 'foobar@pingou.com', + } + + output = self.app.post( + '/settings/email/drop', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertTrue("

    pingou's settings

    " in output.data) + self.assertIn( + '
  • You do not have the email: foobar@pingou' + '.com, nothing to remove
  • ', output.data) + + data = { + 'csrf_token': csrf_token, + 'email': 'foo@pingou.com', + } + + output = self.app.post( + '/settings/email/drop', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertEqual(output.data.count('foo@pingou.com'), 0) + self.assertEqual(output.data.count('bar@pingou.com'), 3) + + output = self.app.post( + '/settings/email/drop', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertEqual(output.data.count('foo@pingou.com'), 0) + self.assertEqual(output.data.count('bar@pingou.com'), 3) + + ast.return_value = True + output = self.app.post('/settings/email/drop', data=data) + self.assertEqual(output.status_code, 302) + if __name__ == '__main__': SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskApptests)