#189 Make fedocal rely on fedocal-messages to check the structure of the messages sent
Merged a month ago by pingou. Opened 5 months ago by pingou.

file modified
+4 -4
@@ -1307,10 +1307,10 @@ 

                  LOG.exception(err)

                  flask.flash(gettext(

                      'Could not clear this calendar.'), 'errors')

-         fedmsg.publish(topic="calendar.clear", msg=dict(

-             agent=flask.g.fas_user.username,

-             calendar=calendarobj.to_json(),

-         ))

+             fedmsg.publish(topic="calendar.clear", msg=dict(

+                 agent=flask.g.fas_user.username,

+                 calendar=calendarobj.to_json(),

+             ))

          return flask.redirect(flask.url_for(

              'calendar', calendar_name=calendar_name))

      return flask.render_template(

@@ -11,6 +11,9 @@ 

  import fedora_messaging.api

  from fedora_messaging.exceptions import PublishReturned, ConnectionException

  

+ import fedocal_messages

+ import fedocal_messages.messages as schema

+ 

  

  _log = logging.getLogger(__name__)

  
@@ -18,10 +21,18 @@ 

  def publish(topic, msg):  # pragma: no cover

      _log.debug('Publishing a message for %s: %s', topic, msg)

      try:

-         message = fedora_messaging.api.Message(

-             topic='fedocal.%s' % topic,

-             body=msg

+ 

+         msg_cls = fedocal_messages.get_message_object_from_topic(

+             'fedocal.%s' % topic

          )

+ 

+         if not hasattr(msg_cls, "app_name") is False:

+             _log.warning(

+                 "fedocal is about to send a message that has no schemas: %s",

+                 topic

+             )

+ 

+         message = msg_cls(body=msg)

          fedora_messaging.api.publish(message)

          _log.debug("Sent to fedora_messaging")

      except PublishReturned as e:

file modified
+6 -5
@@ -28,6 +28,7 @@ 

  from fedocal.fedocal_babel import lazy_gettext as _

  from fedocal import i18nforms

  

+ import email_validator

  from pytz import common_timezones

  

  import wtforms
@@ -64,16 +65,16 @@ 

      """ Raises an exception if the content of the field does not contain one or

          more email.

      """

-     pattern = re.compile(r'^.+@([^.@][^@]+)$', re.IGNORECASE)

      data = field.data.replace(' ', ',')

      for entry in data.split(','):

          entry = entry.strip()

          if not entry:

              continue

-         match = pattern.match(field.data or '')

-         if not match:

-             message = field.gettext(_('Invalid input.'))

-             raise wtforms.ValidationError(message)

+         try:

+             email_validator.validate_email(entry)

+         except email_validator.EmailNotValidError as e:

+             # email is not valid, exception message is human-readable

+             raise wtforms.ValidationError(str(e))

  

  

  class AddCalendarForm(i18nforms.Form):

file modified
+1
@@ -23,3 +23,4 @@ 

  flask_oidc

  fedora-messaging

  email_validator

+ fedocal-messages>=1.4.0

file modified
-13
@@ -71,19 +71,6 @@ 

      os.path.abspath(__file__)), 'ical_wrong.txt')

  

  

- def flask10_only(function):

-     """ Decorator to skip tests if the flask version is lower than 0.10 """

-     @wraps(function)

-     def decorated_function(*args, **kwargs):

-         """ Decorated function, actually does the work. """

-         import flask

-         ver = flask.__version__.split('.')

-         if int(ver[0]) >= 0 and int(ver[1]) >= 10:

-             return function(*args, **kwargs)

-         return 'Skipped'

-     return decorated_function

- 

- 

  @contextmanager

  def user_set(APP, user):

      """ Set the provided user as fas_user in the provided application."""

file modified
+4 -3
@@ -36,7 +36,8 @@ 

  

  from datetime import timedelta, datetime

  

- from fedora_messaging import api, testing

+ import fedocal_messages.messages as schema

+ from fedora_messaging import testing

  from mock import ANY, patch

  

  sys.path.insert(0, os.path.join(os.path.dirname(
@@ -180,7 +181,7 @@ 

          self.session.commit()

          self.assertNotEqual(obj, None)

  

-         with testing.mock_sends(api.Message(

+         with testing.mock_sends(schema.ReminderV1(

                  topic="fedocal.reminder",

                  body={

                      'meeting': {
@@ -244,7 +245,7 @@ 

          self.session.commit()

          self.assertNotEqual(obj, None)

  

-         with testing.mock_sends(api.Message(

+         with testing.mock_sends(schema.ReminderV1(

                  topic="fedocal.reminder",

                  body={

                      'meeting': {

file modified
+313 -169
@@ -42,13 +42,17 @@ 

  import flask

  import six

  

+ import fedocal_messages.messages as schema

+ from fedora_messaging import testing

+ from mock import ANY, patch

+ 

  sys.path.insert(0, os.path.join(os.path.dirname(

      os.path.abspath(__file__)), '..'))

  

  import fedocal

  import fedocal.fedocallib as fedocallib

  import fedocal.fedocallib.model as model

- from tests import (Modeltests, FakeUser, flask10_only, user_set, TODAY,

+ from tests import (Modeltests, FakeUser, user_set, TODAY,

                     ICS_FILE, ICS_FILE_NOTOK)

  

  
@@ -841,16 +845,13 @@ 

              self.assertFalse(

                  fedocal.is_safe_url('https://fedoraproject.org/'))

  

-     @flask10_only

      def test_auth_login(self):

          """ Test the auth_login function. """

          self.__setup_db()

          user = FakeUser([], username='pingou')

          with user_set(fedocal.APP, user):

-             output = self.app.get('/login/', follow_redirects=True)

-             self.assertEqual(output.status_code, 200)

-             output_text = output.get_data(as_text=True)

-             self.assertIn('<title>Home - Fedocal</title>', output_text)

+             output = self.app.get('/login/')

+             self.assertEqual(output.status_code, 302)

  

      def test_locations(self):

          """ Test the locations function. """
@@ -905,7 +906,6 @@ 

              'class="errors">No location named foobar could be found</',

              output_text)

  

-     @flask10_only

      def test_admin(self):

          """ Test the admin function. """

          user = None
@@ -973,18 +973,12 @@ 

              self.assertIn(

                  'value="Delete">', output_text)

  

-     @flask10_only

      def test_add_calendar(self):

          """ Test the add_calendar function. """

          user = None

          with user_set(fedocal.APP, user):

-             output = self.app.get('/calendar/add/', follow_redirects=True)

-             self.assertEqual(output.status_code, 200)

-             output_text = output.get_data(as_text=True)

-             # discoveryfailure happens if there is no network

-             self.assertTrue(

-                 '<title>OpenID transaction in progress</title>'

-                 in output_text or 'discoveryfailure' in output_text)

+             output = self.app.get('/calendar/add/')

+             self.assertEqual(output.status_code, 302)

  

          user = FakeUser(['test'])

          with user_set(fedocal.APP, user):
@@ -1034,12 +1028,26 @@ 

                  'csrf_token': csrf_token,

              }

  

-             output = self.app.post('/calendar/add/', data=data,

-                                    follow_redirects=True)

-             self.assertEqual(output.status_code, 200)

-             output_text = output.get_data(as_text=True)

-             self.assertIn(

-                 '<li class="message">Calendar added</li>', output_text)

+             with testing.mock_sends(schema.CalendarNewV1(

+                     topic="fedocal.calendar.new",

+                     body={

+                         'agent': 'username',

+                         'calendar': {

+                             'calendar_name': 'election1',

+                             'calendar_contact': 'election1',

+                             'calendar_description': '',

+                             'calendar_editor_group': '',

+                             'calendar_admin_group': '',

+                             'calendar_status': 'Enabled'

+                         }

+                     }

+                 )):

+                 output = self.app.post('/calendar/add/', data=data,

+                                        follow_redirects=True)

+                 self.assertEqual(output.status_code, 200)

+                 output_text = output.get_data(as_text=True)

+                 self.assertIn(

+                     '<li class="message">Calendar added</li>', output_text)

  

              # This calendar already exists

              data = {
@@ -1057,7 +1065,6 @@ 

                  '="errors">Could not add this calendar to the database</',

                  output_text)

  

-     @flask10_only

      def test_delete_calendar(self):

          """ Test the delete_calendar function. """

          self.__setup_db()
@@ -1135,20 +1142,33 @@ 

                  'csrf_token': csrf_token,

              }

  

-             output = self.app.post('/calendar/delete/test_calendar/',

-                                    data=data, follow_redirects=True)

-             self.assertEqual(output.status_code, 200)

-             output_text = output.get_data(as_text=True)

-             self.assertIn(

-                 '<title>Home - Fedocal</title>', output_text)

-             self.assertIn(

-                 '<li class="message">Calendar deleted</li>',

-                 output_text)

-             self.assertNotIn(

-                 '<span class="calendar_name">test_calendar</span>',

-                 output_text)

+             with testing.mock_sends(schema.CalendarDeleteV1(

+                     topic="fedocal.calendar.delete",

+                     body={

+                         'agent': 'kevin',

+                         'calendar': {

+                             'calendar_name': 'test_calendar',

+                             'calendar_contact': 'test@example.com',

+                             'calendar_description': 'This is a test calendar',

+                             'calendar_editor_group': 'fi-apprentice',

+                             'calendar_admin_group': 'infrastructure-main2',

+                             'calendar_status': 'Enabled'

+                         }

+                     }

+                 )):

+                 output = self.app.post('/calendar/delete/test_calendar/',

+                                        data=data, follow_redirects=True)

+                 self.assertEqual(output.status_code, 200)

+                 output_text = output.get_data(as_text=True)

+                 self.assertIn(

+                     '<title>Home - Fedocal</title>', output_text)

+                 self.assertIn(

+                     '<li class="message">Calendar deleted</li>',

+                     output_text)

+                 self.assertNotIn(

+                     '<span class="calendar_name">test_calendar</span>',

+                     output_text)

  

-     @flask10_only

      def test_clear_calendar(self):

          """ Test the clear_calendar function. """

          self.__setup_db()
@@ -1220,28 +1240,41 @@ 

              output_text = output.get_data(as_text=True)

              self.assertIn(

                  '<title>test_calendar - Fedocal</title>', output_text)

-             self.assertIn(

-                 '<title>test_calendar - Fedocal</title>', output_text)

+             self.assertNotIn(

+                 '<li class="message">Calendar cleared</li>', output_text)

  

              # Delete

              data = {

+                 # html booleans are: arg missing = False, arg present = True

+                 # regardless of the value of the arg passed

                  'confirm_delete': False,

                  'csrf_token': csrf_token,

              }

  

-             output = self.app.post('/calendar/clear/test_calendar/',

-                                    data=data, follow_redirects=True)

-             self.assertEqual(output.status_code, 200)

-             output_text = output.get_data(as_text=True)

-             self.assertIn(

-                 '<title>test_calendar - Fedocal</title>', output_text)

-             self.assertIn(

-                 '<title>test_calendar - Fedocal</title>', output_text)

-             self.assertIn(

-                 '<li class="message">Calendar cleared</li>',

-                 output_text)

+             with testing.mock_sends(schema.CalendarClearV1(

+                     topic="fedocal.calendar.clear",

+                     body={

+                         'agent': 'kevin',

+                         'calendar': {

+                             'calendar_name': 'test_calendar',

+                             'calendar_contact': 'test@example.com',

+                             'calendar_description': 'This is a test calendar',

+                             'calendar_editor_group': 'fi-apprentice',

+                             'calendar_admin_group': 'infrastructure-main2',

+                             'calendar_status': 'Enabled'

+                         }

+                     }

+                 )):

+                 output = self.app.post('/calendar/clear/test_calendar/',

+                                        data=data, follow_redirects=True)

+                 self.assertEqual(output.status_code, 200)

+                 output_text = output.get_data(as_text=True)

+                 self.assertIn(

+                     '<title>test_calendar - Fedocal</title>', output_text)

+                 self.assertIn(

+                     '<li class="message">Calendar cleared</li>',

+                     output_text)

  

-     @flask10_only

      def test_edit_calendar(self):

          """ Test the edit_calendar function. """

          self.__setup_db()
@@ -1307,7 +1340,7 @@ 

              self.assertEqual(output.status_code, 200)

              output_text = output.get_data(as_text=True)

              self.assertEqual(

-                 output_text.count('<td>This field is required.</td>'), 2)

+                 output_text.count('<td>This field is required.</td>'), 3)

              self.assertIn(

                  '<h2>Edit calendar "test_calendar"</h2>',

                  output_text)
@@ -1323,23 +1356,36 @@ 

                  'csrf_token': csrf_token,

              }

  

-             output = self.app.post('/calendar/edit/test_calendar/',

-                                    data=data, follow_redirects=True)

-             self.assertEqual(output.status_code, 200)

-             output_text = output.get_data(as_text=True)

-             self.assertIn(

-                 '<title>Election1 - Fedocal</title>', output_text)

-             self.assertIn(

-                 '<li class="message">Calendar updated</li>',

-                 output_text)

-             self.assertNotIn(

-                 '<span class="calendar_name">test_calendar</span>',

-                 output_text)

-             self.assertNotIn(

-                 '<span class="calendar_name">election1</span>',

-                 output_text)

+             with testing.mock_sends(schema.CalendarUpdateV1(

+                     topic="fedocal.calendar.update",

+                     body={

+                         'agent': 'kevin',

+                         'calendar': {

+                             'calendar_name': 'Election1',

+                             'calendar_contact': 'election1',

+                             'calendar_description': '',

+                             'calendar_editor_group': '',

+                             'calendar_admin_group': '',

+                             'calendar_status': 'Enabled'

+                         }

+                     }

+                 )):

+                 output = self.app.post('/calendar/edit/test_calendar/',

+                                        data=data, follow_redirects=True)

+                 self.assertEqual(output.status_code, 200)

+                 output_text = output.get_data(as_text=True)

+                 self.assertIn(

+                     '<title>Election1 - Fedocal</title>', output_text)

+                 self.assertIn(

+                     '<li class="message">Calendar updated</li>',

+                     output_text)

+                 self.assertNotIn(

+                     '<span class="calendar_name">test_calendar</span>',

+                     output_text)

+                 self.assertNotIn(

+                     '<span class="calendar_name">election1</span>',

+                     output_text)

  

-     @flask10_only

      def test_auth_logout(self):

          """ Test the auth_logout function. """

          user = FakeUser(fedocal.APP.config['ADMIN_GROUP'])
@@ -1362,7 +1408,6 @@ 

                  '<li class="message">You have been logged out</li>',

                  output_text)

  

-     @flask10_only

      def test_my_meetings(self):

          """ Test the my_meetings function. """

          self.__setup_db()
@@ -1397,7 +1442,6 @@ 

              self.assertIn(

                  '<td> Test meeting with reminder </td>', output_text)

  

-     @flask10_only

      def test_add_meeting(self):

          """ Test the add_meeting function. """

          self.__setup_db()
@@ -1550,16 +1594,43 @@ 

                  'csrf_token': csrf_token,

              }

  

-             output = self.app.post('/test_calendar/add/', data=data,

-                                    follow_redirects=True)

-             self.assertEqual(output.status_code, 200)

-             output_text = output.get_data(as_text=True)

-             self.assertIn(

-                 '<li class="message">Meeting added</li>', output_text)

-             self.assertIn(

-                 'href="/meeting/16/?from_date=', output_text)

-             self.assertNotIn(

-                 'href="/meeting/17/?from_date=', output_text)

+             with testing.mock_sends(schema.MeetingNewV1(

+                     topic="fedocal.meeting.new",

+                     body={

+                         'agent': 'pingou',

+                         'meeting': {

+                             'meeting_id': 16,

+                             'meeting_name': 'guess what?',

+                             'meeting_manager': ['pingou'],

+                             'meeting_date': TODAY.strftime('%Y-%m-%d'),

+                             'meeting_date_end': TODAY.strftime('%Y-%m-%d'),

+                             'meeting_time_start': '13:00:00',

+                             'meeting_time_stop': '14:00:00',

+                             'meeting_timezone': 'Europe/Paris',

+                             'meeting_information': '',

+                             'meeting_location': '',

+                             'calendar_name': 'test_calendar'

+                         },

+                         'calendar': {

+                             'calendar_name': 'test_calendar',

+                             'calendar_contact': 'test@example.com',

+                             'calendar_description': 'This is a test calendar',

+                             'calendar_editor_group': 'fi-apprentice',

+                             'calendar_admin_group': 'infrastructure-main2',

+                             'calendar_status': 'Enabled'

+                         }

+                     }

+                 )):

+                 output = self.app.post('/test_calendar/add/', data=data,

+                                        follow_redirects=True)

+                 self.assertEqual(output.status_code, 200)

+                 output_text = output.get_data(as_text=True)

+                 self.assertIn(

+                     '<li class="message">Meeting added</li>', output_text)

+                 self.assertIn(

+                     'href="/meeting/16/?from_date=', output_text)

+                 self.assertNotIn(

+                     'href="/meeting/17/?from_date=', output_text)

  

              # Works - with a wiki_link

              data = {
@@ -1573,16 +1644,17 @@ 

                  'csrf_token': csrf_token,

              }

  

-             output = self.app.post('/test_calendar/add/', data=data,

-                                    follow_redirects=True)

-             self.assertEqual(output.status_code, 200)

-             output_text = output.get_data(as_text=True)

-             self.assertIn(

-                 '<li class="message">Meeting added</li>', output_text)

-             self.assertIn(

-                 'href="/meeting/17/?from_date=', output_text)

-             self.assertNotIn(

-                 'href="/meeting/18/?from_date=', output_text)

+             with testing.mock_sends(schema.MeetingNewV1):

+                 output = self.app.post('/test_calendar/add/', data=data,

+                                        follow_redirects=True)

+                 self.assertEqual(output.status_code, 200)

+                 output_text = output.get_data(as_text=True)

+                 self.assertIn(

+                     '<li class="message">Meeting added</li>', output_text)

+                 self.assertIn(

+                     'href="/meeting/17/?from_date=', output_text)

+                 self.assertNotIn(

+                     'href="/meeting/18/?from_date=', output_text)

  

              # Calendar disabled

              data = {
@@ -1615,8 +1687,8 @@ 

                  'meeting_time_stop': time(14, 0),

                  'meeting_timezone': 'Europe/Paris',

                  'frequency': '',

-                 'reminder_from': 'pingou@fp.o',

-                 'reminder_who': 'pingou@fp.org',

+                 'reminder_from': 'pingou@fp',

+                 'remind_who': 'pingou@fp.org',

                  'remind_when': 'H-12',

                  'csrf_token': csrf_token,

              }
@@ -1640,7 +1712,7 @@ 

                  'meeting_timezone': 'Europe/Paris',

                  'frequency': '',

                  'reminder_from': 'pingou@fp.o',

-                 'reminder_who': 'pingou@fp.org, pingou@fp.o',

+                 'remind_who': 'pingou@fp.org, pingou@fp',

                  'remind_when': 'H-12',

                  'csrf_token': csrf_token,

              }
@@ -1652,7 +1724,8 @@ 

              self.assertIn(

                  '<h2>New meeting</h2>', output_text)

              self.assertIn(

-                 '<td>Invalid email address.</td>', output_text)

+                 '<td>The domain name fp is not valid. It should have a period.</td>',

+                 output_text)

  

              # Works - with one email as recipient of the reminder

              data = {
@@ -1663,25 +1736,26 @@ 

                  'meeting_timezone': 'Europe/Paris',

                  'frequency': '',

                  'reminder_from': 'pingou@fp.org',

-                 'reminder_who': 'pingou@fp.org',

+                 'remind_who': 'pingou@fp.org',

                  'remind_when': 'H-12',

                  'csrf_token': csrf_token,

              }

  

-             output = self.app.post('/test_calendar/add/', data=data,

-                                    follow_redirects=True)

-             self.assertEqual(output.status_code, 200)

-             output_text = output.get_data(as_text=True)

-             self.assertIn(

-                 '<li class="message">Meeting added</li>', output_text)

-             self.assertIn(

-                 'href="/meeting/17/?from_date=', output_text)

-             self.assertIn(

-                 'href="/meeting/18/?from_date=', output_text)

-             self.assertIn(

-                 'Reminder', output_text)

-             self.assertNotIn(

-                 'href="/meeting/19/?from_date=', output_text)

+             with testing.mock_sends(schema.MeetingNewV1):

+                 output = self.app.post('/test_calendar/add/', data=data,

+                                        follow_redirects=True)

+                 self.assertEqual(output.status_code, 200)

+                 output_text = output.get_data(as_text=True)

+                 self.assertIn(

+                     '<li class="message">Meeting added</li>', output_text)

+                 self.assertIn(

+                     'href="/meeting/17/?from_date=', output_text)

+                 self.assertIn(

+                     'href="/meeting/18/?from_date=', output_text)

+                 self.assertIn(

+                     'Reminder', output_text)

+                 self.assertNotIn(

+                     'href="/meeting/19/?from_date=', output_text)

  

              # Works - with two emails as recipient of the reminder

              data = {
@@ -1692,27 +1766,27 @@ 

                  'meeting_timezone': 'Europe/Paris',

                  'frequency': '',

                  'reminder_from': 'pingou@fp.org',

-                 'reminder_who': 'pingou@fp.org,pingou@p.fr',

+                 'remind_who': 'pingou@fp.org,pingou@p.fr',

                  'remind_when': 'H-12',

                  'csrf_token': csrf_token,

              }

  

-             output = self.app.post('/test_calendar/add/', data=data,

-                                    follow_redirects=True)

-             self.assertEqual(output.status_code, 200)

-             output_text = output.get_data(as_text=True)

-             self.assertIn(

-                 '<li class="message">Meeting added</li>', output_text)

-             self.assertIn(

-                 'href="/meeting/18/?from_date=', output_text)

-             self.assertIn(

-                 'href="/meeting/19/?from_date=', output_text)

-             self.assertIn(

-                 'Reminder2', output_text)

-             self.assertNotIn(

-                 'href="/meeting/20/?from_date=', output_text)

+             with testing.mock_sends(schema.MeetingNewV1):

+                 output = self.app.post('/test_calendar/add/', data=data,

+                                        follow_redirects=True)

+                 self.assertEqual(output.status_code, 200)

+                 output_text = output.get_data(as_text=True)

+                 self.assertIn(

+                     '<li class="message">Meeting added</li>', output_text)

+                 self.assertIn(

+                     'href="/meeting/18/?from_date=', output_text)

+                 self.assertIn(

+                     'href="/meeting/19/?from_date=', output_text)

+                 self.assertIn(

+                     'Reminder2', output_text)

+                 self.assertNotIn(

+                     'href="/meeting/20/?from_date=', output_text)

  

-     @flask10_only

      def test_edit_meeting(self):

          """ Test the edit_meeting function. """

          self.__setup_db()
@@ -1801,7 +1875,7 @@ 

              self.assertEqual(output.status_code, 200)

              output_text = output.get_data(as_text=True)

              self.assertIn(

-                 '<td>Not a valid choice</td>', output_text)

+                 '<td>This field is required.</td>', output_text)

              self.assertIn(

                  '<title>Edit meeting - Fedocal</title>', output_text)

  
@@ -1840,14 +1914,41 @@ 

                  'csrf_token': csrf_token,

              }

  

-             output = self.app.post('/meeting/edit/1/', data=data,

-                                    follow_redirects=True)

-             self.assertEqual(output.status_code, 200)

-             output_text = output.get_data(as_text=True)

-             self.assertIn(

-                 '<li class="message">Meeting updated</li>', output_text)

-             self.assertIn(

-                 '<title>Meeting "guess what?" - Fedocal</title>', output_text)

+             with testing.mock_sends(schema.MeetingUpdateV1(

+                     topic="fedocal.meeting.update",

+                     body={

+                         'agent': 'pingou',

+                         'meeting': {

+                         'meeting_id': 1,

+                             'meeting_name': 'guess what?',

+                             'meeting_manager': ['pingou'],

+                             'meeting_date': TODAY.strftime('%Y-%m-%d'),

+                             'meeting_date_end': TODAY.strftime('%Y-%m-%d'),

+                             'meeting_time_start': '13:00:00',

+                             'meeting_time_stop': '14:00:00',

+                             'meeting_timezone': 'Europe/Paris',

+                             'meeting_information': '',

+                             'meeting_location': None,

+                             'calendar_name': 'test_calendar'

+                         },

+                         'calendar': {

+                             'calendar_name': 'test_calendar',

+                             'calendar_contact': 'test@example.com',

+                             'calendar_description': 'This is a test calendar',

+                             'calendar_editor_group': 'fi-apprentice',

+                             'calendar_admin_group': 'infrastructure-main2',

+                             'calendar_status': 'Enabled'

+                         }

+                     }

+                 )):

+                 output = self.app.post('/meeting/edit/1/', data=data,

+                                        follow_redirects=True)

+                 self.assertEqual(output.status_code, 200)

+                 output_text = output.get_data(as_text=True)

+                 self.assertIn(

+                     '<li class="message">Meeting updated</li>', output_text)

+                 self.assertIn(

+                     '<title>Meeting "guess what?" - Fedocal</title>', output_text)

  

              # Calendar disabled

              data = {
@@ -1883,6 +1984,8 @@ 

              meeting_information='Full day meeting 2',

              calendar_name='test_calendar_disabled',

              full_day=True)

+         self.session.add(obj)

+         self.session.flush()

          obj.add_manager(self.session, ['toshio'])

          obj.save(self.session)

          self.session.commit()
@@ -1950,7 +2053,6 @@ 

              self.assertEqual(

                  output_text.count('<span class="required">*</span>'), 6)

  

-     @flask10_only

      def test_delete_meeting(self):

          """ Test the delete_meeting function. """

          self.__setup_db()
@@ -2047,14 +2149,41 @@ 

                  'csrf_token': csrf_token,

              }

  

-             output = self.app.post('/meeting/delete/1/', data=data,

-                                    follow_redirects=True)

-             self.assertEqual(output.status_code, 200)

-             output_text = output.get_data(as_text=True)

-             self.assertIn(

-                 '<title>test_calendar - Fedocal</title>', output_text)

-             self.assertIn(

-                 '<li class="message">Meeting deleted</li>', output_text)

+             with testing.mock_sends(schema.MeetingDeleteV1(

+                     topic="fedocal.meeting.delete",

+                     body={

+                         'agent': 'pingou',

+                         'meeting': {

+                             'meeting_id': 1,

+                             'meeting_name': 'Fedora-fr-test-meeting',

+                             'meeting_manager': [],

+                             'meeting_date': TODAY.strftime('%Y-%m-%d'),

+                             'meeting_date_end': TODAY.strftime('%Y-%m-%d'),

+                             'meeting_time_start': '19:50:00',

+                             'meeting_time_stop': '20:50:00',

+                             'meeting_timezone': 'UTC',

+                             'meeting_information': 'This is a test meeting',

+                             'meeting_location': None,

+                             'calendar_name': 'test_calendar'

+                         },

+                         'calendar': {

+                             'calendar_name': 'test_calendar',

+                             'calendar_contact': 'test@example.com',

+                             'calendar_description': 'This is a test calendar',

+                             'calendar_editor_group': 'fi-apprentice',

+                             'calendar_admin_group': 'infrastructure-main2',

+                             'calendar_status': 'Enabled'

+                         }

+                     }

+                 )):

+                 output = self.app.post('/meeting/delete/1/', data=data,

+                                        follow_redirects=True)

+                 self.assertEqual(output.status_code, 200)

+                 output_text = output.get_data(as_text=True)

+                 self.assertIn(

+                     '<title>test_calendar - Fedocal</title>', output_text)

+                 self.assertIn(

+                     '<li class="message">Meeting deleted</li>', output_text)

  

              # Delete all

              data = {
@@ -2063,14 +2192,15 @@ 

                  'csrf_token': csrf_token,

              }

  

-             output = self.app.post('/meeting/delete/8/', data=data,

-                                    follow_redirects=True)

-             self.assertEqual(output.status_code, 200)

-             output_text = output.get_data(as_text=True)

-             self.assertIn(

-                 '<title>test_calendar - Fedocal</title>', output_text)

-             self.assertIn(

-                 '<li class="message">Meeting deleted</li>', output_text)

+             with testing.mock_sends(schema.MeetingDeleteV1):

+                 output = self.app.post('/meeting/delete/8/', data=data,

+                                        follow_redirects=True)

+                 self.assertEqual(output.status_code, 200)

+                 output_text = output.get_data(as_text=True)

+                 self.assertIn(

+                     '<title>test_calendar - Fedocal</title>', output_text)

+                 self.assertIn(

+                     '<li class="message">Meeting deleted</li>', output_text)

  

          # Add a meeting to the test_calendar_disabled calendar

          obj = model.Meeting(  # id:16
@@ -2082,6 +2212,8 @@ 

              meeting_information='Full day meeting 2',

              calendar_name='test_calendar_disabled',

              full_day=True)

+         self.session.add(obj)

+         self.session.flush()

          obj.add_manager(self.session, ['toshio'])

          obj.save(self.session)

          self.session.commit()
@@ -2289,7 +2421,6 @@ 

          self.assertIn(

              '<p>This is a test calendar</p>', output_text)

  

-     @flask10_only

      def test_upload_calendar(self):

          """ Test the upload_calendar function. """

          self.__setup_db()
@@ -2334,24 +2465,38 @@ 

                      'enctype': 'multipart/form-data',

                      'csrf_token': csrf_token,

                  }

-                 output = self.app.post('/calendar/upload/test_calendar/',

-                                        follow_redirects=True, data=data)

-                 self.assertEqual(output.status_code, 200)

-                 output_text = output.get_data(as_text=True)

-                 if '<li class="error">' not in output_text:

-                     self.assertIn(

-                         '<title>test_calendar - Fedocal</title>',

-                         output_text)

-                     self.assertIn(

-                         '<p>This is a test calendar</p>', output_text)

-                     self.assertIn(

-                         'li class="message">Calendar uploaded</li>',

-                         output_text)

-                 else:

-                     self.assertIn(

-                         '<li class="error">The submitted candidate has the '

-                         'MIME type &#34;application/octet-stream&#34; which '

-                         'is not an allowed MIME type</li>', output_text)

+                 with testing.mock_sends(schema.CalendarUploadV1(

+                         topic="fedocal.calendar.upload",

+                         body={

+                             'agent': 'kevin',

+                             'calendar': {

+                                 'calendar_name': 'test_calendar',

+                                 'calendar_contact': 'test@example.com',

+                                 'calendar_description': 'This is a test calendar',

+                                 'calendar_editor_group': 'fi-apprentice',

+                                 'calendar_admin_group': 'infrastructure-main2',

+                                 'calendar_status': 'Enabled'

+                             }

+                         }

+                     )):

+                     output = self.app.post('/calendar/upload/test_calendar/',

+                                            follow_redirects=True, data=data)

+                     self.assertEqual(output.status_code, 200)

+                     output_text = output.get_data(as_text=True)

+                     if '<li class="error">' not in output_text:

+                         self.assertIn(

+                             '<title>test_calendar - Fedocal</title>',

+                             output_text)

+                         self.assertIn(

+                             '<p>This is a test calendar</p>', output_text)

+                         self.assertIn(

+                             'li class="message">Calendar uploaded</li>',

+                             output_text)

+                     else:

+                         self.assertIn(

+                             '<li class="error">The submitted candidate has the '

+                             'MIME type &#34;application/octet-stream&#34; which '

+                             'is not an allowed MIME type</li>', output_text)

  

              with open(ICS_FILE_NOTOK, 'rb') as stream:

                  data = {
@@ -2371,7 +2516,6 @@ 

                      'extension &#34;txt&#34; which is not an allowed '

                      'format</li>', output_text)

  

-     @flask10_only

      def test_markdown_preview(self):

          """ Test the markdown_preview function. """

          user = FakeUser(['gitr2spec'], username='kevin')

file modified
+11 -10
@@ -45,7 +45,7 @@ 

  import fedocal

  import fedocal.fedocallib as fedocallib

  import fedocal.fedocallib.model as model

- from tests import (Modeltests, FakeUser, flask10_only, user_set, TODAY)

+ from tests import (Modeltests, FakeUser, user_set, TODAY)

  

  

  # pylint: disable=E1103
@@ -75,7 +75,6 @@ 

          fedocal.SESSION = self.session

          self.app = fedocal.APP.test_client()

  

-     @flask10_only

      def test_start_date_edit_meeting_form(self):

          """ Test the content of the start_date in the edit meeting form.

          """
@@ -93,6 +92,8 @@ 

              calendar_name='test_calendar',

              recursion_frequency=14,

              recursion_ends=TODAY + timedelta(days=90))

+         self.session.add(obj)

+         self.session.flush()

          obj.add_manager(self.session, 'pingou,')

          obj.save(self.session)

          self.session.commit()
@@ -110,7 +111,7 @@ 

  

              # If no date is specified, it returns the next occurence

              self.assertIn(

-                 '<input id="meeting_date" name="meeting_date" type="text" '

+                 '<input id="meeting_date" name="meeting_date" required type="text" '

                  'value="%s">' % (next_date), output_text

              )

  
@@ -123,9 +124,8 @@ 

              output2_text = output2.get_data(as_text=True)

  

              self.assertIn(

-                 '<input id="meeting_date" name="meeting_date" type="text" '

-                 'value="%s">' % (TODAY + timedelta(days=28)),

-                 output2_text

+                 '<input id="meeting_date" name="meeting_date" required type="text" '

+                 'value="%s">' % (TODAY + timedelta(days=28)), output2_text

              )

  

              # If an exact date in the future is specified, return that date
@@ -136,7 +136,7 @@ 

              output2_text = output2.get_data(as_text=True)

  

              self.assertIn(

-                 '<input id="meeting_date" name="meeting_date" type="text" '

+                 '<input id="meeting_date" name="meeting_date" required type="text" '

                  'value="%s">' % (TODAY + timedelta(days=14)), output2_text

              )

  
@@ -146,11 +146,10 @@ 

              output2_text = output2.get_data(as_text=True)

  

              self.assertIn(

-                 '<input id="meeting_date" name="meeting_date" type="text" '

+                 '<input id="meeting_date" name="meeting_date" required type="text" '

                  'value="%s">' % (TODAY), output2_text

              )

  

-     @flask10_only

      def test_start_date_delete_meeting_form(self):

          """ Test the content of the start_date in the delete meeting form.

          """
@@ -168,6 +167,8 @@ 

              calendar_name='test_calendar',

              recursion_frequency=14,

              recursion_ends=TODAY + timedelta(days=90))

+         self.session.add(obj)

+         self.session.flush()

          obj.add_manager(self.session, 'pingou,')

          obj.save(self.session)

          self.session.commit()
@@ -206,7 +207,7 @@ 

              self.assertEqual(output2.status_code, 200)

              output_text = output2.get_data(as_text=True)

  

-             self.assertIn('<li>Date: %s</li>' % next_date, output_text)

+             self.assertIn('<li>Date: %s</li>' % (TODAY + timedelta(days=14)), output_text)

  

              # If an old date in the future is specified, return the first date

              output2 = self.app.get('/meeting/delete/1/?from_date=2000-01-01')

no initial comment

1 new commit added

  • Simplify how dicts are turned into fedora-messaging messages
5 months ago

pretty please pagure-ci rebuild

a month ago

4 new commits added

  • Simplify how dicts are turned into fedora-messaging messages
  • Make fedocal rely on fedocal-messages to check the structure of the messages sent
  • Drop the flask10_only decorator and fix/adjust the tests
  • Port the multi-email validator to email_validator
a month ago

5 new commits added

  • Only send a notification on the bus when a calendar has been cleared
  • Simplify how dicts are turned into fedora-messaging messages
  • Make fedocal rely on fedocal-messages to check the structure of the messages sent
  • Drop the flask10_only decorator and fix/adjust the tests
  • Port the multi-email validator to email_validator
a month ago

Tests work locally, I like the simplifications of removing flask10_only decorator and using fedora_messages for validation, good to merge.

Thanks for the review (and catching all the issues you found!)

Pull-Request has been merged by pingou

a month ago