Reviewed-on: #16deb-packages 0.5.15
commit
f7c2ad84f0
|
@ -23,10 +23,10 @@ NOTA: Se debe ejecutar como "root", o dará errores de permisos con la imagen de
|
|||
# --------------------------------------------------------------------------------------------
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch, mock_open, MagicMock
|
||||
from unittest.mock import patch, mock_open, MagicMock, AsyncMock
|
||||
from flask import json
|
||||
import os
|
||||
from repo_api import app, get_image_params, search_process, check_remote_connection, check_remote_image, check_lock_remote
|
||||
from repo_api import app, get_image_params, search_process, check_remote_connection, check_remote_image, check_lock_remote, check_lock_local, check_aux_files
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------------------------
|
||||
|
@ -169,15 +169,17 @@ class RepoApiTestCase(unittest.TestCase):
|
|||
|
||||
|
||||
@patch('repo_api.check_remote_connection')
|
||||
@patch('repo_api.check_lock_local')
|
||||
@patch('repo_api.check_remote_image')
|
||||
@patch('repo_api.subprocess.Popen')
|
||||
def test_import_image(self, mock_popen, mock_check_remote_image, mock_check_remote_connection):
|
||||
def test_import_image(self, mock_popen, mock_check_remote_image, mock_check_remote_connection, mock_check_lock_local):
|
||||
""" Método de prueba del endpoint "Importar una Imagen".
|
||||
"""
|
||||
print("Testing endpoint 'Importar una Imagen'...")
|
||||
mock_check_remote_connection.return_value = True
|
||||
mock_check_remote_image.return_value = None
|
||||
mock_popen.return_value = MagicMock(returncode=None)
|
||||
mock_check_lock_local.return_value = AsyncMock(returncode=None)
|
||||
response = self.app.post('/ogrepository/v1/repo/images', data=json.dumps({"image": "test4unittest.img", "repo_ip": "127.0.0.1", "user": "test_user"}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn('Importing image...', json.loads(response.data)['output'])
|
||||
|
@ -192,20 +194,22 @@ class RepoApiTestCase(unittest.TestCase):
|
|||
"""
|
||||
print("Testing endpoint 'Exportar una Imagen'...")
|
||||
mock_check_remote_connection.return_value = True
|
||||
mock_check_lock_remote.return_value = None
|
||||
mock_get_image_params.return_value = {'name': 'test4unittest', 'extension': 'img'}
|
||||
mock_popen.return_value = MagicMock(returncode=None)
|
||||
mock_check_lock_remote.return_value = AsyncMock(returncode=None)
|
||||
response = self.app.put('/ogrepository/v1/repo/images', data=json.dumps({"ID_img": "test_image_id", "repo_ip": "127.0.0.1", "user": "test_user"}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn('Exporting image...', json.loads(response.data)['output'])
|
||||
|
||||
|
||||
@patch('repo_api.subprocess.Popen')
|
||||
def test_create_torrent_sum(self, mock_popen):
|
||||
@patch('repo_api.check_aux_files')
|
||||
def test_create_torrent_sum(self, mock_popen, mock_check_aux_files):
|
||||
""" Método de prueba del endpoint "Crear archivos auxiliares".
|
||||
"""
|
||||
print("Testing endpoint 'Crear archivos auxiliares'...")
|
||||
mock_popen.return_value = MagicMock(returncode=None)
|
||||
mock_check_aux_files.return_value = AsyncMock(returncode=None)
|
||||
response = self.app.post('/ogrepository/v1/images/torrentsum', data=json.dumps({"image": "test4unittest.img"}), content_type='application/json')
|
||||
self.assertEqual(response.status_code, 200)
|
||||
self.assertIn('Creating auxiliar files...', json.loads(response.data)['output'])
|
||||
|
|
Loading…
Reference in New Issue