How to use notify_subscribers method in localstack

Best Python code snippet using localstack_python

MoodMovieModel.py

Source:MoodMovieModel.py Github

copy

Full Screen

...6 def subscribe(self, observer):7 self.subscribers.append(observer)8 def unsubscribe(self, movie):9 self.subscribers.remove(movie)10 def notify_subscribers(self, msg):11 for i in self.subscribers:12 i.update(msg)13 def get_movie_from_api(self, ids_genres):14 return self.facade.get_movie_from_api(ids_genres)15 def get_movie_from_bookmarks(self, id):16 return self.facade.get_movie_from_bd(id)17 def add_to_bookmarks(self, movie):18 try:19 self.facade.add_to_db(movie)20 msg = self.create_msg('COUNT ALL BOOKMARKS: {} \n'.format(len(self.get_all_movies_from_bookmarks())), '', 'THE MOVIE BY TITLE {} HAS BEEN ADDED TO BOOKMARKS'.format(movie['title']))21 self.notify_subscribers(msg)22 except:23 msg = self.create_msg(movie['title'], 'FAIL')24 self.notify_subscribers(msg)25 def clear_all_bookmarks(self):26 try:27 self.facade.clear_db()28 count_bookmarks = len(self.get_all_movies_from_bookmarks())29 if count_bookmarks == 0:30 msg = self.create_msg('','','ALL BOOKMARKS WAS DELETED')31 self.notify_subscribers(msg)32 else:33 return SyntaxError34 except:35 msg = self.create_msg('ERROR WHILE CLEAR DB', 'FAIL')36 self.notify_subscribers(msg)37 def add_mark_scratch(self, movie, mark):38 try:39 self.facade.add_mark_scratch(movie, mark)40 msg = self.create_msg('','', 'THE MOVIE BY ID: {} HAS BEEN ADD TO BOOKMARKS WITH MARK: {}'.format(len(self.get_all_movies_from_bookmarks()) -1 , mark))41 self.notify_subscribers(msg)42 except:43 msg = self.create_msg('ERROR WHILE ADDING MARKS',self.facade.add_mark_scratch(movie, mark),'')44 self.notify_subscribers(msg)45 def add_mark_db(self, id, mark):46 try:47 response = self.facade.add_mark_db(id, mark)48 print(response)49 if response:50 msg = self.create_msg('', '', 'THE MARK {} TO MOVIE WITH ID: {} HAS BEEN ADDED'.format(mark, id))51 self.notify_subscribers(msg)52 else:53 msg = self.create_msg('ERROR WHILE ADDING MARK', '1', '')54 self.notify_subscribers(msg)55 except Exception:56 msg = self.create_msg('ERROR WHILE ADDING MARK','2', '')57 self.notify_subscribers(msg)58 def has_bookmark(self, movie_id_api):59 return self.facade.has_bookmark(movie_id_api)60 def has_marks(self, movie_id_api):61 return self.facade.has_mark(movie_id_api)62 def get_all_movies_from_bookmarks(self):63 return self.facade.get_all_movies_from_bookmarks()64 def delete_bookmark(self, id):65 msg = self.facade.delete_bookmark(id)66 if msg:67 msg = self.create_msg('','','THE MOVIE WITH ID: {} WAS DELETED'.format(id))68 else:69 msg = self.create_msg('DELETEING STATUS', 'ERROR', '')70 self.notify_subscribers(msg)71 def create_msg(self, header, status, repr = None):72 return {73 'header': header,74 'status': status,75 'repr': repr...

Full Screen

Full Screen

models.py

Source:models.py Github

copy

Full Screen

...7 for subscriber in args:8 self._subscribers.append(subscriber)9 def unsubscribe(self, subscriber):10 self._subscribers.remove(subscriber)11 def notify_subscribers(self):12 for subscriber in self._subscribers:13 subscriber.update(self)14 def create_item(self, name, quantity):15 self.items.append({'name': name, 'quantity': quantity})16 add_item = {'name': name, 'quantity': quantity}17 self.state = ['create', add_item]18 self.notify_subscribers()19 def read_items(self):20 self.state = ['read_items', [item for item in self.items]]21 self.notify_subscribers()22 def read_item(self, name):23 items = list(filter(lambda x: x['name'] == name, self.items))24 self.state = ['read_item', items[0]]25 self.notify_subscribers()26 def update_item(self, name, quantity):27 index_items = list(filter(lambda i_x: i_x[1]['name'] == name, enumerate(self.items)))28 i, item_to_update = index_items[0][0], index_items[0][1]29 self.items[i] = {'name': name, 'quantity': quantity}30 self.state = ['update', self.items[i]]31 self.notify_subscribers()32 def delete_item(self, name):33 index_items = list(filter(lambda i_x: i_x[1]['name'] == name, enumerate(self.items)))34 i, item_to_delete = index_items[0][0], index_items[0][1]35 self.state = ['delete', self.items[i]]36 del self.items[i]...

Full Screen

Full Screen

base_test.py

Source:base_test.py Github

copy

Full Screen

...5def test_subscriptions():6 svc = BaseService()7 client = mock.Mock()8 svc.subscribe('foo_event', client.on_foo)9 svc.notify_subscribers('foo_event', 1, 2, 3, value='hello')10 deliver_pending_notifications()11 client.on_foo.assert_called_once_with(1, 2, 3, value='hello')12 client.reset_mock()13 svc.notify_subscribers('bar_event')14 deliver_pending_notifications()15 assert not client.on_foo.called16def test_unsubscribe():17 svc = BaseService()18 client = mock.Mock()19 svc.subscribe('foo_event', client.on_foo)20 svc.notify_subscribers('foo_event')21 deliver_pending_notifications()22 client.on_foo.assert_called_once_with()23 client.reset_mock()24 svc.unsubscribe(client.on_foo)25 svc.notify_subscribers('foo_event')26 deliver_pending_notifications()27 assert not client.on_foo.called28def test_async_service():29 class MockService(AsyncService):30 def __init__(self):31 super(MockService, self).__init__(tick_interval=0.01)32 self.call_count = 033 def tick(self):34 super(MockService, self).tick()35 self.call_count += 136 svc = MockService()37 time.sleep(0.05)38 assert svc.call_count == 039 svc.start()...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run localstack automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful