Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Renamed test folder to tests #4

Merged
merged 1 commit into from
Apr 28, 2024
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
File renamed without changes.
84 changes: 42 additions & 42 deletions test/list_backup_counts.py → tests/list_backup_counts.py
Original file line number Diff line number Diff line change
@@ -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"]) )

File renamed without changes.
154 changes: 77 additions & 77 deletions test/urbackup_api_test.py → tests/urbackup_api_test.py
Original file line number Diff line number Diff line change
@@ -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()
Loading