def test_document_saved_signal(self): """ Tests that the document_saved signal is sent with arguments. """ handler = Mock() document_saved.connect(handler, sender='test') document_saved.send(sender='test', doc_obj=self.doc_obj) handler.assert_called_once_with(sender='test', signal=document_saved, doc_obj=self.doc_obj)
def test_save_data_sends_signal(self): """ Tests that the document_saved signal is sent when a document is saved. """ handler = Mock() mock_doc_obj = self.doc_obj mock_doc_id = '1' self.distillery.collection.insert = Mock(return_value=mock_doc_id) self.distillery._create_doc_obj = Mock(return_value=mock_doc_obj) document_saved.connect(handler, sender=Distillery) doc_id = self.distillery._save_and_send_signal(self.doc_obj) # Assert the signal was called only once with the args handler.assert_called_once_with(sender=Distillery, signal=document_saved, doc_obj=mock_doc_obj) self.assertEqual(mock_doc_id, doc_id)