From f6c40c53e14a3f5085d78576ba62973500cddce3 Mon Sep 17 00:00:00 2001 From: judahpaul16 Date: Sun, 28 Apr 2024 01:47:10 -0400 Subject: [PATCH] Renamed test folder to tests --- {test => tests}/__init__.py | 0 {test => tests}/list_backup_counts.py | 84 +++++++------- {test => tests}/stop_all.py | 0 {test => tests}/urbackup_api_test.py | 154 +++++++++++++------------- 4 files changed, 119 insertions(+), 119 deletions(-) rename {test => tests}/__init__.py (100%) rename {test => tests}/list_backup_counts.py (96%) rename {test => tests}/stop_all.py (100%) rename {test => tests}/urbackup_api_test.py (97%) diff --git a/test/__init__.py b/tests/__init__.py similarity index 100% rename from test/__init__.py rename to tests/__init__.py diff --git a/test/list_backup_counts.py b/tests/list_backup_counts.py similarity index 96% rename from test/list_backup_counts.py rename to tests/list_backup_counts.py index 9aeef0d..1da0425 100644 --- a/test/list_backup_counts.py +++ b/tests/list_backup_counts.py @@ -1,42 +1,42 @@ -import urbackup - -server = urbackup.urbackup_server("http://127.0.0.1:55414/x", "admin", "foo") - -clients = server.get_clients_with_group() - -for client in clients: - - file_backups = server.get_clientbackups(client["id"]) - - incr_file = 0 - full_file = 0 - - for file_backup in file_backups: - - if file_backup["incremental"]>0: - incr_file+=1 - else: - full_file+=1 - - incr_image = 0 - full_image = 0 - - image_backups = server.get_clientimagebackups(client["id"]) - - for image_backup in image_backups: - - if image_backup["letter"]=="SYSVOL" or image_backup["letter"]=="ESP": - continue - - if image_backup["incremental"]>0: - incr_image+=1 - else: - full_image+=1 - - print("Client {clientname} in group {groupname} has {incr_file} incr file backups, {full_file} " - "full file backups, {incr_image} incr image backups and " - "{full_image} full image backups".format( - incr_file=incr_file, clientname=client["name"], - full_file=full_file, incr_image=incr_image, - full_image=full_image, groupname=client["groupname"]) ) - +import urbackup + +server = urbackup.urbackup_server("http://127.0.0.1:55414/x", "admin", "foo") + +clients = server.get_clients_with_group() + +for client in clients: + + file_backups = server.get_clientbackups(client["id"]) + + incr_file = 0 + full_file = 0 + + for file_backup in file_backups: + + if file_backup["incremental"]>0: + incr_file+=1 + else: + full_file+=1 + + incr_image = 0 + full_image = 0 + + image_backups = server.get_clientimagebackups(client["id"]) + + for image_backup in image_backups: + + if image_backup["letter"]=="SYSVOL" or image_backup["letter"]=="ESP": + continue + + if image_backup["incremental"]>0: + incr_image+=1 + else: + full_image+=1 + + print("Client {clientname} in group {groupname} has {incr_file} incr file backups, {full_file} " + "full file backups, {incr_image} incr image backups and " + "{full_image} full image backups".format( + incr_file=incr_file, clientname=client["name"], + full_file=full_file, incr_image=incr_image, + full_image=full_image, groupname=client["groupname"]) ) + diff --git a/test/stop_all.py b/tests/stop_all.py similarity index 100% rename from test/stop_all.py rename to tests/stop_all.py diff --git a/test/urbackup_api_test.py b/tests/urbackup_api_test.py similarity index 97% rename from test/urbackup_api_test.py rename to tests/urbackup_api_test.py index 33b9cff..b7fd038 100644 --- a/test/urbackup_api_test.py +++ b/tests/urbackup_api_test.py @@ -1,77 +1,77 @@ -import unittest -from unittest.mock import patch, MagicMock -from urbackup import urbackup_server, installer_os -import datetime -import time - -class TestUrBackupServer(unittest.TestCase): - def setUp(self): - self.server_url = "http://127.0.0.1:55414/x" - self.username = "admin" - self.password = "foo" - self.server = urbackup_server(self.server_url, self.username, self.password) - - @patch('urbackup.urbackup_server.get_extra_clients') - @patch('urbackup.urbackup_server.remove_extra_client') - def test_manage_extra_clients(self, mock_remove, mock_get_clients): - # Mocking the get_extra_clients and remove_extra_client methods - mock_get_clients.return_value = [{'id': 'client1'}, {'id': 'client2'}] - - # Execute the method to test - extra_clients = self.server.get_extra_clients() - for extra_client in extra_clients: - self.server.remove_extra_client(extra_client["id"]) - - # Assert that remove_extra_client was called for each client - mock_remove.assert_any_call('client1') - mock_remove.assert_any_call('client2') - self.assertEqual(mock_remove.call_count, 2) - - @patch('urbackup.urbackup_server.add_extra_client') - def test_add_extra_clients(self, mock_add_client): - # Setup - computernames = ["2.2.2.2", "3.3.3.3"] - mock_add_client.return_value = True - - # Test - for ip in computernames: - result = self.server.add_extra_client(ip) - self.assertTrue(result) - mock_add_client.assert_called_with(ip) - - @patch('urbackup.urbackup_server.get_status') - @patch('urbackup.urbackup_server.get_usage') - def test_check_status_and_usage(self, mock_get_usage, mock_get_status): - # Mocking responses - mock_get_status.return_value = [{'name': 'client1', 'lastbackup': 1590000000}] - mock_get_usage.return_value = [{'client': 'client1', 'data': 1000}] - - # Execution - clients = self.server.get_status() - usage = self.server.get_usage() - - # Verify length and data integrity - self.assertEqual(len(clients), len(usage)) - self.assertGreater(len(clients), 0) - self.assertEqual(clients[0]['name'], 'client1') - self.assertEqual(usage[0]['data'], 1000) - - @patch('urbackup.urbackup_server.get_status') - def test_backup_status_check(self, mock_get_status): - mock_get_status.return_value = [{'name': 'client1', 'lastbackup': time.time() - (4 * 24 * 60 * 60)}] - clients = self.server.get_status() - for client in clients: - if client['lastbackup'] < time.time() - (3 * 24 * 60 * 60): - lastbackup = datetime.datetime.fromtimestamp(client['lastbackup']).strftime('%x %X') - self.assertTrue("Last file backup at" in f"Last file backup at {lastbackup} of client {client['name']} is older than three days") - - @patch('urbackup.urbackup_server.download_installer') - def test_download_installer(self, mock_download): - # Setup - mock_download.return_value = True - result = self.server.download_installer("test.exe", "test", installer_os.Windows) - self.assertTrue(result) - mock_download.assert_called_with("test.exe", "test", installer_os.Windows) - -if __name__ == '__main__': - unittest.main() +import unittest +from unittest.mock import patch, MagicMock +from urbackup import urbackup_server, installer_os +import datetime +import time + +class TestUrBackupServer(unittest.TestCase): + def setUp(self): + self.server_url = "http://127.0.0.1:55414/x" + self.username = "admin" + self.password = "foo" + self.server = urbackup_server(self.server_url, self.username, self.password) + + @patch('urbackup.urbackup_server.get_extra_clients') + @patch('urbackup.urbackup_server.remove_extra_client') + def test_manage_extra_clients(self, mock_remove, mock_get_clients): + # Mocking the get_extra_clients and remove_extra_client methods + mock_get_clients.return_value = [{'id': 'client1'}, {'id': 'client2'}] + + # Execute the method to test + extra_clients = self.server.get_extra_clients() + for extra_client in extra_clients: + self.server.remove_extra_client(extra_client["id"]) + + # Assert that remove_extra_client was called for each client + mock_remove.assert_any_call('client1') + mock_remove.assert_any_call('client2') + self.assertEqual(mock_remove.call_count, 2) + + @patch('urbackup.urbackup_server.add_extra_client') + def test_add_extra_clients(self, mock_add_client): + # Setup + computernames = ["2.2.2.2", "3.3.3.3"] + mock_add_client.return_value = True + + # Test + for ip in computernames: + result = self.server.add_extra_client(ip) + self.assertTrue(result) + mock_add_client.assert_called_with(ip) + + @patch('urbackup.urbackup_server.get_status') + @patch('urbackup.urbackup_server.get_usage') + def test_check_status_and_usage(self, mock_get_usage, mock_get_status): + # Mocking responses + mock_get_status.return_value = [{'name': 'client1', 'lastbackup': 1590000000}] + mock_get_usage.return_value = [{'client': 'client1', 'data': 1000}] + + # Execution + clients = self.server.get_status() + usage = self.server.get_usage() + + # Verify length and data integrity + self.assertEqual(len(clients), len(usage)) + self.assertGreater(len(clients), 0) + self.assertEqual(clients[0]['name'], 'client1') + self.assertEqual(usage[0]['data'], 1000) + + @patch('urbackup.urbackup_server.get_status') + def test_backup_status_check(self, mock_get_status): + mock_get_status.return_value = [{'name': 'client1', 'lastbackup': time.time() - (4 * 24 * 60 * 60)}] + clients = self.server.get_status() + for client in clients: + if client['lastbackup'] < time.time() - (3 * 24 * 60 * 60): + lastbackup = datetime.datetime.fromtimestamp(client['lastbackup']).strftime('%x %X') + self.assertTrue("Last file backup at" in f"Last file backup at {lastbackup} of client {client['name']} is older than three days") + + @patch('urbackup.urbackup_server.download_installer') + def test_download_installer(self, mock_download): + # Setup + mock_download.return_value = True + result = self.server.download_installer("test.exe", "test", installer_os.Windows) + self.assertTrue(result) + mock_download.assert_called_with("test.exe", "test", installer_os.Windows) + +if __name__ == '__main__': + unittest.main()