@@ -1666,10 +1666,41 @@ def test_simplified_eap_export(self, mock_generate_url):
16661666 django_get_language (),
16671667 )
16681668
1669+ # Test Export Snapshot
1670+
1671+ # create a new snapshot
1672+ simplfied_eap_snapshot = self .simplified_eap .generate_snapshot ()
1673+ assert simplfied_eap_snapshot .version == 2 , "Snapshot version should be 2"
1674+
1675+ data = {
1676+ "export_type" : Export .ExportType .SIMPLIFIED_EAP ,
1677+ "export_id" : self .eap_registration .id ,
1678+ "version" : 2 ,
1679+ }
1680+
1681+ with self .capture_on_commit_callbacks (execute = True ):
1682+ response = self .client .post (self .url , data , format = "json" )
1683+ self .assert_201 (response )
1684+ self .assertIsNotNone (response .data ["id" ], response .data )
1685+
1686+ expected_url = (
1687+ f"{ settings .GO_WEB_INTERNAL_URL } /eap/{ self .eap_registration .id } /{ Export .ExportType .SIMPLIFIED_EAP } /export/?version=2"
1688+ )
1689+ self .assertEqual (response .data ["url" ], expected_url )
1690+
16691691 @mock .patch ("api.serializers.generate_url.delay" )
16701692 def test_full_eap_export (self , mock_generate_url ):
1671- self .full_eap = FullEAPFactory .create (
1672- eap_registration = self .eap_registration ,
1693+ eap_registration = EAPRegistrationFactory .create (
1694+ eap_type = EAPType .FULL_EAP ,
1695+ country = self .country ,
1696+ national_society = self .national_society ,
1697+ disaster_type = self .disaster_type ,
1698+ created_by = self .user ,
1699+ modified_by = self .user ,
1700+ )
1701+
1702+ FullEAPFactory .create (
1703+ eap_registration = eap_registration ,
16731704 created_by = self .user ,
16741705 modified_by = self .user ,
16751706 budget_file = EAPFileFactory ._create_file (
@@ -1679,7 +1710,7 @@ def test_full_eap_export(self, mock_generate_url):
16791710 )
16801711 data = {
16811712 "export_type" : Export .ExportType .FULL_EAP ,
1682- "export_id" : self . eap_registration .id ,
1713+ "export_id" : eap_registration .id ,
16831714 "is_pga" : False ,
16841715 }
16851716
@@ -1689,7 +1720,7 @@ def test_full_eap_export(self, mock_generate_url):
16891720 response = self .client .post (self .url , data , format = "json" )
16901721 self .assert_201 (response )
16911722 self .assertIsNotNone (response .data ["id" ], response .data )
1692- expected_url = f"{ settings .GO_WEB_INTERNAL_URL } /eap/{ self . eap_registration .id } /{ Export .ExportType .FULL_EAP } /export/"
1723+ expected_url = f"{ settings .GO_WEB_INTERNAL_URL } /eap/{ eap_registration .id } /{ Export .ExportType .FULL_EAP } /export/"
16931724 self .assertEqual (response .data ["url" ], expected_url )
16941725 self .assertEqual (response .data ["status" ], Export .ExportStatus .PENDING )
16951726
@@ -1703,6 +1734,56 @@ def test_full_eap_export(self, mock_generate_url):
17031734 django_get_language (),
17041735 )
17051736
1737+ @mock .patch ("api.serializers.generate_url.delay" )
1738+ def test_diff_export_eap (self , mock_generate_url ):
1739+ eap_registration = EAPRegistrationFactory .create (
1740+ eap_type = EAPType .SIMPLIFIED_EAP ,
1741+ country = self .country ,
1742+ national_society = self .national_society ,
1743+ disaster_type = self .disaster_type ,
1744+ created_by = self .user ,
1745+ modified_by = self .user ,
1746+ )
1747+
1748+ SimplifiedEAPFactory .create (
1749+ eap_registration = eap_registration ,
1750+ created_by = self .user ,
1751+ modified_by = self .user ,
1752+ budget_file = EAPFileFactory ._create_file (
1753+ created_by = self .user ,
1754+ modified_by = self .user ,
1755+ ),
1756+ )
1757+
1758+ self .authenticate (self .user )
1759+ data = {
1760+ "export_type" : Export .ExportType .SIMPLIFIED_EAP ,
1761+ "export_id" : eap_registration .id ,
1762+ "diff" : True ,
1763+ }
1764+
1765+ self .authenticate (self .user )
1766+
1767+ with self .capture_on_commit_callbacks (execute = True ):
1768+ response = self .client .post (self .url , data , format = "json" )
1769+ self .assert_201 (response )
1770+ self .assertIsNotNone (response .data ["id" ], response .data )
1771+
1772+ expected_url = (
1773+ f"{ settings .GO_WEB_INTERNAL_URL } /eap/{ eap_registration .id } /{ Export .ExportType .SIMPLIFIED_EAP } /export/?diff=true"
1774+ )
1775+ self .assertEqual (response .data ["url" ], expected_url )
1776+
1777+ self .assertEqual (mock_generate_url .called , True )
1778+ title = f"{ self .national_society .name } -{ self .disaster_type .name } "
1779+ mock_generate_url .assert_called_once_with (
1780+ expected_url ,
1781+ response .data ["id" ],
1782+ self .user .id ,
1783+ title ,
1784+ django_get_language (),
1785+ )
1786+
17061787
17071788class EAPFullTestCase (APITestCase ):
17081789 def setUp (self ):
0 commit comments