def post(self, request, *args, **kwargs): original_module_leader = self.get_object().module_leader response = super( AdminModuleUpdateView, self).post(request, *args, **kwargs) # check to see that the module leader may have changed. current_module_leader = self.object.module_leader if current_module_leader != original_module_leader: # create watcher objects for module leaders original_ml_watcher = WatcherWrapper(original_module_leader) current_ml_watcher = WatcherWrapper(current_module_leader) # update module status by removing or adding module original_ml_watcher.remove_module(self.object) current_ml_watcher.add_module(self.object) # push the notification to the new module leader push_notification( 'module_leader', module_code=self.object.module_code, module_leader=current_module_leader ) # publish changes to timeline publish_changes(self.object, request.user) return response
class TestTLEntryNotice(BaseTestNotification): """ Test case for the TLEntryNotice object """ def setUp(self): super(TestTLEntryNotice, self).setUp() self.notice = TLEntryNotice() # test timeline entry self.entry = TimelineEntry.objects.create( title="Changes to ", changes="Test Changes", status="Draft", entry_type="Draft", module_code=self.module.module_code, object_id=self.module.module_code, content_object=self.module, approved_by=self.module_leader) self.watcher = WatcherWrapper(self.user) self.watcher.add_module(self.module) def test_create_notification(self): """ Test the creation of the notification """ sample_data = {'entry': self.entry} # expected output expected_msg = self.notice.content_template.format( self.module.module_code) expected_link = reverse(self.notice.link_name, kwargs={'module_pk': self.module.module_code}) # create the notification self.notice.create(**sample_data) # get the notification notification = self.model.objects.filter(recipient=self.user) self.assertEquals(notification.count(), 1) notice = notification.first() self.assertFalse(notice.seen) self.assertEquals(notice.content, expected_msg) self.assertEquals(notice.link, expected_link) self.assertEquals(notice.recipient, self.user) def test_create_notification_invalid_params(self): """ Test exception is raised when invalid params are provided """ # test with explict None in kwarg sample_data = {'entry': None} with self.assertRaises(ValueError): self.notice.create(**sample_data) # test with no kwargs with self.assertRaises(ValueError): self.notice.create()
def get_success_url(self): # before sending success url, connect the user # to recieve notifiations obj = self.object publish_changes(obj, self.request.user) watcher = WatcherWrapper(obj.module_leader) # add the module created to thier list watcher.add_module(obj) # push notification to module leader push_notification( 'module_leader', module_code=obj.module_code, module_leader=obj.module_leader ) return reverse('all_modules')