60
60
from onadata .apps .logger .xform_instance_parser import XLSFormError
61
61
from onadata .apps .main .models import MetaData
62
62
from onadata .apps .messaging .constants import (
63
- FORM_UPDATED , XFORM , PROJECT , FORM_DELETED , FORM_CREATED
63
+ FORM_UPDATED , XFORM , PROJECT , FORM_DELETED , FORM_CREATED ,
64
+ FORM_RENAMED , FORM_ACTIVE
64
65
)
65
66
from onadata .apps .viewer .models import Export
66
67
from onadata .apps .viewer .models .export import ExportTypeError
@@ -1351,7 +1352,7 @@ def test_publish_xlsform(self, mock_send_message):
1351
1352
self .assertTrue (mock_send_message .called )
1352
1353
mock_send_message .assert_called_with (
1353
1354
instance_id = xform .id ,
1354
- target_id = xform .project . pk ,
1355
+ target_id = xform .pk ,
1355
1356
target_type = XFORM ,
1356
1357
user = request .user ,
1357
1358
message_verb = FORM_CREATED
@@ -1789,7 +1790,8 @@ def test_publish_invalid_xls_form_no_choices(self):
1789
1790
)
1790
1791
self .assertEqual (response .data .get ("text" ), error_msg )
1791
1792
1792
- def test_partial_update (self ):
1793
+ @patch ("onadata.apps.api.viewsets.xform_viewset.send_message" )
1794
+ def test_partial_update (self , mock_send_message ):
1793
1795
with HTTMock (enketo_mock ):
1794
1796
self ._publish_xls_form_to_project ()
1795
1797
view = XFormViewSet .as_view ({"patch" : "partial_update" })
@@ -1813,6 +1815,38 @@ def test_partial_update(self):
1813
1815
request = self .factory .patch ("/" , data = data , ** self .extra )
1814
1816
response = view (request , pk = self .xform .id )
1815
1817
self .assertEqual (response .status_code , 200 )
1818
+
1819
+ # send messages upon form update
1820
+ self .assertTrue (mock_send_message .called )
1821
+
1822
+ # check calls to send_message triggered by patch request
1823
+ mock_calls = mock_send_message .call_args_list
1824
+ args , kwargs = mock_calls [0 ]
1825
+ # test form rename message
1826
+ message_kwargs = {
1827
+ "instance_id" : self .xform .id ,
1828
+ "target_id" : self .xform .id ,
1829
+ "target_type" : XFORM ,
1830
+ "user" : self .xform .user ,
1831
+ "message_verb" : FORM_RENAMED ,
1832
+ "custom_message" : {
1833
+ "old_title" : "transportation_2011_07_25" ,
1834
+ "new_title" : "Hello & World!"
1835
+ }
1836
+ }
1837
+ self .assertEqual (kwargs , message_kwargs )
1838
+
1839
+ # test form status message
1840
+ args , kwargs = mock_calls [1 ]
1841
+ message_kwargs = {
1842
+ "instance_id" : self .xform .id ,
1843
+ "target_id" : self .xform .id ,
1844
+ "target_type" : XFORM ,
1845
+ "user" : self .xform .user ,
1846
+ "message_verb" : FORM_ACTIVE ,
1847
+ }
1848
+ self .assertEqual (kwargs , message_kwargs )
1849
+
1816
1850
xform_old_hash = self .xform .hash
1817
1851
self .xform .refresh_from_db ()
1818
1852
self .assertTrue (self .xform .downloadable )
0 commit comments