This repository has been archived by the owner on May 9, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Increasing code coverage by adding extra unit tests (#444)
* First batch of tests * Added API tests, continued on file based tests * Got 50% test coverage - needs to be addressed further
- Loading branch information
1 parent
73fae15
commit f54384e
Showing
8 changed files
with
140 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,18 @@ | ||
import pytest | ||
from mysql_autoxtrabackup.backup_backup.backuper import Backup | ||
from mysql_autoxtrabackup.api.main import app | ||
from fastapi.testclient import TestClient | ||
|
||
|
||
bck_obj = Backup() | ||
client = TestClient(app) | ||
|
||
|
||
@pytest.fixture() | ||
def return_bck_obj(): | ||
return bck_obj | ||
|
||
|
||
@pytest.fixture() | ||
def fastapi_client(): | ||
return client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
|
||
class TestAPI: | ||
|
||
def test_take_backup(self, fastapi_client): | ||
response = fastapi_client.post('/backup') | ||
assert response.status_code == 201 | ||
assert response.json() == {"result":"Successfully finished the backup process"} | ||
|
||
def test_prepare_backup(self, fastapi_client): | ||
response = fastapi_client.post('/prepare') | ||
assert response.status_code == 200 | ||
assert response.json() == {"result":"Successfully prepared all the backups"} | ||
|
||
def test_list_backups(self, fastapi_client): | ||
response = fastapi_client.get('/backups') | ||
assert response.status_code == 200 | ||
|
||
def test_delete_backups(self, fastapi_client): | ||
response = fastapi_client.delete('/delete') | ||
assert response.status_code == 200 | ||
assert response.json() == {"result":"There is no backups or backups removed successfully"} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import shutil | ||
|
||
import pytest | ||
import os | ||
|
||
from mysql_autoxtrabackup.utils import helpers | ||
|
||
|
||
class TestHelpers: | ||
|
||
def test_get_latest_dir_name(self): | ||
os.makedirs('tests/DELETE_ME', mode=777, exist_ok=True) | ||
os.makedirs('tests/DELETE_ME/2021-05-06_11-48-31', mode=777, exist_ok=True) | ||
os.makedirs('tests/DELETE_ME/2021-05-06_11-47-31', mode=777, exist_ok=True) | ||
|
||
assert helpers.get_latest_dir_name(path=f'{os.path.dirname(__file__)}/DELETE_ME') == '2021-05-06_11-48-31' | ||
|
||
def test_create_backup_directory(self): | ||
path_ = f'{os.path.dirname(__file__)}/DELETE_ME' | ||
assert helpers.create_backup_directory(path_, 'TEST_DIR') == f'{path_}/TEST_DIR' | ||
shutil.rmtree(f'{path_}/TEST_DIR') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import os | ||
import pytest | ||
|
||
|
||
class TestMySQLCLi: | ||
def test_create_mysql_client_command(self, return_bck_obj): | ||
result = '/usr/bin/mysql --defaults-file= -uroot --password=12345 --socket=/var/run/mysqld/mysqld.sock -e "select 1"' | ||
sql = "select 1" | ||
assert return_bck_obj.mysql_cli.create_mysql_client_command(sql) == result | ||
|
||
def test_mysql_run_command(self, return_bck_obj): | ||
sql = "select 1" | ||
assert return_bck_obj.mysql_cli.mysql_run_command(sql) is True |