diff --git a/decide/backups/backups.py b/decide/backups/backups.py index 0df52b02b6..2264b7f111 100644 --- a/decide/backups/backups.py +++ b/decide/backups/backups.py @@ -1,13 +1,25 @@ import os import time +from rest_framework import generics +from rest_framework.response import Response +from rest_framework.status import ( + HTTP_201_CREATED as ST_201, + HTTP_400_BAD_REQUEST as ST_400, +) def location(dir): - return dir + time.strftime("%d-%m-%Y-%H:%M:%S") + return dir + str(time.strftime("%d-%m-%Y-%H:%M:%S")) -def run_backup(dir): - print("generating mongo backup...") - run_backup = "mongodump --out " + location(dir) - os.system(run_backup) +class CreateBackup(generics.CreateAPIView): + def post(self, request, *args, **kwargs): + try: + print("generating mongo backup...") + run_backup = "mongodump --out " + location("./backups/backups/") + os.system(run_backup) + return Response({"name": location("./backups/backups/")}, status=ST_201) + except Exception as e: + return Response({"error": str(e)}, status=ST_400) + diff --git a/decide/backups/tests.py b/decide/backups/tests.py index e6218a8320..a6461357b8 100644 --- a/decide/backups/tests.py +++ b/decide/backups/tests.py @@ -4,12 +4,8 @@ # Create your tests here. class TestBackups(BaseTestCase): def test_create_backups(self): - run_backup("./backups/backups_test/") - path = time.strftime("%d-%m-%Y") - ls = os.listdir("./backups/backups_test/") - cont = 0 - for i in ls: - if path in i: - cont += 1 - self.assertTrue(cont>0) - os.system("rm -rf ./backups/backups_test") + response = self.client.post('/backups/create', "", format='json') + self.assertEqual(response.status_code, 201) + ls = os.listdir("./backups/backups") + backup_test = ls[-1] + os.system("rm -rf ./backups/backups/" + backup_test) diff --git a/decide/backups/urls.py b/decide/backups/urls.py index c50996d637..5742c85aea 100644 --- a/decide/backups/urls.py +++ b/decide/backups/urls.py @@ -1,7 +1,9 @@ from django.urls import path, include +from . import backups from . import views urlpatterns = [ #It isn already implemented in the views.py path('', views.index), + path('create', backups.CreateBackup.as_view(), name='create_backup'), ] \ No newline at end of file diff --git a/decide/decide/test_settings.py b/decide/decide/test_settings.py index 50d62be08d..140efb9469 100644 --- a/decide/decide/test_settings.py +++ b/decide/decide/test_settings.py @@ -70,6 +70,7 @@ 'postproc', 'store', 'visualizer', + 'backups', ] diff --git a/decide_panel/src/App.js b/decide_panel/src/App.js index 1df5dfca66..6810c34474 100644 --- a/decide_panel/src/App.js +++ b/decide_panel/src/App.js @@ -3,6 +3,7 @@ import "./css/App.css"; import { TabPanel } from "primereact/tabview"; import ConnectionTest from "./components/ConnectionTest"; import Voting from "./components/Voting"; +import Backups from "./components/Backups"; function App() { return ( @@ -18,6 +19,9 @@ function App() { {/*Componente personalizado de gráficos*/}
Estadísticas
+