Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/rockstor/smart_manager/tests/test_snmp.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,20 @@
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from unittest.mock import patch

from rest_framework import status
from rest_framework.test import APITestCase


"""
To run the tests:
cd /opt/rockstor/src/rockstor
export DJANGO_SETTINGS_MODULE="settings"
poetry run django-admin test -v 2 -p test_snmp.py
"""


class SNMPTests(APITestCase):
multi_db = True
# TODO Requires command to reproduce minimal fixture:
Expand All @@ -41,6 +50,11 @@ def test_snmp_0_1(self):
"""
config happy path
"""
self.patch_configure_snmp = patch(
"smart_manager.views.snmp_service.configure_snmp"
)
self.mock_configure_snmp = self.patch_configure_snmp.start()

config = {
"syslocation": "Rockstor Labs",
"syscontact": "rocky@rockstor.com",
Expand Down Expand Up @@ -159,6 +173,10 @@ def test_snmp_7(self):
"""
start/stop tests
"""
self.patch_systemctl = patch("smart_manager.views.snmp_service.systemctl")
self.mock_systemctl = self.patch_systemctl.start()
self.mock_systemctl.return_value = [""], [""], 0

self.session_login()
response = self.client.post("%s/start" % self.BASE_URL)
self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response.content)
Expand Down
47 changes: 47 additions & 0 deletions src/rockstor/storageadmin/fixtures/test_user.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[
{
"model": "storageadmin.user",
"pk": 1,
"fields": {
"user": [
"admin"
],
"username": "admin",
"uid": 1003,
"gid": 100,
"public_key": null,
"shell": "/bin/bash",
"homedir": "/home/radmin",
"email": null,
"admin": true,
"group": 1,
"smb_shares": []
}
},
{
"model": "storageadmin.user",
"pk": 2,
"fields": {
"user": null,
"username": "testuser",
"uid": 1004,
"gid": 100,
"public_key": null,
"shell": "/bin/bash",
"homedir": "/home/testuser",
"email": null,
"admin": false,
"group": 1,
"smb_shares": []
}
},
{
"model": "storageadmin.group",
"pk": 1,
"fields": {
"gid": 100,
"groupname": "users",
"admin": true
}
}
]
20 changes: 20 additions & 0 deletions src/rockstor/storageadmin/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
from storageadmin.tests.test_api import APITestMixin


"""
To run the tests:
cd /opt/rockstor/src/rockstor
export DJANGO_SETTINGS_MODULE="settings"
poetry run django-admin test -v 2 -p test_commands.py
"""


class CommandTests(APITestMixin):
# Proposed fixture = "test_commands.json" was "fix5.json"
fixtures = ["test_api.json"]
Expand Down Expand Up @@ -74,6 +82,18 @@ def setUpClass(cls):
)
cls.mock_import_snapshots = cls.patch_import_snapshots.start()

cls.patch_get_unlocked_luks_containers_uuids = patch(
"storageadmin.views.disk.get_unlocked_luks_containers_uuids"
)
cls.mock_get_unlocked_luks_containers_uuids = (
cls.patch_get_unlocked_luks_containers_uuids.start()
)
cls.mock_get_unlocked_luks_containers_uuids.return_value = []

cls.patch_enable_quota = patch("storageadmin.views.disk.enable_quota")
cls.mock_enable_quota = cls.patch_enable_quota.start()
cls.mock_enable_quota.return_value = [""], [""], 0

@classmethod
def tearDownClass(cls):
super(CommandTests, cls).tearDownClass()
Expand Down
9 changes: 8 additions & 1 deletion src/rockstor/storageadmin/tests/test_config_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
from unittest import mock
from unittest.mock import patch
from rest_framework import status

from storageadmin.models import ConfigBackup
Expand All @@ -37,14 +38,16 @@
- Create 1 share named 'test_share01'
- Create 1 share named 'test_share02'

cd /opt/rockstor
export DJANGO_SETTINGS_MODULE="settings"
poetry run django-admin dumpdata storageadmin.pool storageadmin.share \
--natural-foreign --indent 4 > \
src/rockstor/storageadmin/fixtures/test_config_backup.json

To run the tests:
cd /opt/rockstor/src/rockstor
export DJANGO_SETTINGS_MODULE="settings"
cd src/rockstor && poetry run django-admin test -v 2 -p test_config_backup.py
poetry run django-admin test -v 2 -p test_config_backup.py
"""


Expand Down Expand Up @@ -1245,6 +1248,10 @@ def setUpClass(cls):

# TODO: may need to mock os.path.isfile

cls.patch_backup_config = patch("storageadmin.views.config_backup.backup_config")
cls.mock_backup_config = cls.patch_backup_config.start()
cls.mock_backup_config.return_value = None

@classmethod
def tearDownClass(cls):
super(ConfigBackupTests, cls).tearDownClass()
Expand Down
16 changes: 16 additions & 0 deletions src/rockstor/storageadmin/tests/test_disks.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@
from storageadmin.tests.test_api import APITestMixin


"""
To run the tests:
cd /opt/rockstor/src/rockstor
export DJANGO_SETTINGS_MODULE="settings"
poetry run django-admin test -v 2 -p test_disks.py
"""


class DiskTests(APITestMixin):
# Proposed fixture = ['test_disks.json']
fixtures = ["test_api.json"]
Expand All @@ -40,6 +48,14 @@ def setUpClass(cls):
cls.patch_scan_disks = patch("storageadmin.views.disk.scan_disks")
cls.mock_scan_disks = cls.patch_scan_disks.start()

cls.patch_get_unlocked_luks_containers_uuids = patch(
"storageadmin.views.disk.get_unlocked_luks_containers_uuids"
)
cls.mock_get_unlocked_luks_containers_uuids = (
cls.patch_get_unlocked_luks_containers_uuids.start()
)
cls.mock_get_unlocked_luks_containers_uuids.return_value = []

cls.patch_blink_disk = patch("storageadmin.views.disk.blink_disk")
cls.mock_blink_disk = cls.patch_blink_disk.start()

Expand Down
11 changes: 11 additions & 0 deletions src/rockstor/storageadmin/tests/test_email_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
from storageadmin.tests.test_api import APITestMixin


"""
To run the tests:
cd /opt/rockstor/src/rockstor
export DJANGO_SETTINGS_MODULE="settings"
poetry run django-admin test -v 2 -p test_email_client.py
"""


class EmailTests(APITestMixin):
# Proposed fixture "test_appliances.json"
fixtures = ["test_api.json"]
Expand Down Expand Up @@ -55,6 +63,9 @@ def setUpClass(cls):
cls.patch_update_sasl = patch("storageadmin.views.email_client.update_sasl")
cls.mock_update_sasl = cls.patch_update_sasl.start()

cls.patch_update_master = patch("storageadmin.views.email_client.update_master")
cls.mock_update_master = cls.patch_update_master.start()

# all values as per fixture
cls.temp_appliance = Appliance(
id=1,
Expand Down
13 changes: 12 additions & 1 deletion src/rockstor/storageadmin/tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
from storageadmin.models import NetworkConnection, NetworkDevice


"""
To run the tests:
cd /opt/rockstor/src/rockstor
export DJANGO_SETTINGS_MODULE="settings"
poetry run django-admin test -v 2 -p test_network.py
"""

class NetworkTests(APITestMixin):
# TODO Move as many by-hand mocks to now functional fixture setup.
# TODO Provide command to create fixture
Expand All @@ -31,7 +38,6 @@ class NetworkTests(APITestMixin):
# Proposed fixture = "test_network.json"
# TODO: Needs changing as API url different ie connection|devices|refresh
# see referenced pr in setUpClass
# ./bin/test -v 2 -p test_network.py
fixtures = ["test_api.json"]
BASE_URL = "/api/network"

Expand Down Expand Up @@ -92,6 +98,11 @@ def setUpClass(cls):
}
}

# system.network.get_con_list()
cls.patch_get_con_list = patch("system.network.get_con_list")
cls.mock_get_con_list = cls.patch_get_con_list.start()
cls.mock_get_con_list.return_value = []

# valid_connection
cls.patch_valid_connection = patch("system.network.valid_connection")
cls.mock_valid_connection = cls.patch_valid_connection.start()
Expand Down
71 changes: 43 additions & 28 deletions src/rockstor/storageadmin/tests/test_samba.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,36 +25,46 @@
from storageadmin.tests.test_api import APITestMixin
from storageadmin.views.samba import SambaListView

"""
fixture with:
1 pool:
- id=11
- name="rock-pool"
1 share:
- pool: "rock-pool" above
- name: share-smb
- exported with defaults:
- comment: "Samba-Export"
- admin_users: None
- browsable: 'yes'
- guest_ok: 'no'
- read_only: 'no'
1 share:
- name: share2 - no SMB export
1 User:
- id: 1
- name: admin
- group: 1
1 Group:
- pk: 1

proposed fixture = "test_smb.json"

cd /opt/rockstor
export DJANGO_SETTINGS_MODULE="settings"
poetry run django-admin dumpdata storageadmin.pool storageadmin.share
storageadmin.sambashare storageadmin.user storageadmin.group
--natural-foreign --indent 4 >
src/rockstor/storageadmin/fixtures/test_smb.json

To run the tests:
cd /opt/rockstor/src/rockstor
export DJANGO_SETTINGS_MODULE="settings"
poetry run django-admin test -v 2 -p test_samba.py
"""


class SambaTests(APITestMixin, SambaListView):
# fixture with:
# 1 pool:
# - id=11
# - name="rock-pool"
# 1 share:
# - pool: "rock-pool" above
# - name: share-smb
# - exported with defaults:
# - comment: "Samba-Export"
# - admin_users: None
# - browsable: 'yes'
# - guest_ok: 'no'
# - read_only: 'no'
# 1 share:
# - name: share2 - no SMB export
# 1 User:
# - id: 1
# - name: admin
# - group: 1
# 1 Group:
# - pk: 1

# proposed fixture = "test_smb.json"
# bin/django dumpdata storageadmin.pool storageadmin.share
# storageadmin.sambashare storageadmin.user storageadmin.group
# --natural-foreign --indent 4 >
# src/rockstor/storageadmin/fixtures/test_smb.json
# ./bin/test -v 2 -p test_samba.py
fixtures = ["test_api.json", "test_smb.json"]
BASE_URL = "/api/samba"

Expand Down Expand Up @@ -85,6 +95,11 @@ def setUpClass(cls):
cls.mock_refresh_smb_config = cls.patch_refresh_smb_config.start()
cls.mock_refresh_smb_config.return_value = "smbconfig"

cls.patch_refresh_smb_discovery = patch(
"storageadmin.views.samba.refresh_smb_discovery"
)
cls.mock_refresh_smb_discovery = cls.patch_refresh_smb_discovery.start()

@classmethod
def tearDownClass(cls):
super(SambaTests, cls).tearDownClass()
Expand Down
Loading