diff --git a/src/rockstor/storageadmin/fixtures/test_nfs.json b/src/rockstor/storageadmin/fixtures/test_nfs.json new file mode 100644 index 000000000..b22a642b5 --- /dev/null +++ b/src/rockstor/storageadmin/fixtures/test_nfs.json @@ -0,0 +1,112 @@ +[ +{ + "model": "storageadmin.pool", + "pk": 11, + "fields": { + "name": "rock-pool", + "uuid": "26e1fb5e-65fc-43e1-8054-60ccec189243", + "size": 10485760, + "raid": "single-dup", + "toc": "2024-11-06T16:05:29.817Z", + "compression": "no", + "mnt_options": null, + "role": null + } +}, +{ + "model": "storageadmin.share", + "pk": 21, + "fields": { + "pool": 11, + "qgroup": "0/463", + "pqgroup": "2015/3", + "name": "share-nfs", + "uuid": null, + "size": 1048576, + "owner": "root", + "group": "root", + "perms": "755", + "toc": "2024-11-06T16:05:29.894Z", + "subvol_name": "share-nfs", + "replica": false, + "compression_algo": "no", + "rusage": 16, + "eusage": 16, + "pqgroup_rusage": 16, + "pqgroup_eusage": 16 + } +}, +{ + "model": "storageadmin.share", + "pk": 22, + "fields": { + "pool": 11, + "qgroup": "0/464", + "pqgroup": "2015/4", + "name": "share2", + "uuid": null, + "size": 1048576, + "owner": "root", + "group": "root", + "perms": "755", + "toc": "2024-11-06T16:05:29.918Z", + "subvol_name": "share2", + "replica": false, + "compression_algo": "no", + "rusage": 16, + "eusage": 16, + "pqgroup_rusage": 16, + "pqgroup_eusage": 16 + } +}, +{ + "model": "storageadmin.nfsexport", + "pk": 3, + "fields": { + "export_group": 3, + "share": 21, + "mount": "/export/share-nfs" + } +}, +{ + "model": "storageadmin.nfsexportgroup", + "pk": 3, + "fields": { + "host_str": "*", + "editable": "rw", + "syncable": "async", + "mount_security": "insecure", + "nohide": false, + "enabled": true, + "admin_host": null + } +}, +{ + "model": "storageadmin.user", + "pk": 1, + "fields": { + "user": [ + "admin" + ], + "username": "admin", + "uid": 1000, + "gid": 100, + "public_key": null, + "shell": "/bin/bash", + "homedir": "/home/admin", + "email": null, + "admin": true, + "group": 1, + "smb_shares": [] + } +}, +{ + "model": "storageadmin.group", + "pk": 1, + "fields": { + "gid": 100, + "groupname": "users", + "admin": true + } +} +] diff --git a/src/rockstor/storageadmin/tests/test_nfs_export.py b/src/rockstor/storageadmin/tests/test_nfs_export.py index 67c7c8388..2fa715473 100644 --- a/src/rockstor/storageadmin/tests/test_nfs_export.py +++ b/src/rockstor/storageadmin/tests/test_nfs_export.py @@ -14,21 +14,52 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . """ -from unittest import mock from unittest.mock import patch from rest_framework import status -from storageadmin.models import Pool, Share, NFSExportGroup, NFSExport from storageadmin.tests.test_api import APITestMixin +""" +fixture with: +Pool: + - pk=11 + - name="rock-pool" +Share: + - pk=21 + - name: "share-nfs" + - pool: "rock-pool" above + - exported with defaults: + - (NFS Clients) host_str: "*" + - (Admin Host) admin_host: None + - (Access type) mod_choice: "rw" + - (Response type) sync_choice: "async" +Share: + - pk=22 + - name: "share2" +User: + - pk: 1 + - name: admin + - group: 1 +Group: + - pk: 1 + +proposed fixture = 'test_nfs.json' + +cd /opt/rockstor +poetry run django-admin dumpdata storageadmin.pool storageadmin.share \ +storageadmin.nfsexport storageadmin.nfsexportgroup \ +storageadmin.user storageadmin.group \ +--natural-foreign --indent 4 > \ +src/rockstor/storageadmin/fixtures/test_nfs.json + +To run the tests: +cd /opt/rockstor/src/rockstor +poetry run django-admin test -v 2 -p test_nfs_export.py +""" + class NFSExportTests(APITestMixin): - # fixture with: - # share-nfs - NFS exported - with defaults: client=*, Writable, async - # {'host_str': '*', 'mod_choice': 'rw', 'sync_choice': 'async', } - # share2 - no NFS export - # proposed fixture = 'test_nfs.json' - fixtures = ["test_api.json"] + fixtures = ["test_api.json", "test_nfs.json"] BASE_URL = "/api/nfs-exports" @classmethod @@ -51,56 +82,46 @@ def setUpClass(cls): # validate_nfs_modify_str # validate_nfs_sync_choice - # all values as per fixture - cls.temp_pool = Pool(id=11, name="rock-pool", size=5242880) - cls.temp_share_nfs = Share(id=21, name="share-nfs", pool=cls.temp_pool) - # the following is not picking up from db !! - # cls.temp_nfsexportgroup = NFSExportGroup.objects.get(id=1) - cls.temp_nfsexportgroup = NFSExportGroup(id=1) - cls.temp_nfsexport = NFSExport( - export_group=cls.temp_nfsexportgroup, - share=cls.temp_share_nfs, - mount="/export/share-nfs", - id=1, - ) - - cls.temp_share2 = Share(id=22, name="share2", pool=cls.temp_pool) - @classmethod def tearDownClass(cls): super(NFSExportTests, cls).tearDownClass() - # TODO: FAIL {"detail":"Not found."} - # def test_get(self): - # """ - # Test GET request - # 1. Get base URL - # 2. Get request with id - # """ - # # get base URL - # self.get_base(self.BASE_URL) - # - # # get nfs-export with id - # nfs_id = self.temp_nfsexport.id - # response = self.client.get('{}/{}'.format(self.BASE_URL, nfs_id)) - # self.assertEqual(response.status_code, status.HTTP_200_OK, - # msg=response) + def test_get(self): + # get base URL + self.get_base(self.BASE_URL) + + # get nfs-export with id + nfs_id = 3 # from fixture + response = self.client.get(f"{self.BASE_URL}/{nfs_id}") + self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response) + + def test_post(self): + # Happy path - ensuring we create all that we intend. + # Clarifies current map re field naming of API vs DB vs Web-UI. + + # API / DB / Web-UI field name map: + data = { + "shares": ("share2",), + "host_str": "*.edu", # 'host_str', "NFS Clients" + "admin_host": "example-host", # 'admin_host', "Admin Host" + "mod_choice": "rw", # 'editable', "Access type" + "sync_choice": "sync", # 'syncable', "Response type" + # "mount_security": "secure", # 'mount_security', NOT IMPLEMENTED. + } + response = self.client.post(self.BASE_URL, data=data) + self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response.data) + self.assertEqual(response.data["host_str"], "*.edu") + self.assertEqual(response.data["admin_host"], "example-host") + self.assertEqual(response.data["editable"], "rw") + self.assertEqual(response.data["syncable"], "sync") + # self.assertEqual(response.data["mount_security"], "secure") def test_invalid_get(self): # get nfs-export with invalid id - response = self.client.get("{}/99999".format(self.BASE_URL)) + response = self.client.get(f"{self.BASE_URL}/99999") self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND, msg=response) - @mock.patch("storageadmin.views.share_helpers.Share") - def test_post_requests(self, mock_share): - """ - invalid nfs-export api operations - 1. Add nfs-export without providing share names - 2 Add nfs-export - 3. Add nfs-export for the share that has already been exported - - """ - + def test_post_requests(self): # Add nfs-export without providing share names self.mock_refresh_nfs_exports.side_effect = None self.mock_refresh_nfs_exports.return_value = "out", "err", 0 @@ -115,29 +136,20 @@ def test_post_requests(self, mock_share): e_msg = "Cannot export without specifying shares." self.assertEqual(response.data[0], e_msg) - mock_share.objects.get.return_value = self.temp_share2 - - # AssertionError: ["{'share': [u'share instance with id 22 does not exist.']}", - # # happy path - # data1 = {'shares': ('share2',), 'host_str': '*.edu', - # 'mod_choice': 'rw', 'sync_choice': 'async', } - # response = self.client.post(self.BASE_URL, data=data1) - # self.assertEqual(response.status_code, - # status.HTTP_200_OK, msg=response.data) - - # # Add nfs-export for the share that is already been exported - # data1 = {'shares': ('share1',), 'host_str': '*', 'mod_choice': 'rw', - # 'sync_choice': 'async', } - # response = self.client.post(self.BASE_URL, data=data1) - # self.assertEqual(response.status_code, - # status.HTTP_500_INTERNAL_SERVER_ERROR, - # msg=response.data) - # e_msg = 'An export already exists for the host string: (*).' - # self.assertEqual(response.data[0], e_msg) - - # Add nfs-export with invalid nfs-client + # happy path data1 = { - "shares": ("share1",), + "shares": ("share2",), + "host_str": "*.edu", + "mod_choice": "rw", + "sync_choice": "async", + } + response = self.client.post(self.BASE_URL, data=data1) + self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response.data) + + # Add NFS export - non-existent share + fake_share_name: str = "non-existent" + data1 = { + "shares": (f"{fake_share_name}",), "host_str": "*", "mod_choice": "rw", "sync_choice": "async", @@ -148,129 +160,203 @@ def test_post_requests(self, mock_share): status.HTTP_500_INTERNAL_SERVER_ERROR, msg=response.data, ) - # TODO: AssertionError: "{'share': [u'share instance with id 22 does not exist.']} - # e_msg = 'An export already exists for the host string: (*).' - # self.assertEqual(response.data[0], e_msg) - - # TODO: Test needs updating - # AssertionError: ['Share with name (clone1) does not exist.', - # def test_no_nfs_client(self): - # # Add nfs-export without specifying nfs-clients(host string). The - # # server side defaults the host string to * so test for this. - # - # self.mock_refresh_nfs_exports.side_effect = None - # data1 = {'shares': ('clone1',), 'mod_choice': 'rw', - # 'sync_choice': 'async', } - # response = self.client.post(self.BASE_URL, data=data1) - # self.assertEqual(response.status_code, - # status.HTTP_200_OK, msg=response.data) - # self.assertEqual(response.data['host_str'], '*') - - # def test_invalid_nfs_client2(self): - # - # # TODO: Test needs updating - # # invalid post request - # # Add nfs-export providing invalid nfs client - # self.mock_refresh_nfs_exports.side_effect = Exception() - # - # data1 = {'shares': ('clone1',), 'host_str': 'host%%%edu', - # 'mod_choice': 'rw', 'sync_choice': 'async', } - # response = self.client.post(self.BASE_URL, data=data1) - # self.assertEqual(response.status_code, - # status.HTTP_500_INTERNAL_SERVER_ERROR, - # msg=response.data) - # - # e_msg = 'Invalid Hostname or IP: host%%%edu' - # self.assertEqual(response.data[0], e_msg) - # self.mock_refresh_nfs_exports.side_effect = None - # - # def test_invalid_nfs_client3(self): - # - # # TODO: Test needs updating - # # invalid put request - # # edit nfs-export providing invalid nfs-client - # self.mock_refresh_nfs_exports.side_effect = Exception() - # nfs_id = 11 - # data = {'shares': ('share2',), 'host_str': 'host%%%edu', - # 'admin_host': ' ', 'mod_choice': 'rw', - # 'sync_choice': 'async', } - # response = self.client.put('{}/{}'.format(self.BASE_URL, nfs_id), - # data=data) - # self.assertEqual(response.status_code, - # status.HTTP_500_INTERNAL_SERVER_ERROR, - # msg=response.data) - # e_msg = 'Invalid Hostname or IP: host%%%edu' - # self.assertEqual(response.data[0], e_msg) - # self.mock_refresh_nfs_exports.side_effect = None - - @mock.patch("storageadmin.views.share_helpers.Share") - def test_invalid_admin_host1(self, mock_share): - - mock_share.objects.get.return_value = self.temp_share2 - - # invalid post request - # Add nfs-export providing invalid admin host - self.mock_refresh_nfs_exports.side_effect = Exception() + e_msg = f"Share with name ({fake_share_name}) does not exist." + self.assertEqual(response.data[0], e_msg) + + def test_no_nfs_client(self): + # Add NFS export without host_str + # The server side defaults the host string to * so test for this. + + self.mock_refresh_nfs_exports.side_effect = None + data = { "shares": ("share2",), - "host_str": "*.edu", - "admin_host": "admin%host", "mod_choice": "rw", "sync_choice": "async", } response = self.client.post(self.BASE_URL, data=data) + self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response.data) + self.assertEqual(response.data["host_str"], "*") + + def test_mod_choice_validator_post(self): + # DB validator should restrict to "ro" or "rw": validate_nfs_modify_str() & model choices + data = { + "shares": ("share2",), + "mod_choice": "rr", + "sync_choice": "async", + } + response = self.client.post(self.BASE_URL, data=data) self.assertEqual( response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR, msg=response.data, ) - # TODO: FAIL AssertionError: - # "{'share': [u'share instance with id 22 does not exist.']}" - # != 'Invalid admin host: admin%host' - # e_msg = 'Invalid admin host: admin%host' - # self.assertEqual(response.data[0], e_msg) - self.mock_refresh_nfs_exports.side_effect = None + e_msg = {'editable': ["Value 'rr' is not a valid choice."]} + self.assertEqual(response.data[0], str(e_msg)) + + def test_mod_choice_validator_put(self): + # DB validator should restrict to "ro" or "rw": validate_nfs_modify_str() & model choices + data = { + "shares": ("share-nfs",), + "mod_choice": "rr", + "sync_choice": "async", + } + nfs_id = 3 # from fixture + response = self.client.put(f"{self.BASE_URL}/{nfs_id}", data=data) + self.assertEqual( + response.status_code, + status.HTTP_500_INTERNAL_SERVER_ERROR, + msg=response.data, + ) + e_msg = {'editable': ["Value 'rr' is not a valid choice."]} + self.assertEqual(response.data[0], str(e_msg)) + + def test_sync_choice_validator_post(self): + # DB validator should restrict to "async" or "sync": validate_nfs_sync_choice() & model choices + data = { + "shares": ("share2",), + "mod_choice": "ro", + "sync_choice": "aaaaa", + } + response = self.client.post(self.BASE_URL, data=data) + self.assertEqual( + response.status_code, + status.HTTP_500_INTERNAL_SERVER_ERROR, + msg=response.data, + ) + e_msg = {'syncable': ["Value 'aaaaa' is not a valid choice."]} + self.assertEqual(response.data[0], str(e_msg)) + + def test_sync_choice_validator_put(self): + # DB validator should restrict to "async" or "sync": validate_nfs_sync_choice() & model choices + data = { + "shares": ("share-nfs",), + "mod_choice": "ro", + "sync_choice": "aaaaa", + } + nfs_id = 3 # from fixture + response = self.client.put(f"{self.BASE_URL}/{nfs_id}", data=data) + self.assertEqual( + response.status_code, + status.HTTP_500_INTERNAL_SERVER_ERROR, + msg=response.data, + ) + e_msg = {'syncable': ["Value 'aaaaa' is not a valid choice."]} + self.assertEqual(response.data[0], str(e_msg)) + + def test_host_str_validator_post(self): + # DB validator should restrict to valid entry: validate_nfs_host_str + data = { + "shares": ("share2",), + "host_str": "1.!", + "mod_choice": "ro", + "sync_choice": "async", + } + response = self.client.post(self.BASE_URL, data=data) + self.assertEqual( + response.status_code, + status.HTTP_500_INTERNAL_SERVER_ERROR, + msg=response.data, + ) + e_msg = {'host_str': ['Invalid host string: 1.!']} + self.assertEqual(response.data[0], str(e_msg)) + + def test_host_str_validator_put(self): + # DB validator should restrict to valid entry: validate_nfs_host_str + data = { + "shares": ("share-nfs",), + "host_str": "ted fred", + "mod_choice": "ro", + "sync_choice": "async", + } + nfs_id = 3 # from fixture + response = self.client.put(f"{self.BASE_URL}/{nfs_id}", data=data) + self.assertEqual( + response.status_code, + status.HTTP_500_INTERNAL_SERVER_ERROR, + msg=response.data, + ) + e_msg = {'host_str': ['Invalid host string: ted fred']} + self.assertEqual(response.data[0], str(e_msg)) - def test_invalid_admin_host2(self): - # invalid put request - # edit nfs-export providing invalid admin host - self.mock_refresh_nfs_exports.side_effect = Exception() - nfs_id = 11 + def test_share_already_exported(self): + # Add NFS export for share already exported + data = { + "shares": ("share-nfs",), + "host_str": "*", + "mod_choice": "rw", + "sync_choice": "async", + } + response = self.client.post(self.BASE_URL, data=data) + self.assertEqual( + response.status_code, + status.HTTP_500_INTERNAL_SERVER_ERROR, + msg=response.data, + ) + e_msg = "An export already exists for the host string: (*)." + self.assertEqual(response.data[0], e_msg) + + def test_low_level_error_post(self): + # Invalid POST request + # Add NFS export - invalid admin host + ll_error: str = "post low level error" + self.mock_refresh_nfs_exports.side_effect = Exception(ll_error) data = { "shares": ("share2",), "host_str": "*.edu", - "admin_host": "admin%host", + "admin_host": "admin-host", "mod_choice": "rw", "sync_choice": "async", } - response = self.client.put("{}/{}".format(self.BASE_URL, nfs_id), data=data) + response = self.client.post(self.BASE_URL, data=data) self.assertEqual( response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR, msg=response.data, ) - # TODO: FAIL AssertionError: - # 'Share with name (share2) does not exist.' != 'Invalid admin host: admin%host' - # e_msg = 'Invalid admin host: admin%host' - # self.assertEqual(response.data[0], e_msg) + + e_msg = ( + f"A lower level error occurred while refreshing NFS exports: ({ll_error})." + ) + self.assertEqual(response.data[0], e_msg) + self.mock_refresh_nfs_exports.side_effect = None - @mock.patch("storageadmin.views.nfs_exports.NFSExportGroup") - @mock.patch("storageadmin.views.share_helpers.Share") - def test_put_requests(self, mock_share, mock_nfsexportgroup): - """ - . Edit nfs-export with no shares - . Edit nfs-export - . Edit nfs-export that does not exists - """ + def test_low_level_error_put(self): + # Invalid PUT request + # Edit NFS export - invalid admin host + ll_error: str = "put low level error" + self.mock_refresh_nfs_exports.side_effect = Exception(ll_error) + + data = { + "shares": ("share-nfs",), + "host_str": "*.edu", + "admin_host": "admin-host", + "mod_choice": "rw", + "sync_choice": "async", + } + nfs_id = 3 # from fixture + response = self.client.put(f"{self.BASE_URL}/{nfs_id}", data=data) + self.assertEqual( + response.status_code, + status.HTTP_500_INTERNAL_SERVER_ERROR, + msg=response.data, + ) + + e_msg = ( + f"A lower level error occurred while refreshing NFS exports: ({ll_error})." + ) + self.assertEqual(response.data[0], e_msg) - # Edit nfs-export with no shares self.mock_refresh_nfs_exports.side_effect = None - self.mock_refresh_nfs_exports.return_value = "out", "err", 0 - nfs_id = self.temp_nfsexport.id + def test_put_requests(self): + # Edit NFS export without specifying share. + self.mock_refresh_nfs_exports.side_effect = None + self.mock_refresh_nfs_exports.return_value = "out", "err", 0 + nfs_id = 3 # from fixture data = {"host_str": "*.edu", "mod_choice": "rw", "sync_choice": "async"} - response = self.client.put("{}/{}".format(self.BASE_URL, nfs_id), data=data) + response = self.client.put(f"{self.BASE_URL}/{nfs_id}", data=data) self.assertEqual( response.status_code, status.HTTP_500_INTERNAL_SERVER_ERROR, @@ -279,90 +365,69 @@ def test_put_requests(self, mock_share, mock_nfsexportgroup): e_msg = "Cannot export without specifying shares." self.assertEqual(response.data[0], e_msg) - mock_share.objects.get.return_value = self.temp_share_nfs - mock_nfsexportgroup.objects.get.return_value = self.temp_nfsexportgroup - - # TODO: FAIL AssertionError: ["{'export_group': [u'This field cannot be null.'], - # 'share': [u'share instance with id 21 does not exist.']}", - # # happy path of editing existing nfs export - # nfs_id = self.temp_nfsexport.id - # data = {'shares': ('share-nfs',), 'host_str': '*.edu', - # 'mod_choice': 'rw', 'sync_choice': 'async', } - # response = self.client.put('{}/{}'.format(self.BASE_URL, nfs_id), - # data=data) - # self.assertEqual(response.status_code, - # status.HTTP_200_OK, msg=response.data) - - # TODO: FAIL AssertionError: ["{'export_group': [u'This field cannot be null.'], - # 'share': [u'share instance with id 21 does not exist.']}", - # # happy path2 with admin host - # nfs_id = 11 - # data = {'shares': ('share2',), 'host_str': '*.edu', - # 'admin_host': 'host', 'mod_choice': 'rw', - # 'sync_choice': 'async', } - # response = self.client.put('{}/{}'.format(self.BASE_URL, nfs_id), - # data=data) - # self.assertEqual(response.status_code, - # status.HTTP_200_OK, msg=response.data) - - # TODO: FAIL AssertionError: "{'export_group': [u'This field cannot be null.'], - # 'share': [u'share instance with id 21 does not exist.']}" - # # edit nfs-export that does not exist - # nfs_id = 99999 - # data = {'shares': ('share2',), 'host_str': '*.edu', - # 'mod_choice': 'rw', 'sync_choice': 'async', } - # response = self.client.put('{}/{}'.format(self.BASE_URL, nfs_id), - # data=data) - # self.assertEqual(response.status_code, - # status.HTTP_500_INTERNAL_SERVER_ERROR, - # msg=response.data) - # e_msg = 'NFS export with id ({}) does not exist.'.format(nfs_id) - # self.assertEqual(response.data[0], e_msg) - - @mock.patch("storageadmin.views.nfs_exports.NFSExport") - @mock.patch("storageadmin.views.nfs_exports.NFSExportGroup") - def test_delete_requests(self, mock_nfsexportgroup, mock_nfsexport): - - """ - . Delete nfs-export that does not exist - . Delete nfs-export - """ - - mock_nfsexportgroup.objects.get.return_value = self.temp_nfsexportgroup - mock_nfsexport.objects.get.return_value = self.temp_nfsexport + # Happy path - editing existing NFS export. + nfs_id = 3 # from fixture + data = { + "shares": ("share-nfs",), + "host_str": "*.edu", + "mod_choice": "rw", + "sync_choice": "async", + } + response = self.client.put(f"{self.BASE_URL}/{nfs_id}", data=data) + self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response.data) - # happy path - nfs_id = self.temp_nfsexport.id - response = self.client.delete("{}/{}".format(self.BASE_URL, nfs_id)) + # Happy path - editing existing NFS export re adding admin host. + nfs_id = 3 # from fixture + data = { + "shares": ("share-nfs",), + "host_str": "*.edu", + "admin_host": "test-nfs-admin-host", + "mod_choice": "rw", + "sync_choice": "async", + } + response = self.client.put(f"{self.BASE_URL}/{nfs_id}", data=data) + self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response.data) + + # Edit non-existent NFS export, existing share in fixtures. + nfs_id = 99999 + data = { + "shares": ("share2",), + "host_str": "*.edu", + "mod_choice": "rw", + "sync_choice": "async", + } + response = self.client.put(f"{self.BASE_URL}/{nfs_id}", data=data) + self.assertEqual( + response.status_code, + status.HTTP_500_INTERNAL_SERVER_ERROR, + msg=response.data, + ) + e_msg = f"NFS export with id ({nfs_id}) does not exist." + self.assertEqual(response.data[0], e_msg) + + def test_delete_requests(self): + # Happy path + nfs_id = 3 # from fixture + response = self.client.delete(f"{self.BASE_URL}/{nfs_id}") self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response.data) - # TODO: FAIL - # mock_nfsexport.objects.get.side_effect = NFSExport.DoesNotExist - # - # # Delete nfs-export that does nor exists - # nfs_id = 99999 - # response = self.client.delete('{}/{}'.format(self.BASE_URL, nfs_id)) - # self.assertEqual(response.status_code, - # status.HTTP_500_INTERNAL_SERVER_ERROR, - # msg=response.data) - # e_msg = 'NFS export with id ({}) does not exist.'.format(nfs_id) - # self.assertEqual(response.data[0], e_msg) + # Delete nfs-export that does not exist + nfs_id = 99999 + response = self.client.delete(f"{self.BASE_URL}/{nfs_id}") + self.assertEqual( + response.status_code, + status.HTTP_500_INTERNAL_SERVER_ERROR, + msg=response.data, + ) + e_msg = f"NFS export with id ({nfs_id}) does not exist." + self.assertEqual(response.data[0], e_msg) def test_adv_nfs_get(self): - """ - Test GET request - 1. Get base URL - 2. Get request with id - """ - # get base URL + # Get advanced base URL self.get_base("/api/adv-nfs-exports") - @mock.patch("storageadmin.views.share_helpers.Share") - def test_adv_nfs_post_requests(self, mock_share): - - mock_share.objects.get.return_value = self.temp_share_nfs - - # without specifying entries + def test_adv_nfs_post_requests(self): + # Without specifying entries data = {} response = self.client.post("/api/adv-nfs-exports", data=data) self.assertEqual( @@ -373,7 +438,7 @@ def test_adv_nfs_post_requests(self, mock_share): e_msg = "Cannot export without specifying entries." self.assertEqual(response.data[0], e_msg) - # happy path + # Happy path data = {"entries": ["/export/share-nfs *(rw,async,insecure)"]} response = self.client.post("/api/adv-nfs-exports", data=data) self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response.data)