From e501419c723ab410da3ff3a301fcdffcabd5e0f6 Mon Sep 17 00:00:00 2001 From: pedalopon Date: Fri, 7 Jan 2022 21:37:52 +0100 Subject: [PATCH 01/38] #43-test: Started voting test implementation --- decide/administration/tests.py | 41 ++++++++++++++++++++++++++++++++++ decide/administration/views.py | 12 +++++----- 2 files changed, 47 insertions(+), 6 deletions(-) diff --git a/decide/administration/tests.py b/decide/administration/tests.py index 7ce503c..79ed2a2 100644 --- a/decide/administration/tests.py +++ b/decide/administration/tests.py @@ -1,3 +1,44 @@ +from django.contrib.auth.models import User from django.test import TestCase +from rest_framework.test import APITestCase, APIClient + # Create your tests here. +from voting.models import Voting + + +class AdministrationTestCase(APITestCase): + def setUp(self): + self.client = APIClient() + user_admin = User(username='admin', is_staff=True, is_superuser=True) + user_admin.set_password('qwerty') + user_admin.save() + data = {'username': "admin", 'password': "qwerty"} + response = self.client.post('/administration/api/auth/login', data, format="json") + self.assertEqual(response.status_code, 200) + self.token = response.cookies.get('token', "") + self.assertTrue(self.token) + + def tearDown(self): + response = self.client.get('/administration/api/auth/logout') + self.assertEqual(response.status_code, 200) + self.token = response.COOKIES.get('token', "") + self.assertFalse(self.token) + + def test_post_voting_api(self): + data = { + "name": "test", + "desc": "test", + "question": { + "desc": "test?", + "options": [ + {"number": 1, + "option": "prueba"}, + {"number": 2, + "option": "no prueba"}]}, + "census": [1], + "auth": "http://localhost:8000" + } + response = self.client.post('/administration/api/votings', data, format="json") + self.assertEqual(response.status_code, 200) + self.assertTrue(Voting.objects.all().First() is not None) diff --git a/decide/administration/views.py b/decide/administration/views.py index fea4df4..d09b8c0 100644 --- a/decide/administration/views.py +++ b/decide/administration/views.py @@ -82,7 +82,7 @@ def post(self, request): for voter_id in id_users: census = Census(voting_id=voting_id, voter_id=voter_id) census.save() - return Response({"id": voting_id, "name": voting.name}, status=HTTP_200_OK) + return Response({"id": voting_id, "name": voting.name}, status=HTTP_201_CREATED) def put(self, request): @@ -218,7 +218,7 @@ def post(self, request): question_serializer = AdminQuestionSerializer(data=request.data) is_valid(question_serializer.is_valid(), question_serializer.errors) question_serializer.save() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_201_CREATED) def delete(self, request): if request.data.get("idList") is None: @@ -263,7 +263,7 @@ def post(self, request): census_serializer = CensusSerializer(data=request.data) is_valid(census_serializer.is_valid(), census_serializer.errors) census_serializer.save() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_201_CREATED) def delete(self, request): if request.data.get("idList") is None: @@ -308,7 +308,7 @@ def post(self, request): auth_serializer = AuthSerializer(data=request.data) is_valid(auth_serializer.is_valid(), auth_serializer.errors) auth_serializer.save() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_201_CREATED) def delete(self, request): if request.data.get("idList") is None: @@ -354,7 +354,7 @@ def post(self, request): key_serializer = KeySerializer(data=request.data) is_valid(key_serializer.is_valid(), key_serializer.errors) key_serializer.save() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_201_CREATED) def delete(self, request): if request.data.get("idList") is None: @@ -404,7 +404,7 @@ def post(self, request): last_name=fields['last_name'], email=fields['email'], is_staff=False) user.set_password(request.data['password']) user.save() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_201_CREATED) def delete(self, request): if request.data.get("idList") is None: From d33d6d481f23cb39e2165d74a7365f818c876c15 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sat, 8 Jan 2022 01:47:58 +0100 Subject: [PATCH 02/38] #43-feat: implement dashboard test and add mocks --- decide/administration/tests.py | 165 ++++++++++++++++++++++++++++----- decide/administration/views.py | 2 +- decide/decide/settings.py | 2 + 3 files changed, 143 insertions(+), 26 deletions(-) diff --git a/decide/administration/tests.py b/decide/administration/tests.py index 79ed2a2..c67779f 100644 --- a/decide/administration/tests.py +++ b/decide/administration/tests.py @@ -1,44 +1,159 @@ from django.contrib.auth.models import User -from django.test import TestCase +from .serializers import AdminVotingGetSerializer +from voting.models import Voting + from rest_framework.test import APITestCase, APIClient # Create your tests here. -from voting.models import Voting + +base_url = "/administration/api" + +user_json_mock = { + "username": "admin", + "password": "qwerty", + "email": "ad@admin.com", + "first_name": "admin", + "last_name": "admin", +} + +user_json_mock_updated = { + "id": 1, + "username": "updated", + "password": "updated", + "email": "updated@admin.com", + "first_name": "updated", + "last_name": "updated", +} + +voting_json_mock = { + "name": "Test voting", + "desc": "Test description", + "question": { + "desc": "Test question", + "options": [ + {"number": 1, "option": "Test option 1"}, + {"number": 2, "option": "Test option 2"}, + {"number": 3, "option": "Test option 3"} + ] + }, + "auth": "http://localhost:8000", + "census": [1] +} + +voting_json_mock_updated = { + "id": 1, + "name": "Test updated voting", + "desc": "Test updated voting description", + "question": { + "desc": "Test updated question", + "options": [ + {"number": 1, "desc": "Test option 1"}, + {"number": 2, "desc": "Test option 2"}, + ] + }, + "auth": "http://localhost:8080", + "census": [1] +} + + +def create_voting(self): + response = self.client.post(base_url + "/voting/", + voting_json_mock, format='json') + return response class AdministrationTestCase(APITestCase): def setUp(self): + super().setUp() self.client = APIClient() - user_admin = User(username='admin', is_staff=True, is_superuser=True) - user_admin.set_password('qwerty') - user_admin.save() + + admin_mock = User(username="admin", is_superuser=True) + admin_mock.set_password("qwerty") + admin_mock.save() + + url = base_url + "/auth/login" data = {'username': "admin", 'password': "qwerty"} - response = self.client.post('/administration/api/auth/login', data, format="json") - self.assertEqual(response.status_code, 200) + response = self.client.post(url, data, format="json") self.token = response.cookies.get('token', "") + + self.assertEqual(response.status_code, 200) self.assertTrue(self.token) def tearDown(self): - response = self.client.get('/administration/api/auth/logout') + super().tearDown() + + url = base_url + "/auth/logout" + response = self.client.get(url, format="json") + self.token = response.cookies.get('token', "") + self.assertEqual(response.status_code, 200) - self.token = response.COOKIES.get('token', "") - self.assertFalse(self.token) + self.assertEqual(self.token["expires"], + "Thu, 01 Jan 1970 00:00:00 GMT") + def test_get_dashboard_api(self): + url = base_url + '/dashboard' + response = self.client.get(url, format="json") + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data['votings'], { + "notStarted": 0, "inProgress": 0, "finished": 0}) + self.assertEqual(response.data['users'], { + "active": 1, "admins": 1, "employees": 0, "total": 1}) + + +''' def test_post_voting_api(self): - data = { - "name": "test", - "desc": "test", - "question": { - "desc": "test?", - "options": [ - {"number": 1, - "option": "prueba"}, - {"number": 2, - "option": "no prueba"}]}, - "census": [1], - "auth": "http://localhost:8000" - } - response = self.client.post('/administration/api/votings', data, format="json") + response = self.create_voting() + db_voting = Voting.objects.get(id=1) + + self.assertEqual(response.status_code, 200) + self.assertTrue(db_voting) + self.assertEqual(Voting.objects.count(), 1) + self.assertEqual(db_voting.desc, voting_json_mock.get("desc")) + self.assertEqual(db_voting.question.desc, + voting_json_mock.get("question").get("desc")) + self.assertEqual(db_voting.question.options.count(), 3) + self.assertEqual(db_voting.auth, voting_json_mock.get("auth")) + self.assertEqual(db_voting.census, [1]) + + def test_get_voting_api(self): + self.create_voting() + + url = base_url + "/votings" + response = self.client.get(url, format="json") + self.assertEqual(response.status_code, 200) - self.assertTrue(Voting.objects.all().First() is not None) + self.assertEqual(len(response.data), 1) + self.assertEqual(response.data[0]['id'], 1) + self.assertEqual(response.data[0]['name'], "Test voting") + self.assertEqual(response.data[0]['desc'], "Test description") + + def test_update_voting_api(self): + self.create_voting() + + url = base_url + "/votings/1" + data = voting_json_mock_updated + response = self.client.put( + url, voting_json_mock_updated, format="json") + db_voting = Voting.objects.get(id=1) + + self.assertEqual(response.status_code, 200) + self.assertTrue(db_voting) + self.assertEqual(db_voting.desc, data.get("desc")) + self.assertEqual(db_voting.question.desc, + data.get("question").get("desc")) + self.assertEqual(db_voting.question.options.count(), 2) + self.assertEqual(db_voting.auth, data.get("auth")) + self.assertEqual(db_voting.census, [1]) + + def test_delete_voting_api(self): + self.create_voting() + + url = base_url + "/votings/1" + response = self.client.delete(url, format="json") + + self.assertEqual(response.status_code, 200) + self.assertEqual(Voting.objects.count(), 0) + +''' diff --git a/decide/administration/views.py b/decide/administration/views.py index d09b8c0..be87aeb 100644 --- a/decide/administration/views.py +++ b/decide/administration/views.py @@ -92,6 +92,7 @@ def put(self, request): return Response({}, status=status.HTTP_400_BAD_REQUEST) msg = '' st = status.HTTP_200_OK + if action == 'start': votings = Voting.objects.filter( id__in=votings_id, start_date__isnull=True) @@ -104,7 +105,6 @@ def put(self, request): else: msg = 'All votings all already started' st = status.HTTP_400_BAD_REQUEST - elif action == 'stop': votings = Voting.objects.filter( id__in=votings_id, start_date__isnull=False, end_date__isnull=True) diff --git a/decide/decide/settings.py b/decide/decide/settings.py index 9bc12ec..8ddc641 100644 --- a/decide/decide/settings.py +++ b/decide/decide/settings.py @@ -24,6 +24,8 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True +ALLOWED_HOSTS = ['*'] + # Application definition From 78f133c788b34e34445d252c58e8367f620e1553 Mon Sep 17 00:00:00 2001 From: pedalopon Date: Sat, 8 Jan 2022 12:21:55 +0100 Subject: [PATCH 03/38] #43-test: Voting tests fixed and completed --- decide/administration/tests.py | 76 +++++++++++++++++----------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/decide/administration/tests.py b/decide/administration/tests.py index c67779f..96de823 100644 --- a/decide/administration/tests.py +++ b/decide/administration/tests.py @@ -1,10 +1,10 @@ from django.contrib.auth.models import User -from .serializers import AdminVotingGetSerializer -from voting.models import Voting +from census.models import Census +from .serializers import AdminVotingGetSerializer +from voting.models import Voting, QuestionOption from rest_framework.test import APITestCase, APIClient - # Create your tests here. base_url = "/administration/api" @@ -31,11 +31,11 @@ "desc": "Test description", "question": { "desc": "Test question", - "options": [ - {"number": 1, "option": "Test option 1"}, - {"number": 2, "option": "Test option 2"}, - {"number": 3, "option": "Test option 3"} - ] + "options": [ + {"number": 1, "option": "Test option 1"}, + {"number": 2, "option": "Test option 2"}, + {"number": 3, "option": "Test option 3"} + ] }, "auth": "http://localhost:8000", "census": [1] @@ -48,22 +48,22 @@ "question": { "desc": "Test updated question", "options": [ - {"number": 1, "desc": "Test option 1"}, - {"number": 2, "desc": "Test option 2"}, + {"number": 1, "option": "Test option 1"}, + {"number": 2, "option": "Test option 2"}, ] }, "auth": "http://localhost:8080", - "census": [1] + "census": [1] } -def create_voting(self): - response = self.client.post(base_url + "/voting/", - voting_json_mock, format='json') - return response - - class AdministrationTestCase(APITestCase): + def create_voting(self): + url = base_url + "/votings" + response = self.client.post(url, + voting_json_mock, format='json') + return response + def setUp(self): super().setUp() self.client = APIClient() @@ -97,25 +97,25 @@ def test_get_dashboard_api(self): self.assertEqual(response.status_code, 200) self.assertEqual(response.data['votings'], { - "notStarted": 0, "inProgress": 0, "finished": 0}) + "notStarted": 0, "inProgress": 0, "finished": 0}) self.assertEqual(response.data['users'], { - "active": 1, "admins": 1, "employees": 0, "total": 1}) + "active": 1, "admins": 1, "employees": 0, "total": 1}) - -''' def test_post_voting_api(self): response = self.create_voting() - db_voting = Voting.objects.get(id=1) + db_voting = Voting.objects.last() - self.assertEqual(response.status_code, 200) + self.assertEqual(response.status_code, 201) self.assertTrue(db_voting) self.assertEqual(Voting.objects.count(), 1) self.assertEqual(db_voting.desc, voting_json_mock.get("desc")) self.assertEqual(db_voting.question.desc, voting_json_mock.get("question").get("desc")) - self.assertEqual(db_voting.question.options.count(), 3) - self.assertEqual(db_voting.auth, voting_json_mock.get("auth")) - self.assertEqual(db_voting.census, [1]) + options = QuestionOption.objects.all().filter(question__pk=db_voting.question.id) + self.assertEqual(options.count(), 3) + self.assertEqual(db_voting.auths.all().first().url, voting_json_mock.get("auth")) + censuss = Census.objects.filter(voting_id=db_voting.id) + self.assertEqual([census.voter_id for census in censuss], [1]) def test_get_voting_api(self): self.create_voting() @@ -125,35 +125,33 @@ def test_get_voting_api(self): self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), 1) - self.assertEqual(response.data[0]['id'], 1) self.assertEqual(response.data[0]['name'], "Test voting") self.assertEqual(response.data[0]['desc'], "Test description") def test_update_voting_api(self): self.create_voting() - - url = base_url + "/votings/1" + db_voting = Voting.objects.last() + url = base_url + "/votings/" + str(db_voting.id) + "/" data = voting_json_mock_updated response = self.client.put( url, voting_json_mock_updated, format="json") - db_voting = Voting.objects.get(id=1) - + db_voting = Voting.objects.last() self.assertEqual(response.status_code, 200) self.assertTrue(db_voting) self.assertEqual(db_voting.desc, data.get("desc")) self.assertEqual(db_voting.question.desc, data.get("question").get("desc")) - self.assertEqual(db_voting.question.options.count(), 2) - self.assertEqual(db_voting.auth, data.get("auth")) - self.assertEqual(db_voting.census, [1]) + options = QuestionOption.objects.all().filter(question__pk=db_voting.question.id) + self.assertEqual(options.count(), 2) + self.assertEqual(db_voting.auths.all().first().url, data.get("auth")) + censuss = Census.objects.filter(voting_id=db_voting.id) + self.assertEqual([census.voter_id for census in censuss], [1]) def test_delete_voting_api(self): self.create_voting() - - url = base_url + "/votings/1" + db_voting = Voting.objects.last() + url = base_url + "/votings/" + str(db_voting.id) + "/" response = self.client.delete(url, format="json") self.assertEqual(response.status_code, 200) - self.assertEqual(Voting.objects.count(), 0) - -''' + self.assertEqual(Voting.objects.filter(id=db_voting.id).count(), 0) From db52fd4b36e3436bd5cf302fa12051d66596d09d Mon Sep 17 00:00:00 2001 From: pedalopon Date: Sat, 8 Jan 2022 12:27:30 +0100 Subject: [PATCH 04/38] #43-refactor: Change return status code of delete endpoints to 204 --- decide/administration/views.py | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/decide/administration/views.py b/decide/administration/views.py index 5ad3f86..fa1c036 100644 --- a/decide/administration/views.py +++ b/decide/administration/views.py @@ -135,12 +135,12 @@ def put(self, request): def delete(self, request): if request.data.get("idList") is None: Voting.objects.all().delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) else: ids = request.data.get("idList") is_valid(len(ids) > 0, 'The format of the ids list is not correct') Voting.objects.filter(id__in=ids).delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) class VotingsAPI(APIView): @@ -202,7 +202,7 @@ def put(self, request, voting_id): def delete(self, request, voting_id): Voting.objects.all().filter(id=voting_id).delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) class QuestionsAPI(APIView): @@ -223,12 +223,12 @@ def post(self, request): def delete(self, request): if request.data.get("idList") is None: Question.objects.all().delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) else: ids = request.data.get("idList") is_valid(len(ids) > 0, 'The format of the ids list is not correct') Question.objects.filter(id__in=ids).delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) class QuestionAPI(APIView): @@ -249,7 +249,7 @@ def put(self, request, question_id): def delete(self, request, question_id): Question.objects.all().filter(id=question_id).delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) class CensussAPI(APIView): @@ -294,7 +294,7 @@ def put(self, request, census_id): def delete(self, request, census_id): Census.objects.all().filter(id=census_id).delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) class AuthsAPI(APIView): @@ -313,12 +313,12 @@ def post(self, request): def delete(self, request): if request.data.get("idList") is None: Auth.objects.all().delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) else: ids = request.data.get("idList") is_valid(len(ids) > 0, 'The ids list can not be empty') Auth.objects.filter(id__in=ids).delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) class AuthAPI(APIView): @@ -340,7 +340,7 @@ def put(self, request, auth_id): def delete(self, request, auth_id): Auth.objects.all().filter(id=auth_id).delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) class KeysAPI(APIView): @@ -359,12 +359,12 @@ def post(self, request): def delete(self, request): if request.data.get("idList") is None: Key.objects.all().delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) else: ids = request.data.get("idList") is_valid(len(ids) > 0, 'The ids list can not be empty') Key.objects.filter(id__in=ids).delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) class KeyAPI(APIView): @@ -385,7 +385,7 @@ def put(self, request, key_id): def delete(self, request, key_id): Key.objects.all().filter(id=key_id).delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) class UsersAPI(APIView): @@ -414,7 +414,7 @@ def delete(self, request): ids = request.data.get("idList") is_valid(len(ids) > 0, 'The ids list can not be empty') User.objects.filter(id__in=ids).delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) class UserAPI(APIView): @@ -439,7 +439,7 @@ def put(self, request, user_id): def delete(self, request, user_id): User.objects.all().filter(is_superuser=False, id=user_id).delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) class LoginAuthAPI(APIView): From 98b8acff20adc60bf784262f8eb2b00eb5ef3b9b Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sat, 8 Jan 2022 12:51:56 +0100 Subject: [PATCH 05/38] #43-test: user test cases --- decide/administration/tests.py | 110 ++++++++++++++++++++++++++++++--- 1 file changed, 103 insertions(+), 7 deletions(-) diff --git a/decide/administration/tests.py b/decide/administration/tests.py index c67779f..083d004 100644 --- a/decide/administration/tests.py +++ b/decide/administration/tests.py @@ -10,15 +10,14 @@ base_url = "/administration/api" user_json_mock = { - "username": "admin", + "username": "mock", "password": "qwerty", - "email": "ad@admin.com", - "first_name": "admin", - "last_name": "admin", + "email": "mock@mock.com", + "first_name": "mock", + "last_name": "mock", } user_json_mock_updated = { - "id": 1, "username": "updated", "password": "updated", "email": "updated@admin.com", @@ -58,8 +57,18 @@ def create_voting(self): - response = self.client.post(base_url + "/voting/", + response = self.client.post(base_url + "/voting", voting_json_mock, format='json') + self.assertEqual(response.status_code, 200) + + return response + + +def create_user(self): + response = self.client.post(base_url + "/users", + user_json_mock, format='json') + self.assertEqual(response.status_code, 201) + return response @@ -68,7 +77,8 @@ def setUp(self): super().setUp() self.client = APIClient() - admin_mock = User(username="admin", is_superuser=True) + admin_mock = User(username="admin", + email="a@admin.com", is_superuser=True) admin_mock.set_password("qwerty") admin_mock.save() @@ -101,6 +111,92 @@ def test_get_dashboard_api(self): self.assertEqual(response.data['users'], { "active": 1, "admins": 1, "employees": 0, "total": 1}) + def test_create_user_api(self): + response = create_user(self) + db_user = User.objects.get(username="mock") + + self.assertTrue(db_user) + self.assertEqual(response.status_code, 201) + self.assertEqual(db_user.username, user_json_mock['username']) + self.assertEqual(db_user.email, user_json_mock['email']) + self.assertEqual(db_user.first_name, user_json_mock['first_name']) + self.assertEqual(db_user.last_name, user_json_mock['last_name']) + self.assertEqual(db_user.is_active, True) + self.assertEqual(db_user.is_superuser, False) + self.assertEqual(db_user.is_staff, False) + + def test_get_users_api(self): + url = base_url + '/users' + response = self.client.get(url, format="json") + user_count = User.objects.count() + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.data), user_count) + + def test_update_user_api(self): + create_user(self) + db_user_id = User.objects.get(username="mock").id + + url = base_url + '/users/' + str(db_user_id) + response = self.client.put(url, user_json_mock_updated, format="json") + self.assertEqual(response.status_code, 200) + + db_user = User.objects.get(username="updated") + self.assertEquals(db_user.id, db_user_id) + self.assertEqual(db_user.username, user_json_mock_updated['username']) + self.assertEqual(db_user.email, user_json_mock_updated['email']) + self.assertEqual(db_user.first_name, + user_json_mock_updated['first_name']) + self.assertEqual(db_user.last_name, + user_json_mock_updated['last_name']) + self.assertEqual(db_user.is_active, True) + self.assertEqual(db_user.is_superuser, False) + self.assertEqual(db_user.is_staff, False) + + def test_update_user_state_api(self): + create_user(self) + db_user_id = User.objects.get(username="mock").id + + data = { + "idList": [db_user_id], + "state": "Active", + "value": "False" + } + url = base_url + "/users/state" + response = self.client.post(url, data, format="json") + self.assertEqual(response.status_code, 200) + + data = { + "idList": [db_user_id], + "state": "Staff", + "value": "True" + } + response = self.client.post(url, data, format="json") + self.assertEqual(response.status_code, 200) + + data = { + "idList": [db_user_id], + "state": "Superuser", + "value": "True" + } + response = self.client.post(url, data, format="json") + self.assertEqual(response.status_code, 200) + + db_user = User.objects.get(username="mock") + self.assertTrue(db_user.is_superuser) + self.assertTrue(db_user.is_staff) + self.assertFalse(db_user.is_active) + + def test_delete_user_api(self): + create_user(self) + db_user_id = User.objects.get(username="mock").id + + url = base_url + '/users/' + str(db_user_id) + response = self.client.delete(url, format="json") + + self.assertEqual(response.status_code, 200) + self.assertEqual(User.objects.count(), 1) + ''' def test_post_voting_api(self): From a10e296fa4fcafb3952d6a931d0ca0cd822b86a5 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sat, 8 Jan 2022 13:14:33 +0100 Subject: [PATCH 06/38] #43-refactor: views.py imports --- decide/administration/views.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/decide/administration/views.py b/decide/administration/views.py index fa1c036..80937f6 100644 --- a/decide/administration/views.py +++ b/decide/administration/views.py @@ -1,19 +1,24 @@ +from django.contrib.auth.models import User from django.utils import timezone from django.shortcuts import render, get_object_or_404 -from rest_framework.status import * + +from rest_framework.status import HTTP_200_OK, HTTP_400_BAD_REQUEST, HTTP_204_NO_CONTENT, HTTP_201_CREATED, HTTP_403_FORBIDDEN from rest_framework import parsers, renderers, status from rest_framework.authtoken.models import Token from rest_framework.authtoken.serializers import AuthTokenSerializer from rest_framework.response import Response from rest_framework.views import APIView -from base.models import Auth, Key -from authentication.serializers import UserSerializer -from administration.serializers import * -from base.serializers import AuthSerializer, KeySerializer -from voting.serializers import VotingSerializer -from .serializers import CensusSerializer + from base.perms import IsAdminAPI -from voting.models import Question + +from base.serializers import KeySerializer, AuthSerializer +from voting.serializers import VotingSerializer +from .serializers import AdminQuestionSerializer, AdminVotingGetSerializer, AdminVotingSerializer, CensusSerializer, UserAdminSerializer, UserSerializer, UserUpdateSerializer + +from base.models import Auth, Key +from voting.models import Question, Voting, QuestionOption +from census.models import Census + from utils.utils import is_valid From 7b4d08e45dd1ecbd42f797ae4f9ed54a8107f55d Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sat, 8 Jan 2022 13:19:07 +0100 Subject: [PATCH 07/38] #43-test: bulk delete users --- decide/administration/tests.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/decide/administration/tests.py b/decide/administration/tests.py index 29b3319..7ad8d3b 100644 --- a/decide/administration/tests.py +++ b/decide/administration/tests.py @@ -103,6 +103,7 @@ def tearDown(self): self.assertEqual(self.token["expires"], "Thu, 01 Jan 1970 00:00:00 GMT") + #! DASHBOARD TESTS def test_get_dashboard_api(self): url = base_url + '/dashboard' response = self.client.get(url, format="json") @@ -113,6 +114,7 @@ def test_get_dashboard_api(self): self.assertEqual(response.data['users'], { "active": 1, "admins": 1, "employees": 0, "total": 1}) + #! USER TESTS def test_create_user_api(self): response = create_user(self) db_user = User.objects.get(username="mock") @@ -193,6 +195,7 @@ def test_update_user_state_api(self): def test_delete_user_api(self): create_user(self) + self.assertEqual(User.objects.count(), 2) db_user_id = User.objects.get(username="mock").id url = base_url + '/users/' + str(db_user_id) @@ -201,6 +204,21 @@ def test_delete_user_api(self): self.assertEqual(response.status_code, 204) self.assertEqual(User.objects.count(), 1) + def test_bulk_delete_users_api(self): + create_user(self) + self.assertEqual(User.objects.count(), 2) + db_user_id = User.objects.get(username="mock").id + + data = { + "idList": [db_user_id] + } + url = base_url + '/users' + response = self.client.delete(url, data, format="json") + + self.assertEqual(response.status_code, 204) + self.assertEqual(User.objects.count(), 1) + + #! VOTING TESTS def test_post_voting_api(self): response = create_voting(self) db_voting = Voting.objects.last() From 707815ab174fbc70023a2cd712d4a60c5bfda10d Mon Sep 17 00:00:00 2001 From: pedalopon Date: Sat, 8 Jan 2022 13:43:11 +0100 Subject: [PATCH 08/38] #43-test: Auth test --- decide/administration/tests.py | 109 +++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/decide/administration/tests.py b/decide/administration/tests.py index 96de823..4a192bb 100644 --- a/decide/administration/tests.py +++ b/decide/administration/tests.py @@ -1,5 +1,6 @@ from django.contrib.auth.models import User +from base.models import Auth from census.models import Census from .serializers import AdminVotingGetSerializer from voting.models import Voting, QuestionOption @@ -25,6 +26,23 @@ "first_name": "updated", "last_name": "updated", } +auth_json_mock = { + "name": "pruebaeeww", + "url": "http://localhost:8000", + "me": True +} + +auth_json_mock_update = { + "name": "update", + "url": "http://localhost:3000", + "me": False +} + +auth_json_mock_delete = { + "name": "pruebaeeww2222", + "url": "http://localhost:9000", + "me": False +} voting_json_mock = { "name": "Test voting", @@ -64,6 +82,12 @@ def create_voting(self): voting_json_mock, format='json') return response + def create_auth(self, data=auth_json_mock): + url = base_url + "/base/auth" + response = self.client.post(url, + data, format='json') + return response + def setUp(self): super().setUp() self.client = APIClient() @@ -117,6 +141,11 @@ def test_post_voting_api(self): censuss = Census.objects.filter(voting_id=db_voting.id) self.assertEqual([census.voter_id for census in censuss], [1]) + url = base_url + "/votings" + response = self.client.post(url, + {"question": ""}, format='json') + self.assertEqual(response.status_code, 400) + def test_get_voting_api(self): self.create_voting() @@ -147,6 +176,10 @@ def test_update_voting_api(self): censuss = Census.objects.filter(voting_id=db_voting.id) self.assertEqual([census.voter_id for census in censuss], [1]) + response = self.client.put(url, + {"name": "hola", "desc": ""}, format='json') + self.assertEqual(response.status_code, 400) + def test_delete_voting_api(self): self.create_voting() db_voting = Voting.objects.last() @@ -155,3 +188,79 @@ def test_delete_voting_api(self): self.assertEqual(response.status_code, 200) self.assertEqual(Voting.objects.filter(id=db_voting.id).count(), 0) + + def test_get_list_auth_api(self): + self.create_auth() + url = base_url + "/base/auth" + response = self.client.get(url, format="json") + self.assertEqual(len(response.data), Auth.objects.count()) + self.assertEqual(response.data[len(response.data) - 1]['name'], "pruebaeeww") + self.assertEqual(response.data[len(response.data) - 1]['url'], "http://localhost:8000") + self.assertEqual(response.data[len(response.data) - 1]['me'], True) + + def test_get_auth_api(self): + self.create_auth() + db_auth = Auth.objects.last() + url = base_url + "/base/auth/" + str(db_auth.id) + response = self.client.get(url, format="json") + self.assertEqual(response.data['name'], "pruebaeeww") + self.assertEqual(response.data['url'], "http://localhost:8000") + self.assertEqual(response.data['me'], True) + + def test_post_auth_api(self): + self.create_auth() + db_auth = Auth.objects.last() + self.assertEqual(auth_json_mock.get('name'), db_auth.name) + self.assertEqual(auth_json_mock.get('url'), db_auth.url) + self.assertEqual(auth_json_mock.get('me'), db_auth.me) + + url = base_url + "/base/auth" + response = self.client.post(url, + {"name": "hola"}, format='json') + self.assertEqual(response.status_code, 400) + + def test_put_auth_api(self): + self.create_auth() + db_auth = Auth.objects.last() + url = base_url + "/base/auth/" + str(db_auth.id) + response = self.client.put( + url, auth_json_mock_update, format="json") + db_auth = Auth.objects.last() + + self.assertEqual(response.status_code, 200) + self.assertEqual(auth_json_mock_update.get('name'), db_auth.name) + self.assertEqual(auth_json_mock_update.get('url'), db_auth.url) + self.assertEqual(auth_json_mock_update.get('me'), db_auth.me) + + response = self.client.put(url, + {"name": "hola"}, format='json') + self.assertEqual(response.status_code, 400) + + def test_delete_auth_api(self): + self.create_auth() + db_auth = Auth.objects.last() + + url = base_url + "/base/auth/" + str(db_auth.id) + response = self.client.delete(url, format="json") + + self.assertEqual(response.status_code, 204) + self.assertEqual(Voting.objects.filter(id=db_auth.id).count(), 0) + + def test_bulk_delete_auth_api(self): + self.create_auth() + self.create_auth(auth_json_mock_delete) + db_auth_id = Auth.objects.last().id + + url = base_url + "/base/auth" + id_list = [db_auth_id, db_auth_id - 1] + response = self.client.delete(url, {"idList": id_list}, format="json") + + self.assertEqual(response.status_code, 204) + self.assertEqual(Voting.objects.filter(id__in=id_list).count(), 0) + + self.create_auth() + self.create_auth(auth_json_mock_delete) + + response = self.client.delete(url, format="json") + self.assertEqual(response.status_code, 204) + self.assertEqual(Voting.objects.count(), 0) From 64c4fc947d85ec8b1866579e696ed48507258133 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sat, 8 Jan 2022 13:46:58 +0100 Subject: [PATCH 09/38] #43-test: keys --- decide/administration/tests.py | 81 ++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 3 deletions(-) diff --git a/decide/administration/tests.py b/decide/administration/tests.py index 7ad8d3b..904b6d2 100644 --- a/decide/administration/tests.py +++ b/decide/administration/tests.py @@ -1,11 +1,11 @@ from django.contrib.auth.models import User +from rest_framework.test import APITestCase, APIClient + from voting.models import Voting, QuestionOption from census.models import Census +from base.models import Auth, Key -from .serializers import AdminVotingGetSerializer - -from rest_framework.test import APITestCase, APIClient # Create your tests here. @@ -74,6 +74,19 @@ def create_user(self): return response +def create_key(self): + response = self.client.post(base_url + "/base/key", + { + "p": 9945, + "g": 7876878768, + "y": 876254876254, + "x": 675 + }, format='json') + self.assertEqual(response.status_code, 201) + + return response + + class AdministrationTestCase(APITestCase): def setUp(self): super().setUp() @@ -276,3 +289,65 @@ def test_delete_voting_api(self): self.assertEqual(response.status_code, 204) self.assertEqual(Voting.objects.filter(id=db_voting.id).count(), 0) + + #! KEY TESTS + def test_post_key_api(self): + response = create_key(self) + + self.assertEqual(response.status_code, 201) + self.assertEqual(Key.objects.count(), 1) + self.assertEqual(Key.objects.last().p, 9945) + + def test_get_keys_api(self): + create_key(self) + + url = base_url + "/base/key" + response = self.client.get(url, format="json") + + self.assertEqual(response.status_code, 200) + self.assertEqual(len(response.data), 1) + self.assertEqual(response.data[0]['p'], 9945) + + def test_bulk_delete_keys_api(self): + create_key(self) + self.assertEqual(Key.objects.count(), 1) + + data = { + "idList": [Key.objects.last().id] + } + url = base_url + "/base/key" + response = self.client.delete(url, data, format="json") + + self.assertEqual(response.status_code, 204) + self.assertEqual(Key.objects.count(), 0) + + def test_delete_key_api(self): + create_key(self) + self.assertEqual(Key.objects.count(), 1) + + db_key = Key.objects.last() + url = base_url + "/base/key/" + str(db_key.id) + response = self.client.delete(url, format="json") + + self.assertEqual(response.status_code, 204) + self.assertEqual(Key.objects.count(), 0) + + def test_update_key_api(self): + create_key(self) + db_key = Key.objects.last() + url = base_url + "/base/key/" + str(db_key.id) + data = { + "p": 5000, + "g": 7878787878, + "y": 8732482384744, + "x": 670 + } + response = self.client.put(url, data, format="json") + + db_key = Key.objects.last() + self.assertEqual(response.status_code, 200) + self.assertTrue(db_key) + self.assertEqual(db_key.p, 5000) + self.assertEqual(db_key.g, 7878787878) + self.assertEqual(db_key.y, 8732482384744) + self.assertEqual(db_key.x, 670) From 1971079105a491274dcf4179b11b3262030d2432 Mon Sep 17 00:00:00 2001 From: josaloroc Date: Sat, 8 Jan 2022 18:20:54 +0100 Subject: [PATCH 10/38] #76 - test: Implemented Question endpoints tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tested CRUD Operations for Question Co-Authored-By: Beatriz María Beltrán Álvarez --- decide/administration/tests.py | 115 ++++++++++++++++++++++++++++++++- 1 file changed, 112 insertions(+), 3 deletions(-) diff --git a/decide/administration/tests.py b/decide/administration/tests.py index 0352e28..e302a2f 100644 --- a/decide/administration/tests.py +++ b/decide/administration/tests.py @@ -2,11 +2,10 @@ from rest_framework.test import APITestCase, APIClient -from voting.models import Voting, QuestionOption +from voting.models import Voting, QuestionOption, Question from census.models import Census from base.models import Auth, Key - # Create your tests here. base_url = "/administration/api" @@ -73,7 +72,31 @@ "auth": "http://localhost:8080", "census": [1] } +question_json_mock = { + "id": 1, + "desc": "Test description", + "options": [ + {"number": 1, "option": "Test option 1"}, + {"number": 2, "option": "Test option 2"} + ] +} + +question_json_mock_updated = { + "id": 1, + "desc": "Test description updated", + "options": [ + {"number": 1, "option": "Test option 1 updated"}, + {"number": 2, "option": "Test option 2 updated"} + ] +} +question_json_mock_delete = { + "desc": "Test description delete", + "options": [ + {"number": 1, "option": "Test option 1 delete"}, + {"number": 2, "option": "Test option 2 delete"} + ] +} def create_voting(self): response = self.client.post(base_url + "/votings", @@ -112,6 +135,13 @@ def create_key(self): return response +def create_question(self): + response = self.client.post(base_url + "/votings/question", + question_json_mock, format="json") + self.assertEqual(response.status_code, 201) + return response + + class AdministrationTestCase(APITestCase): def setUp(self): super().setUp() @@ -324,7 +354,7 @@ def test_delete_voting_api(self): self.assertEqual(response.status_code, 204) self.assertEqual(Voting.objects.filter(id=db_voting.id).count(), 0) - #! KEY TESTS + # ! KEY TESTS def test_post_key_api(self): response = create_key(self) @@ -462,3 +492,82 @@ def test_bulk_delete_auth_api(self): response = self.client.delete(url, format="json") self.assertEqual(response.status_code, 204) self.assertEqual(Voting.objects.count(), 0) + + #! QUESTION TESTS + def test_get_list_question_api(self): + create_question(self) + url = base_url + "/votings/question" + response = self.client.get(url, format="json") + self.assertEqual(len(response.data), Question.objects.count()) + self.assertEqual(response.data[len(response.data) - 1]['desc'], "Test description") + self.assertEqual(response.data[len(response.data) - 1]['options'][0].get("option"), "Test option 1") + self.assertEqual(response.data[len(response.data) - 1]['options'][1].get("option"), "Test option 2") + self.assertEqual(response.data[len(response.data) - 1]['options'][0].get("number"), 1) + self.assertEqual(response.data[len(response.data) - 1]['options'][1].get("number"), 2) + + def test_get_question_api(self): + create_question(self) + db_question = Question.objects.last() + + url = base_url + "/votings/question/" + str(db_question.id) +"/" + response = self.client.get(url, format="json") + self.assertEqual(response.data['desc'], "Test description") + self.assertEqual(response.data['options'][0].get("option"), "Test option 1") + self.assertEqual(response.data['options'][1].get("option"), "Test option 2") + self.assertEqual(response.data['options'][0].get("number"), 1) + self.assertEqual(response.data['options'][1].get("number"), 2) + + + def test_post_question_api(self): + create_question(self) + db_question = Question.objects.last() + self.assertEqual(db_question.desc, question_json_mock.get("desc")) + options = QuestionOption.objects.all().filter(question__pk=db_question.id) + self.assertEqual(options.count(), 2) + + url = base_url + "/votings/question" + response = self.client.post(url, + {"desc":"Test description"}, format="json") + self.assertEqual(response.status_code, 400) + + + def test_put_question_api(self): + create_question(self) + db_question = Question.objects.last() + url = base_url + "/votings/question/" + str(db_question.id) + "/" + response = self.client.put( + url, question_json_mock_updated, format="json") + db_question = Question.objects.last() + + self.assertEqual(response.status_code, 200) + self.assertEqual(question_json_mock_updated.get('desc'), db_question.desc) + options = QuestionOption.objects.all().filter(question__pk=db_question.id) + self.assertEqual(question_json_mock_updated.get('options')[0]["option"], options.values("option")[0]["option"]) + self.assertEqual(question_json_mock_updated.get('options')[1]["option"], options.values("option")[1]["option"]) + + response = self.client.put(url, + {"desc": "Test description 1 update"}, format='json') + self.assertEqual(response.status_code, 400) + + def test_delete_question_api(self): + create_question(self) + db_question = Question.objects.last() + + url = base_url + "/votings/question/" + str(db_question.id) + "/" + response = self.client.delete(url, format = "json") + + self.assertEqual(response.status_code,204) + self.assertEqual(Question.objects.filter(id=db_question.id).count(),0) + + def test_bulk_delete_question_api(self): + create_question(self) + self.assertEqual(Question.objects.count(), 1) + + data = { + "idList": [Question.objects.last().id] + } + url = base_url + "/votings/question" + response = self.client.delete(url, data, format="json") + + self.assertEqual(response.status_code, 204) + self.assertEqual(Question.objects.count(), 0) \ No newline at end of file From a15289c1aa55354e28befd0118fcd25ab7a81252 Mon Sep 17 00:00:00 2001 From: josaloroc Date: Sat, 8 Jan 2022 19:51:43 +0100 Subject: [PATCH 11/38] #77 - feat: Added test endpoints for census MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: José Luis Alonso Rocha --- decide/administration/tests.py | 92 +++++++++++++++++++++++++++++++++- 1 file changed, 90 insertions(+), 2 deletions(-) diff --git a/decide/administration/tests.py b/decide/administration/tests.py index e302a2f..219b5ad 100644 --- a/decide/administration/tests.py +++ b/decide/administration/tests.py @@ -97,6 +97,20 @@ {"number": 2, "option": "Test option 2 delete"} ] } +census_json_mock = { + "voting_id": 1, + "voter_id": 1 +} + +census_json_mock_updated = { + "voting_id": 2, + "voter_id": 2 +} + +census_json_mock_delete = { + "voting_id": 1, + "voter_id": 1 +} def create_voting(self): response = self.client.post(base_url + "/votings", @@ -142,6 +156,12 @@ def create_question(self): return response +def create_census(self): + response = self.client.post(base_url + "/census", + census_json_mock, format="json") + self.assertEqual(response.status_code, 201) + return response + class AdministrationTestCase(APITestCase): def setUp(self): super().setUp() @@ -416,7 +436,7 @@ def test_update_key_api(self): self.assertEqual(db_key.y, 8732482384744) self.assertEqual(db_key.x, 670) - # ! AUTH TESTS + #!AUTH TESTS def test_get_list_auth_api(self): create_auth(self) url = base_url + "/base/auth" @@ -570,4 +590,72 @@ def test_bulk_delete_question_api(self): response = self.client.delete(url, data, format="json") self.assertEqual(response.status_code, 204) - self.assertEqual(Question.objects.count(), 0) \ No newline at end of file + self.assertEqual(Question.objects.count(), 0) + + #! CENSUS TESTS + def test_get_list_census_api(self): + create_census(self) + url = base_url + "/census" + response = self.client.get(url, format="json") + self.assertEqual(len(response.data), Census.objects.count()) + self.assertEqual(response.data[len(response.data) - 1]['voting_id'], 1) + self.assertEqual(response.data[len(response.data) - 1]['voter_id'], 1) + + def test_get_census_api(self): + create_census(self) + db_census = Census.objects.last() + + url = base_url + "/census/" + str(db_census.id) + response = self.client.get(url, format="json") + self.assertEqual(response.data['voting_id'], 1) + self.assertEqual(response.data['voter_id'], 1) + + def test_post_census_api(self): + create_census(self) + db_census = Census.objects.last() + self.assertEqual(db_census.voting_id, census_json_mock.get("voting_id")) + self.assertEqual(db_census.voter_id, census_json_mock.get("voter_id")) + + url = base_url + "/census" + response = self.client.post(url, + {"desc":"Test description"}, format="json") + self.assertEqual(response.status_code, 400) + + def test_put_census_api(self): + create_census(self) + db_census = Census.objects.last() + url = base_url + "/census/" + str(db_census.id) + response = self.client.put( + url, census_json_mock_updated, format="json") + db_census = Census.objects.last() + + self.assertEqual(response.status_code, 200) + self.assertEqual(census_json_mock_updated.get('voting_id'), db_census.voting_id) + self.assertEqual(census_json_mock_updated.get('voter_id'), db_census.voter_id) + + response = self.client.put(url, + {"voting_id": 2}, format='json') + self.assertEqual(response.status_code, 400) + + def test_delete_census_api(self): + create_census(self) + db_census = Census.objects.last() + + url = base_url + "/census/" + str(db_census.id) + response = self.client.delete(url, format = "json") + + self.assertEqual(response.status_code,204) + self.assertEqual(Census.objects.filter(id=db_census.id).count(),0) + + def test_bulk_delete_census_api(self): + create_census(self) + self.assertEqual(Census.objects.count(), 1) + + data = { + "idList": [Census.objects.last().id] + } + url = base_url + "/census" + response = self.client.delete(url, data, format="json") + self.assertEqual(Census.objects.count(), 0) + + From aeb101c906e7e6a8950c8d6041b999bed8a29da4 Mon Sep 17 00:00:00 2001 From: josaloroc Date: Sat, 8 Jan 2022 20:05:52 +0100 Subject: [PATCH 12/38] #11 - fix: Fixed minor bug in census bulk delete for testing Added .data to request to get the correct idList --- decide/administration/views.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/decide/administration/views.py b/decide/administration/views.py index 80937f6..b41d05d 100644 --- a/decide/administration/views.py +++ b/decide/administration/views.py @@ -275,7 +275,7 @@ def delete(self, request): Census.objects.all().delete() return Response({}, status=HTTP_200_OK) else: - ids = request.get("idList") + ids = request.data.get("idList") Census.objects.filter(id__in=ids).delete() return Response({}, status=HTTP_200_OK) From e7ef01504077104c19cb26e4f0724a52ed8e44f7 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sat, 8 Jan 2022 22:08:08 +0100 Subject: [PATCH 13/38] #43-test: improve coverage --- decide/administration/tests.py | 242 +++++++++++++++++++++++++++------ decide/administration/urls.py | 4 +- decide/administration/views.py | 4 +- 3 files changed, 208 insertions(+), 42 deletions(-) diff --git a/decide/administration/tests.py b/decide/administration/tests.py index 219b5ad..8270440 100644 --- a/decide/administration/tests.py +++ b/decide/administration/tests.py @@ -70,7 +70,7 @@ ] }, "auth": "http://localhost:8080", - "census": [1] + "census": [1, 2] } question_json_mock = { "id": 1, @@ -91,8 +91,8 @@ } question_json_mock_delete = { - "desc": "Test description delete", - "options": [ + "desc": "Test description delete", + "options": [ {"number": 1, "option": "Test option 1 delete"}, {"number": 2, "option": "Test option 2 delete"} ] @@ -112,6 +112,7 @@ "voter_id": 1 } + def create_voting(self): response = self.client.post(base_url + "/votings", voting_json_mock, format='json') @@ -151,7 +152,7 @@ def create_key(self): def create_question(self): response = self.client.post(base_url + "/votings/question", - question_json_mock, format="json") + question_json_mock, format="json") self.assertEqual(response.status_code, 201) return response @@ -162,6 +163,7 @@ def create_census(self): self.assertEqual(response.status_code, 201) return response + class AdministrationTestCase(APITestCase): def setUp(self): super().setUp() @@ -191,6 +193,11 @@ def tearDown(self): self.assertEqual(self.token["expires"], "Thu, 01 Jan 1970 00:00:00 GMT") + # ! INDEX TESTS + def test_get_index_page(self): + response = self.client.get(base_url, format="json") + self.assertEqual(response.status_code, 200) + # ! DASHBOARD TESTS def test_get_dashboard_api(self): url = base_url + '/dashboard' @@ -227,6 +234,22 @@ def test_get_users_api(self): self.assertEqual(response.status_code, 200) self.assertEqual(len(response.data), user_count) + def test_get_user_api(self): + create_user(self) + db_user = User.objects.get(username="mock") + + url = base_url + '/users/' + str(db_user.id) + response = self.client.get(url, format="json") + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data['username'], db_user.username) + self.assertEqual(response.data['email'], db_user.email) + self.assertEqual(response.data['first_name'], db_user.first_name) + self.assertEqual(response.data['last_name'], db_user.last_name) + self.assertEqual(response.data['is_active'], db_user.is_active) + self.assertEqual(response.data['is_superuser'], db_user.is_superuser) + self.assertEqual(response.data['is_staff'], db_user.is_staff) + def test_update_user_api(self): create_user(self) db_user_id = User.objects.get(username="mock").id @@ -276,6 +299,14 @@ def test_update_user_state_api(self): response = self.client.post(url, data, format="json") self.assertEqual(response.status_code, 200) + data = { + "idList": [db_user_id], + "state": "Rare", + "value": "True" + } + response = self.client.post(url, data, format="json") + self.assertEqual(response.status_code, 400) + db_user = User.objects.get(username="mock") self.assertTrue(db_user.is_superuser) self.assertTrue(db_user.is_staff) @@ -307,6 +338,7 @@ def test_bulk_delete_users_api(self): self.assertEqual(User.objects.count(), 1) # ! VOTING TESTS + def test_post_voting_api(self): response = create_voting(self) db_voting = Voting.objects.last() @@ -330,7 +362,7 @@ def test_post_voting_api(self): {"question": ""}, format='json') self.assertEqual(response.status_code, 400) - def test_get_voting_api(self): + def test_get_votings_api(self): create_voting(self) url = base_url + "/votings" @@ -341,10 +373,21 @@ def test_get_voting_api(self): self.assertEqual(response.data[0]['name'], "Test voting") self.assertEqual(response.data[0]['desc'], "Test description") + def test_get_voting_api(self): + create_voting(self) + db_voting_id = Voting.objects.last().id + + url = base_url + "/votings/" + str(db_voting_id) + response = self.client.get(url, format="json") + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data['name'], "Test voting") + self.assertEqual(response.data['desc'], "Test description") + def test_update_voting_api(self): create_voting(self) db_voting = Voting.objects.last() - url = base_url + "/votings/" + str(db_voting.id) + "/" + url = base_url + "/votings/" + str(db_voting.id) data = voting_json_mock_updated response = self.client.put( url, voting_json_mock_updated, format="json") @@ -359,22 +402,92 @@ def test_update_voting_api(self): self.assertEqual(options.count(), 2) self.assertEqual(db_voting.auths.all().first().url, data.get("auth")) censuss = Census.objects.filter(voting_id=db_voting.id) - self.assertEqual([census.voter_id for census in censuss], [1]) + self.assertEqual([census.voter_id for census in censuss], [1, 2]) response = self.client.put(url, {"name": "hola", "desc": ""}, format='json') self.assertEqual(response.status_code, 400) + # def test_update_status_voting_api(self): + # create_voting(self) + + # db_voting_id = Voting.objects.last().id + # url = base_url + "/votings" + # data = { + # "action": "start", + # "idList": [db_voting_id], + # } + # response = self.client.put(url, data, format="json") + # self.assertEqual(response.status_code, 200) + + # db_voting = Voting.objects.get(id=db_voting_id) + # self.assertTrue(db_voting.start_date is not None) + + # data = { + # "action": "stop", + # "idList": [db_voting.id], + # } + # response = self.client.put(url, data, format="json") + # self.assertEqual(response.status_code, 200) + + # db_voting = Voting.objects.get(id=db_voting_id) + # self.assertTrue(db_voting.start_date is not None) + # self.assertTrue(db_voting.end_date is not None) + + # data = { + # "action": "tally", + # "idList": [db_voting.id], + # } + # response = self.client.put(url, data, format="json") + # self.assertEqual(response.status_code, 200) + + # db_voting = Voting.objects.get(id=db_voting_id) + # self.assertTrue(db_voting.start_date is not None) + # self.assertTrue(db_voting.end_date is not None) + # self.assertTrue(db_voting.tally is not None) + + # data = { + # "action": "rare", + # "idList": [db_voting.id], + # } + # response = self.client.put(url, data, format="json") + # self.assertEqual(response.status_code, 400) + + def test_bulk_delete_voting_api(self): + create_voting(self) + db_voting = Voting.objects.last() + + data = { + "idList": [db_voting.id], + } + url = base_url + "/votings" + response = self.client.delete(url, data, format="json") + + self.assertEqual(response.status_code, 204) + self.assertEqual(Voting.objects.filter(id=db_voting.id).count(), 0) + + create_voting(self) + Voting.objects.last() + self.assertEqual(Voting.objects.count(), 1) + + url = base_url + "/votings" + response = self.client.delete(url, format="json") + + self.assertEqual(response.status_code, 204) + self.assertEqual(Voting.objects.count(), 0) + def test_delete_voting_api(self): create_voting(self) db_voting = Voting.objects.last() - url = base_url + "/votings/" + str(db_voting.id) + "/" + + url = base_url + "/votings/" + str(db_voting.id) response = self.client.delete(url, format="json") self.assertEqual(response.status_code, 204) self.assertEqual(Voting.objects.filter(id=db_voting.id).count(), 0) # ! KEY TESTS + def test_post_key_api(self): response = create_key(self) @@ -392,6 +505,16 @@ def test_get_keys_api(self): self.assertEqual(len(response.data), 1) self.assertEqual(response.data[0]['p'], 9945) + def test_get_key_api(self): + create_key(self) + db_key_id = Key.objects.last().id + + url = base_url + "/base/key/" + str(db_key_id) + response = self.client.get(url, format="json") + + self.assertEqual(response.status_code, 200) + self.assertEqual(response.data['p'], 9945) + def test_bulk_delete_keys_api(self): create_key(self) self.assertEqual(Key.objects.count(), 1) @@ -405,7 +528,6 @@ def test_bulk_delete_keys_api(self): self.assertEqual(response.status_code, 204) self.assertEqual(Key.objects.count(), 0) - def test_delete_key_api(self): create_key(self) self.assertEqual(Key.objects.count(), 1) @@ -416,6 +538,25 @@ def test_delete_key_api(self): self.assertEqual(response.status_code, 204) self.assertEqual(Key.objects.count(), 0) + create_key(self) + self.assertEqual(Key.objects.count(), 1) + + url = base_url + "/base/key" + response = self.client.delete(url, format="json") + + self.assertEqual(response.status_code, 204) + self.assertEqual(Key.objects.count(), 0) + + def test_delete_key_api(self): + create_key(self) + db_key = Key.objects.last() + + url = base_url + "/base/key/" + str(db_key.id) + response = self.client.delete(url, format="json") + + self.assertEqual(response.status_code, 204) + self.assertEqual(Key.objects.count(), 0) + def test_update_key_api(self): create_key(self) db_key = Key.objects.last() @@ -442,8 +583,10 @@ def test_get_list_auth_api(self): url = base_url + "/base/auth" response = self.client.get(url, format="json") self.assertEqual(len(response.data), Auth.objects.count()) - self.assertEqual(response.data[len(response.data) - 1]['name'], "pruebaeeww") - self.assertEqual(response.data[len(response.data) - 1]['url'], "http://localhost:8000") + self.assertEqual( + response.data[len(response.data) - 1]['name'], "pruebaeeww") + self.assertEqual( + response.data[len(response.data) - 1]['url'], "http://localhost:8000") self.assertEqual(response.data[len(response.data) - 1]['me'], True) def test_get_auth_api(self): @@ -519,25 +662,31 @@ def test_get_list_question_api(self): url = base_url + "/votings/question" response = self.client.get(url, format="json") self.assertEqual(len(response.data), Question.objects.count()) - self.assertEqual(response.data[len(response.data) - 1]['desc'], "Test description") - self.assertEqual(response.data[len(response.data) - 1]['options'][0].get("option"), "Test option 1") - self.assertEqual(response.data[len(response.data) - 1]['options'][1].get("option"), "Test option 2") - self.assertEqual(response.data[len(response.data) - 1]['options'][0].get("number"), 1) - self.assertEqual(response.data[len(response.data) - 1]['options'][1].get("number"), 2) + self.assertEqual( + response.data[len(response.data) - 1]['desc'], "Test description") + self.assertEqual(response.data[len( + response.data) - 1]['options'][0].get("option"), "Test option 1") + self.assertEqual(response.data[len( + response.data) - 1]['options'][1].get("option"), "Test option 2") + self.assertEqual( + response.data[len(response.data) - 1]['options'][0].get("number"), 1) + self.assertEqual( + response.data[len(response.data) - 1]['options'][1].get("number"), 2) def test_get_question_api(self): create_question(self) db_question = Question.objects.last() - url = base_url + "/votings/question/" + str(db_question.id) +"/" + url = base_url + "/votings/question/" + str(db_question.id) response = self.client.get(url, format="json") self.assertEqual(response.data['desc'], "Test description") - self.assertEqual(response.data['options'][0].get("option"), "Test option 1") - self.assertEqual(response.data['options'][1].get("option"), "Test option 2") + self.assertEqual(response.data['options'] + [0].get("option"), "Test option 1") + self.assertEqual(response.data['options'] + [1].get("option"), "Test option 2") self.assertEqual(response.data['options'][0].get("number"), 1) self.assertEqual(response.data['options'][1].get("number"), 2) - def test_post_question_api(self): create_question(self) db_question = Question.objects.last() @@ -547,23 +696,25 @@ def test_post_question_api(self): url = base_url + "/votings/question" response = self.client.post(url, - {"desc":"Test description"}, format="json") + {"desc": "Test description"}, format="json") self.assertEqual(response.status_code, 400) - def test_put_question_api(self): create_question(self) db_question = Question.objects.last() - url = base_url + "/votings/question/" + str(db_question.id) + "/" + url = base_url + "/votings/question/" + str(db_question.id) response = self.client.put( url, question_json_mock_updated, format="json") db_question = Question.objects.last() self.assertEqual(response.status_code, 200) - self.assertEqual(question_json_mock_updated.get('desc'), db_question.desc) + self.assertEqual(question_json_mock_updated.get( + 'desc'), db_question.desc) options = QuestionOption.objects.all().filter(question__pk=db_question.id) - self.assertEqual(question_json_mock_updated.get('options')[0]["option"], options.values("option")[0]["option"]) - self.assertEqual(question_json_mock_updated.get('options')[1]["option"], options.values("option")[1]["option"]) + self.assertEqual(question_json_mock_updated.get('options')[ + 0]["option"], options.values("option")[0]["option"]) + self.assertEqual(question_json_mock_updated.get('options')[ + 1]["option"], options.values("option")[1]["option"]) response = self.client.put(url, {"desc": "Test description 1 update"}, format='json') @@ -573,11 +724,11 @@ def test_delete_question_api(self): create_question(self) db_question = Question.objects.last() - url = base_url + "/votings/question/" + str(db_question.id) + "/" - response = self.client.delete(url, format = "json") + url = base_url + "/votings/question/" + str(db_question.id) + response = self.client.delete(url, format="json") - self.assertEqual(response.status_code,204) - self.assertEqual(Question.objects.filter(id=db_question.id).count(),0) + self.assertEqual(response.status_code, 204) + self.assertEqual(Question.objects.filter(id=db_question.id).count(), 0) def test_bulk_delete_question_api(self): create_question(self) @@ -592,7 +743,13 @@ def test_bulk_delete_question_api(self): self.assertEqual(response.status_code, 204) self.assertEqual(Question.objects.count(), 0) - #! CENSUS TESTS + create_question(self) + self.assertEqual(Question.objects.count(), 1) + + response = self.client.delete(url, format="json") + self.assertEqual(response.status_code, 204) + + # ! CENSUS TESTS def test_get_list_census_api(self): create_census(self) url = base_url + "/census" @@ -613,12 +770,13 @@ def test_get_census_api(self): def test_post_census_api(self): create_census(self) db_census = Census.objects.last() - self.assertEqual(db_census.voting_id, census_json_mock.get("voting_id")) + self.assertEqual(db_census.voting_id, + census_json_mock.get("voting_id")) self.assertEqual(db_census.voter_id, census_json_mock.get("voter_id")) url = base_url + "/census" response = self.client.post(url, - {"desc":"Test description"}, format="json") + {"desc": "Test description"}, format="json") self.assertEqual(response.status_code, 400) def test_put_census_api(self): @@ -630,8 +788,10 @@ def test_put_census_api(self): db_census = Census.objects.last() self.assertEqual(response.status_code, 200) - self.assertEqual(census_json_mock_updated.get('voting_id'), db_census.voting_id) - self.assertEqual(census_json_mock_updated.get('voter_id'), db_census.voter_id) + self.assertEqual(census_json_mock_updated.get( + 'voting_id'), db_census.voting_id) + self.assertEqual(census_json_mock_updated.get( + 'voter_id'), db_census.voter_id) response = self.client.put(url, {"voting_id": 2}, format='json') @@ -642,10 +802,10 @@ def test_delete_census_api(self): db_census = Census.objects.last() url = base_url + "/census/" + str(db_census.id) - response = self.client.delete(url, format = "json") + response = self.client.delete(url, format="json") - self.assertEqual(response.status_code,204) - self.assertEqual(Census.objects.filter(id=db_census.id).count(),0) + self.assertEqual(response.status_code, 204) + self.assertEqual(Census.objects.filter(id=db_census.id).count(), 0) def test_bulk_delete_census_api(self): create_census(self) @@ -656,6 +816,12 @@ def test_bulk_delete_census_api(self): } url = base_url + "/census" response = self.client.delete(url, data, format="json") + self.assertEqual(response.status_code, 204) self.assertEqual(Census.objects.count(), 0) + create_census(self) + self.assertEqual(Census.objects.count(), 1) + response = self.client.delete(url, format="json") + self.assertEqual(response.status_code, 204) + self.assertEqual(Census.objects.count(), 0) diff --git a/decide/administration/urls.py b/decide/administration/urls.py index d14f168..2447a59 100644 --- a/decide/administration/urls.py +++ b/decide/administration/urls.py @@ -19,9 +19,9 @@ path('api/census/', views.CensusAPI.as_view()), path('api/users/state', views.UpdateUserStateAPI.as_view()), path('api/votings/question', views.QuestionsAPI.as_view()), - path('api/votings/question//', views.QuestionAPI.as_view()), + path('api/votings/question/', views.QuestionAPI.as_view()), path('api/votings', views.VotingAPI.as_view()), - path('api/votings//', views.VotingsAPI.as_view()), + path('api/votings/', views.VotingsAPI.as_view()), # react-app url('', views.index) ] diff --git a/decide/administration/views.py b/decide/administration/views.py index b41d05d..7ce9408 100644 --- a/decide/administration/views.py +++ b/decide/administration/views.py @@ -273,11 +273,11 @@ def post(self, request): def delete(self, request): if request.data.get("idList") is None: Census.objects.all().delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) else: ids = request.data.get("idList") Census.objects.filter(id__in=ids).delete() - return Response({}, status=HTTP_200_OK) + return Response({}, status=HTTP_204_NO_CONTENT) class CensusAPI(APIView): From 773542de2958723f829f911a4a74e3c27f402302 Mon Sep 17 00:00:00 2001 From: Fernando Date: Sat, 8 Jan 2022 22:52:37 +0100 Subject: [PATCH 14/38] #93-test: Implement User tests with Selenium --- decide/administration/testSelenium.py | 191 ++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 decide/administration/testSelenium.py diff --git a/decide/administration/testSelenium.py b/decide/administration/testSelenium.py new file mode 100644 index 0000000..65f9952 --- /dev/null +++ b/decide/administration/testSelenium.py @@ -0,0 +1,191 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +import time +import random + +'''Para poder ejecutar este test, se debe crear un superusuario +con el siguiente comando: + +./manage.py createsuperuser + +con datos: + Username: admin + password: qwerty +y hacer bypass de la restriccion de contraseña + +Entrar en http://localhost:8000/administration/users +iniciar sesión con el usuario admin +y si hubiera más usuarios creados, hay que eliminarlos +antes de realizar los tests +''' + + +#USER TESTS +def log_in(driver, cont): + try: + print("Test LogIn") + time.sleep(2) + driver.get('http://localhost:8000/administration/') + time.sleep(2) + driver.find_element(By.XPATH,'//*[@id="content"]/div/form/div[1]/div/input').send_keys("admin") + driver.find_element(By.XPATH,'//*[@id="content"]/div/form/div[2]/div/input').send_keys("qwerty") + driver.find_element(By.XPATH,'//*[@id="content"]/div/form/button').click() + time.sleep(2) + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont +1 + return cont + +def log_out(driver, cont): + try: + print("Test LogOut") + driver.get('http://localhost:8000/administration/') + time.sleep(2) + driver.find_element(By.XPATH, '//*[@id="root"]/div/div[1]/button').click() + time.sleep(1) + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont +1 + return cont + + +def incorrect_log_in(driver, cont): + try: + print("Test LogIn Incorrecto") + driver.get('http://localhost:8000/administration/') + driver.find_element(By.XPATH, '//*[@id="content"]/div/form/div[1]/div/input').send_keys("badadmin") + driver.find_element(By.XPATH, '//*[@id="content"]/div/form/div[2]/div/input').send_keys("qwerty") + driver.find_element(By.XPATH, '//*[@id="content"]/div/form/button').click() + time.sleep(1) + elemento = driver.find_element(By.XPATH,'//*[@id="content"]/div/form/div[2]/p') + error_text = 'Unable to log in with provided credentials.' + if elemento.text == error_text: + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont +1 + return cont + + +def create_user(driver, cont): + try: + print("Test Create User") + time.sleep(1) + driver.get("http://localhost:8000/administration/users") + time.sleep(4) + driver.find_element(By.XPATH, '//*[@id="actions"]/div/button[1]').click() + time.sleep(4) + numalea = str(random.randint(0,9)) + str(random.randint(0,9))+ str(random.randint(0,9)) + username = str("nuevouser"+ str(numalea)) + driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[1]/div/input').send_keys(username) + driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[2]/div/input').send_keys("passwordNew") + driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[3]/div/input').send_keys("Nueva") + driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[4]/div/input').send_keys("Cuenta") + driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[5]/div/input').send_keys("email@gmail.com") + time.sleep(2) + driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/form/div[2]/button').click() + time.sleep(5) + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont +1 + return cont + + +def make_staff(driver, cont): + try: + driver.get("http://localhost:8000/administration/users") + print("Test hacer staff") + driver.find_element(By.XPATH,'//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() + time.sleep(2) + driver.find_element(By.XPATH, '//*[@id="actions"]/div/button[5]').click() + #driver.find_element(By.XPATH, '') + print("Test correctamente realizado\n") + + return cont + except Exception as e: + print("Error") + print(e) + cont = cont +1 + return cont + +def make_superuser(driver, cont): + try: + driver.get("http://localhost:8000/administration/users") + print("Test hacer superuser") + driver.find_element(By.XPATH,'//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() + time.sleep(2) + driver.find_element(By.XPATH, '//*[@id="actions"]/div/button[6]').click() + #print(element) + #driver.find_element(By.XPATH, '') + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont +1 + return cont + + +def delete_user(driver, cont): + try: + driver.get("http://localhost:8000/administration/users") + print("Test borrar usuario") + driver.find_element(By.XPATH,'//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() + time.sleep(2) + driver.find_element(By.XPATH, '//*[@id="actions"]/div/button[3]').click() + time.sleep(1) + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont +1 + return cont + + +def base(driver, cont): + try: + print("Test") + driver.find_element(By.XPATH, '') + return cont + except : + print("Error") + cont = cont +1 + return cont + + +if __name__ == "__main__": + cont = 0 + options = webdriver.ChromeOptions() + driver = webdriver.Chrome(options=options) + + #USER TESTS + cont = incorrect_log_in(driver, cont) + cont = log_in(driver, cont) + cont = create_user(driver, cont) + cont = create_user(driver, cont) + cont = create_user(driver, cont) + cont = create_user(driver, cont) + time.sleep(2) + cont = make_staff(driver, cont) + time.sleep(2) + cont = make_superuser(driver, cont) + time.sleep(3) + cont = delete_user(driver, cont) + cont = log_out(driver, cont) + + print("Se han realizado Test de FrontEnd") + print("Se han encontrado: "+ str(cont) + " errores ") + + \ No newline at end of file From b7e70bf3c655f207936cc3559b5afc387efcc0ce Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 00:09:34 +0100 Subject: [PATCH 15/38] #43-fix: add migrations to django workflow --- .github/workflows/django.yml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index b7175a7..08124a4 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -37,9 +37,23 @@ jobs: run: | python -m pip install --upgrade pip pip install -r requirements.txt + pip install codacy-coverage + - name: Migrate + run: | + cd decide + python manage.py + makemigrations + python manage.py migrate - name: Copy local_settings run: | cp ./decide/local_settings.example.py ./decide/local_settings.py - name: Test administration module run: | - python ./decide/manage.py test administration \ No newline at end of file + cd decide + coverage run --branch --source=./administration/ ./manage.py test administration --keepdb --verbosity=2 + coverage xml + - name: Codacy Coverage Reporter + uses: codacy/codacy-coverage-reporter-action@v1.1.0 + with: + project-token: ${{ secrets.CODACY_API_TOKEN }} + coverage-reports: decide/coverage.xml From a0295436a340defba63c3f27dbebadde2f35a17c Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 00:13:36 +0100 Subject: [PATCH 16/38] #43-fix: sort django workflow commands --- .github/workflows/django.yml | 9 ++++----- README.md | 8 +++++++- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 08124a4..22b2acf 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -38,15 +38,14 @@ jobs: python -m pip install --upgrade pip pip install -r requirements.txt pip install codacy-coverage + - name: Copy local_settings + run: | + cp ./decide/local_settings.example.py ./decide/local_settings.py - name: Migrate run: | cd decide - python manage.py - makemigrations + python manage.py makemigrations python manage.py migrate - - name: Copy local_settings - run: | - cp ./decide/local_settings.example.py ./decide/local_settings.py - name: Test administration module run: | cd decide diff --git a/README.md b/README.md index a32e8a3..802c3ed 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,10 @@ -[![Build Status](https://travis-ci.com/wadobo/decide.svg?branch=master)](https://travis-ci.com/wadobo/decide) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/94a85eaa0e974c71af6899ea3b0d27e0)](https://www.codacy.com/app/Wadobo/decide?utm_source=github.com&utm_medium=referral&utm_content=wadobo/decide&utm_campaign=Badge_Grade) [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/94a85eaa0e974c71af6899ea3b0d27e0)](https://www.codacy.com/app/Wadobo/decide?utm_source=github.com&utm_medium=referral&utm_content=wadobo/decide&utm_campaign=Badge_Coverage) +[![Admin Build CI](https://github.com/Full-Tortuga/decide-full-tortuga-admin/actions/workflows/django.yml/badge.svg?branch=main)](https://github.com/Full-Tortuga/decide-full-tortuga-admin/actions/workflows/django.yml) +[![Admin Frontend CI](https://github.com/Full-Tortuga/decide-full-tortuga-admin/actions/workflows/react.yml/badge.svg?branch=main)](https://github.com/Full-Tortuga/decide-full-tortuga-admin/actions/workflows/react.yml) + +[![Test Deployment CD](https://github.com/Full-Tortuga/decide-full-tortuga-admin/actions/workflows/herokuDevelop.yml/badge.svg?branch=main)](https://github.com/Full-Tortuga/decide-full-tortuga-admin/actions/workflows/herokuDevelop.yml) +[![Test Deployment CD](https://github.com/Full-Tortuga/decide-full-tortuga-admin/actions/workflows/herokuMain.yml/badge.svg?branch=main)](https://github.com/Full-Tortuga/decide-full-tortuga-admin/actions/workflows/herokuMain.yml) + +[![Codacy Badge](https://api.codacy.com/project/badge/Grade/94a85eaa0e974c71af6899ea3b0d27e0)](https://www.codacy.com/app/Wadobo/decide?utm_source=github.com&utm_medium=referral&utm_content=wadobo/decide&utm_campaign=Badge_Grade) [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/94a85eaa0e974c71af6899ea3b0d27e0)](https://www.codacy.com/app/Wadobo/decide?utm_source=github.com&utm_medium=referral&utm_content=wadobo/decide&utm_campaign=Badge_Coverage) Plataforma voto electrónico educativa From ce0fddf7709f82424d2c669cd97669d0a3aec8c0 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 00:20:31 +0100 Subject: [PATCH 17/38] #43-fix: rename selenium tests and avoid workflow call --- .../{testSelenium.py => selenium.py} | 106 +++++++++++------- 1 file changed, 64 insertions(+), 42 deletions(-) rename decide/administration/{testSelenium.py => selenium.py} (55%) diff --git a/decide/administration/testSelenium.py b/decide/administration/selenium.py similarity index 55% rename from decide/administration/testSelenium.py rename to decide/administration/selenium.py index 65f9952..5223516 100644 --- a/decide/administration/testSelenium.py +++ b/decide/administration/selenium.py @@ -20,38 +20,43 @@ ''' -#USER TESTS -def log_in(driver, cont): +# USER TESTS +def log_in(driver, cont): try: print("Test LogIn") time.sleep(2) driver.get('http://localhost:8000/administration/') time.sleep(2) - driver.find_element(By.XPATH,'//*[@id="content"]/div/form/div[1]/div/input').send_keys("admin") - driver.find_element(By.XPATH,'//*[@id="content"]/div/form/div[2]/div/input').send_keys("qwerty") - driver.find_element(By.XPATH,'//*[@id="content"]/div/form/button').click() + driver.find_element( + By.XPATH, '//*[@id="content"]/div/form/div[1]/div/input').send_keys("admin") + driver.find_element( + By.XPATH, '//*[@id="content"]/div/form/div[2]/div/input').send_keys("qwerty") + driver.find_element( + By.XPATH, '//*[@id="content"]/div/form/button').click() time.sleep(2) print("Test correctamente realizado\n") return cont except Exception as e: print("Error") print(e) - cont = cont +1 + cont = cont + 1 return cont + def log_out(driver, cont): try: print("Test LogOut") driver.get('http://localhost:8000/administration/') time.sleep(2) - driver.find_element(By.XPATH, '//*[@id="root"]/div/div[1]/button').click() + driver.find_element( + By.XPATH, '//*[@id="root"]/div/div[1]/button').click() time.sleep(1) print("Test correctamente realizado\n") return cont except Exception as e: print("Error") print(e) - cont = cont +1 + cont = cont + 1 return cont @@ -59,11 +64,15 @@ def incorrect_log_in(driver, cont): try: print("Test LogIn Incorrecto") driver.get('http://localhost:8000/administration/') - driver.find_element(By.XPATH, '//*[@id="content"]/div/form/div[1]/div/input').send_keys("badadmin") - driver.find_element(By.XPATH, '//*[@id="content"]/div/form/div[2]/div/input').send_keys("qwerty") - driver.find_element(By.XPATH, '//*[@id="content"]/div/form/button').click() + driver.find_element( + By.XPATH, '//*[@id="content"]/div/form/div[1]/div/input').send_keys("badadmin") + driver.find_element( + By.XPATH, '//*[@id="content"]/div/form/div[2]/div/input').send_keys("qwerty") + driver.find_element( + By.XPATH, '//*[@id="content"]/div/form/button').click() time.sleep(1) - elemento = driver.find_element(By.XPATH,'//*[@id="content"]/div/form/div[2]/p') + elemento = driver.find_element( + By.XPATH, '//*[@id="content"]/div/form/div[2]/p') error_text = 'Unable to log in with provided credentials.' if elemento.text == error_text: print("Test correctamente realizado\n") @@ -71,34 +80,42 @@ def incorrect_log_in(driver, cont): except Exception as e: print("Error") print(e) - cont = cont +1 + cont = cont + 1 return cont - - + + def create_user(driver, cont): try: print("Test Create User") time.sleep(1) driver.get("http://localhost:8000/administration/users") time.sleep(4) - driver.find_element(By.XPATH, '//*[@id="actions"]/div/button[1]').click() + driver.find_element( + By.XPATH, '//*[@id="actions"]/div/button[1]').click() time.sleep(4) - numalea = str(random.randint(0,9)) + str(random.randint(0,9))+ str(random.randint(0,9)) - username = str("nuevouser"+ str(numalea)) - driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[1]/div/input').send_keys(username) - driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[2]/div/input').send_keys("passwordNew") - driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[3]/div/input').send_keys("Nueva") - driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[4]/div/input').send_keys("Cuenta") - driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[5]/div/input').send_keys("email@gmail.com") + numalea = str(random.randint(0, 9)) + \ + str(random.randint(0, 9)) + str(random.randint(0, 9)) + username = str("nuevouser" + str(numalea)) + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[1]/div/input').send_keys(username) + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[2]/div/input').send_keys("passwordNew") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[3]/div/input').send_keys("Nueva") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[4]/div/input').send_keys("Cuenta") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[5]/div/input').send_keys("email@gmail.com") time.sleep(2) - driver.find_element(By.XPATH, '/html/body/div[2]/div[3]/div/form/div[2]/button').click() + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[2]/button').click() time.sleep(5) print("Test correctamente realizado\n") return cont except Exception as e: print("Error") print(e) - cont = cont +1 + cont = cont + 1 return cont @@ -106,9 +123,11 @@ def make_staff(driver, cont): try: driver.get("http://localhost:8000/administration/users") print("Test hacer staff") - driver.find_element(By.XPATH,'//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() + driver.find_element( + By.XPATH, '//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() time.sleep(2) - driver.find_element(By.XPATH, '//*[@id="actions"]/div/button[5]').click() + driver.find_element( + By.XPATH, '//*[@id="actions"]/div/button[5]').click() #driver.find_element(By.XPATH, '') print("Test correctamente realizado\n") @@ -116,24 +135,27 @@ def make_staff(driver, cont): except Exception as e: print("Error") print(e) - cont = cont +1 + cont = cont + 1 return cont + def make_superuser(driver, cont): try: driver.get("http://localhost:8000/administration/users") print("Test hacer superuser") - driver.find_element(By.XPATH,'//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() + driver.find_element( + By.XPATH, '//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() time.sleep(2) - driver.find_element(By.XPATH, '//*[@id="actions"]/div/button[6]').click() - #print(element) + driver.find_element( + By.XPATH, '//*[@id="actions"]/div/button[6]').click() + # print(element) #driver.find_element(By.XPATH, '') print("Test correctamente realizado\n") return cont except Exception as e: print("Error") print(e) - cont = cont +1 + cont = cont + 1 return cont @@ -141,16 +163,18 @@ def delete_user(driver, cont): try: driver.get("http://localhost:8000/administration/users") print("Test borrar usuario") - driver.find_element(By.XPATH,'//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() + driver.find_element( + By.XPATH, '//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() time.sleep(2) - driver.find_element(By.XPATH, '//*[@id="actions"]/div/button[3]').click() + driver.find_element( + By.XPATH, '//*[@id="actions"]/div/button[3]').click() time.sleep(1) print("Test correctamente realizado\n") return cont except Exception as e: print("Error") print(e) - cont = cont +1 + cont = cont + 1 return cont @@ -159,9 +183,9 @@ def base(driver, cont): print("Test") driver.find_element(By.XPATH, '') return cont - except : + except: print("Error") - cont = cont +1 + cont = cont + 1 return cont @@ -169,8 +193,8 @@ def base(driver, cont): cont = 0 options = webdriver.ChromeOptions() driver = webdriver.Chrome(options=options) - - #USER TESTS + + # USER TESTS cont = incorrect_log_in(driver, cont) cont = log_in(driver, cont) cont = create_user(driver, cont) @@ -186,6 +210,4 @@ def base(driver, cont): cont = log_out(driver, cont) print("Se han realizado Test de FrontEnd") - print("Se han encontrado: "+ str(cont) + " errores ") - - \ No newline at end of file + print("Se han encontrado: " + str(cont) + " errores ") From 8edc9a541aa0a823bc87c5aad52744ec7d84bc07 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 10:21:46 +0100 Subject: [PATCH 18/38] #43-fix: remove final slash of api utils --- .../frontend/src/api/votingApiUtils.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/decide/administration/frontend/src/api/votingApiUtils.ts b/decide/administration/frontend/src/api/votingApiUtils.ts index 2c67aec..4a0bb3e 100644 --- a/decide/administration/frontend/src/api/votingApiUtils.ts +++ b/decide/administration/frontend/src/api/votingApiUtils.ts @@ -13,13 +13,13 @@ const votingApi = { //Individual Operations getQuestion: (questionId: number) => - axios.get(`/voting/question/${questionId}/`), + axios.get(`/voting/question/${questionId}`), createQuestion: (question: votingType.Question) => axios.post("/voting/question/", question), updateQuestion: (question: votingType.Question, questionId: number) => - axios.put(`/voting/question/${questionId}/`, question), + axios.put(`/voting/question/${questionId}`, question), deleteQuestion: (questionId: number) => - axios.delete(`/voting/question/${questionId}/`), + axios.delete(`/voting/question/${questionId}`), //VOTING API //Bulk Operations @@ -49,12 +49,12 @@ const votingApi = { }), //Individual Operations - getVoting: (votingId: number) => axios.get(`/votings/${votingId}/`), + getVoting: (votingId: number) => axios.get(`/votings/${votingId}`), createVoting: (voting: votingType.VotingFormFields) => axios.post("/votings", voting), updateVoting: (voting: votingType.VotingFormFields, votingId: number) => - axios.put(`/votings/${votingId}/`, voting), - deleteVoting: (votingId: number) => axios.delete(`/votings/${votingId}/`), + axios.put(`/votings/${votingId}`, voting), + deleteVoting: (votingId: number) => axios.delete(`/votings/${votingId}`), }; export default votingApi; From 10e9b95620f04230175b0f239af012502eb879c4 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 10:34:17 +0100 Subject: [PATCH 19/38] #43-fix: add test-settings to the workflow and codacy badges --- .github/workflows/django.yml | 2 +- README.md | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 22b2acf..660db20 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -49,7 +49,7 @@ jobs: - name: Test administration module run: | cd decide - coverage run --branch --source=./administration/ ./manage.py test administration --keepdb --verbosity=2 + coverage run --branch --source=./administration/ ./manage.py test -settings=decide.test_settings administration --keepdb --verbosity=2 coverage xml - name: Codacy Coverage Reporter uses: codacy/codacy-coverage-reporter-action@v1.1.0 diff --git a/README.md b/README.md index 802c3ed..4bb240a 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,8 @@ [![Test Deployment CD](https://github.com/Full-Tortuga/decide-full-tortuga-admin/actions/workflows/herokuDevelop.yml/badge.svg?branch=main)](https://github.com/Full-Tortuga/decide-full-tortuga-admin/actions/workflows/herokuDevelop.yml) [![Test Deployment CD](https://github.com/Full-Tortuga/decide-full-tortuga-admin/actions/workflows/herokuMain.yml/badge.svg?branch=main)](https://github.com/Full-Tortuga/decide-full-tortuga-admin/actions/workflows/herokuMain.yml) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/94a85eaa0e974c71af6899ea3b0d27e0)](https://www.codacy.com/app/Wadobo/decide?utm_source=github.com&utm_medium=referral&utm_content=wadobo/decide&utm_campaign=Badge_Grade) [![Codacy Badge](https://api.codacy.com/project/badge/Coverage/94a85eaa0e974c71af6899ea3b0d27e0)](https://www.codacy.com/app/Wadobo/decide?utm_source=github.com&utm_medium=referral&utm_content=wadobo/decide&utm_campaign=Badge_Coverage) +[![Codacy Badge](https://app.codacy.com/project/badge/Grade/a9e07b14853a487d82a187bc69365d50)](https://www.codacy.com/gh/Full-Tortuga/decide-full-tortuga-admin/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Full-Tortuga/decide-full-tortuga-admin&utm_campaign=Badge_Grade) +[![Codacy Badge](https://app.codacy.com/project/badge/Coverage/a9e07b14853a487d82a187bc69365d50)](https://www.codacy.com/gh/Full-Tortuga/decide-full-tortuga-admin/dashboard?utm_source=github.com&utm_medium=referral&utm_content=Full-Tortuga/decide-full-tortuga-admin&utm_campaign=Badge_Coverage) Plataforma voto electrónico educativa From 90105fee29efdf409a1c64e48170213a8731d758 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 10:43:02 +0100 Subject: [PATCH 20/38] #43-fix: add missing "-" to the workflow --- .github/workflows/django.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 660db20..8183d0e 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -49,7 +49,7 @@ jobs: - name: Test administration module run: | cd decide - coverage run --branch --source=./administration/ ./manage.py test -settings=decide.test_settings administration --keepdb --verbosity=2 + coverage run --branch --source=./administration/ ./manage.py test --settings=decide.test_settings administration --keepdb --verbosity=2 coverage xml - name: Codacy Coverage Reporter uses: codacy/codacy-coverage-reporter-action@v1.1.0 From db17606f1833fbe2af7b40cc69463b6af2f5827a Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 10:48:54 +0100 Subject: [PATCH 21/38] #43-fix: change test settings to local_settings --- .github/workflows/django.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 8183d0e..bce9b08 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -49,7 +49,7 @@ jobs: - name: Test administration module run: | cd decide - coverage run --branch --source=./administration/ ./manage.py test --settings=decide.test_settings administration --keepdb --verbosity=2 + coverage run --branch --source=./administration/ ./manage.py test --settings=local_settings administration --keepdb --verbosity=2 coverage xml - name: Codacy Coverage Reporter uses: codacy/codacy-coverage-reporter-action@v1.1.0 From 383cfb67778620aa0de48d0b52b63d943e1aa347 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 11:07:42 +0100 Subject: [PATCH 22/38] #43-fix: add mongo image config to the workflow --- .github/workflows/django.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index bce9b08..9b8394f 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -17,8 +17,12 @@ jobs: services: mongodb: image: mongo:3.4.23 + env: + MONGO_INITDB_DATABASE: decide ports: - 27017:27017 + options: --health-cmd mongo --health-interval 10s --health-timeout 5s --health-retries 5 + ldap: image: carvilgar1us/decideldap ports: @@ -49,7 +53,7 @@ jobs: - name: Test administration module run: | cd decide - coverage run --branch --source=./administration/ ./manage.py test --settings=local_settings administration --keepdb --verbosity=2 + coverage run --branch --source=./administration/ ./manage.py test administration --keepdb --verbosity=2 coverage xml - name: Codacy Coverage Reporter uses: codacy/codacy-coverage-reporter-action@v1.1.0 From e5a199b993d78d7d1b5aaa480b13a98877c5a565 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 11:17:57 +0100 Subject: [PATCH 23/38] #43-fix: change test command params --- .github/workflows/django.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 9b8394f..6c7b07f 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -53,7 +53,7 @@ jobs: - name: Test administration module run: | cd decide - coverage run --branch --source=./administration/ ./manage.py test administration --keepdb --verbosity=2 + coverage run --branch --source=./administration/ ./manage.py test administration -v 2 coverage xml - name: Codacy Coverage Reporter uses: codacy/codacy-coverage-reporter-action@v1.1.0 From 9ce10decf8314cd08b0bb3707f1785972726fc98 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 12:08:19 +0100 Subject: [PATCH 24/38] #43-fix: add keepdb and change database name in settings --- .github/workflows/django.yml | 2 +- decide/decide/settings.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 6c7b07f..7692fa2 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -53,7 +53,7 @@ jobs: - name: Test administration module run: | cd decide - coverage run --branch --source=./administration/ ./manage.py test administration -v 2 + coverage run --branch --source=./administration/ ./manage.py test administration --keepdb -v 2 coverage xml - name: Codacy Coverage Reporter uses: codacy/codacy-coverage-reporter-action@v1.1.0 diff --git a/decide/decide/settings.py b/decide/decide/settings.py index 152a3d8..d498f6b 100644 --- a/decide/decide/settings.py +++ b/decide/decide/settings.py @@ -140,7 +140,7 @@ DATABASES = { 'default': { 'ENGINE': 'djongo', - 'NAME': 'prueba', + 'NAME': 'decide', 'CLIENT': { 'host': '127.0.0.1', } From 569210f9dc9186ddb859e5ebdca217ab7419dd72 Mon Sep 17 00:00:00 2001 From: almafe2510 Date: Sun, 9 Jan 2022 12:13:23 +0100 Subject: [PATCH 25/38] #43-test: Add Votings test in Selenium Co-Authored-By: Fernando Rabasco Ledesma <48551658+ferrabled@users.noreply.github.com> --- decide/administration/selenium.py | 213 ---------------- decide/administration/seleniumT.py | 375 +++++++++++++++++++++++++++++ 2 files changed, 375 insertions(+), 213 deletions(-) delete mode 100644 decide/administration/selenium.py create mode 100644 decide/administration/seleniumT.py diff --git a/decide/administration/selenium.py b/decide/administration/selenium.py deleted file mode 100644 index 5223516..0000000 --- a/decide/administration/selenium.py +++ /dev/null @@ -1,213 +0,0 @@ -from selenium import webdriver -from selenium.webdriver.common.by import By -import time -import random - -'''Para poder ejecutar este test, se debe crear un superusuario -con el siguiente comando: - -./manage.py createsuperuser - -con datos: - Username: admin - password: qwerty -y hacer bypass de la restriccion de contraseña - -Entrar en http://localhost:8000/administration/users -iniciar sesión con el usuario admin -y si hubiera más usuarios creados, hay que eliminarlos -antes de realizar los tests -''' - - -# USER TESTS -def log_in(driver, cont): - try: - print("Test LogIn") - time.sleep(2) - driver.get('http://localhost:8000/administration/') - time.sleep(2) - driver.find_element( - By.XPATH, '//*[@id="content"]/div/form/div[1]/div/input').send_keys("admin") - driver.find_element( - By.XPATH, '//*[@id="content"]/div/form/div[2]/div/input').send_keys("qwerty") - driver.find_element( - By.XPATH, '//*[@id="content"]/div/form/button').click() - time.sleep(2) - print("Test correctamente realizado\n") - return cont - except Exception as e: - print("Error") - print(e) - cont = cont + 1 - return cont - - -def log_out(driver, cont): - try: - print("Test LogOut") - driver.get('http://localhost:8000/administration/') - time.sleep(2) - driver.find_element( - By.XPATH, '//*[@id="root"]/div/div[1]/button').click() - time.sleep(1) - print("Test correctamente realizado\n") - return cont - except Exception as e: - print("Error") - print(e) - cont = cont + 1 - return cont - - -def incorrect_log_in(driver, cont): - try: - print("Test LogIn Incorrecto") - driver.get('http://localhost:8000/administration/') - driver.find_element( - By.XPATH, '//*[@id="content"]/div/form/div[1]/div/input').send_keys("badadmin") - driver.find_element( - By.XPATH, '//*[@id="content"]/div/form/div[2]/div/input').send_keys("qwerty") - driver.find_element( - By.XPATH, '//*[@id="content"]/div/form/button').click() - time.sleep(1) - elemento = driver.find_element( - By.XPATH, '//*[@id="content"]/div/form/div[2]/p') - error_text = 'Unable to log in with provided credentials.' - if elemento.text == error_text: - print("Test correctamente realizado\n") - return cont - except Exception as e: - print("Error") - print(e) - cont = cont + 1 - return cont - - -def create_user(driver, cont): - try: - print("Test Create User") - time.sleep(1) - driver.get("http://localhost:8000/administration/users") - time.sleep(4) - driver.find_element( - By.XPATH, '//*[@id="actions"]/div/button[1]').click() - time.sleep(4) - numalea = str(random.randint(0, 9)) + \ - str(random.randint(0, 9)) + str(random.randint(0, 9)) - username = str("nuevouser" + str(numalea)) - driver.find_element( - By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[1]/div/input').send_keys(username) - driver.find_element( - By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[2]/div/input').send_keys("passwordNew") - driver.find_element( - By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[3]/div/input').send_keys("Nueva") - driver.find_element( - By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[4]/div/input').send_keys("Cuenta") - driver.find_element( - By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[5]/div/input').send_keys("email@gmail.com") - time.sleep(2) - driver.find_element( - By.XPATH, '/html/body/div[2]/div[3]/div/form/div[2]/button').click() - time.sleep(5) - print("Test correctamente realizado\n") - return cont - except Exception as e: - print("Error") - print(e) - cont = cont + 1 - return cont - - -def make_staff(driver, cont): - try: - driver.get("http://localhost:8000/administration/users") - print("Test hacer staff") - driver.find_element( - By.XPATH, '//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() - time.sleep(2) - driver.find_element( - By.XPATH, '//*[@id="actions"]/div/button[5]').click() - #driver.find_element(By.XPATH, '') - print("Test correctamente realizado\n") - - return cont - except Exception as e: - print("Error") - print(e) - cont = cont + 1 - return cont - - -def make_superuser(driver, cont): - try: - driver.get("http://localhost:8000/administration/users") - print("Test hacer superuser") - driver.find_element( - By.XPATH, '//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() - time.sleep(2) - driver.find_element( - By.XPATH, '//*[@id="actions"]/div/button[6]').click() - # print(element) - #driver.find_element(By.XPATH, '') - print("Test correctamente realizado\n") - return cont - except Exception as e: - print("Error") - print(e) - cont = cont + 1 - return cont - - -def delete_user(driver, cont): - try: - driver.get("http://localhost:8000/administration/users") - print("Test borrar usuario") - driver.find_element( - By.XPATH, '//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() - time.sleep(2) - driver.find_element( - By.XPATH, '//*[@id="actions"]/div/button[3]').click() - time.sleep(1) - print("Test correctamente realizado\n") - return cont - except Exception as e: - print("Error") - print(e) - cont = cont + 1 - return cont - - -def base(driver, cont): - try: - print("Test") - driver.find_element(By.XPATH, '') - return cont - except: - print("Error") - cont = cont + 1 - return cont - - -if __name__ == "__main__": - cont = 0 - options = webdriver.ChromeOptions() - driver = webdriver.Chrome(options=options) - - # USER TESTS - cont = incorrect_log_in(driver, cont) - cont = log_in(driver, cont) - cont = create_user(driver, cont) - cont = create_user(driver, cont) - cont = create_user(driver, cont) - cont = create_user(driver, cont) - time.sleep(2) - cont = make_staff(driver, cont) - time.sleep(2) - cont = make_superuser(driver, cont) - time.sleep(3) - cont = delete_user(driver, cont) - cont = log_out(driver, cont) - - print("Se han realizado Test de FrontEnd") - print("Se han encontrado: " + str(cont) + " errores ") diff --git a/decide/administration/seleniumT.py b/decide/administration/seleniumT.py new file mode 100644 index 0000000..7145cea --- /dev/null +++ b/decide/administration/seleniumT.py @@ -0,0 +1,375 @@ +from selenium import webdriver +from selenium.webdriver.common.by import By +import time +import random + +'''Para poder ejecutar este test, se debe crear un superusuario +con el siguiente comando: + +./manage.py createsuperuser + +con datos: + Username: admin + password: qwerty +y hacer bypass de la restriccion de contraseña + +Entrar en http://localhost:8000/administration/users +iniciar sesión con el usuario admin +y si hubiera más usuarios creados, hay que eliminarlos +antes de realizar los tests +''' + + +# USER TESTS +def log_in(driver, cont): + try: + print("Test LogIn") + time.sleep(2) + driver.get('http://localhost:8000/administration/') + time.sleep(2) + driver.find_element( + By.XPATH, '//*[@id="content"]/div/form/div[1]/div/input').send_keys("admin") + driver.find_element( + By.XPATH, '//*[@id="content"]/div/form/div[2]/div/input').send_keys("qwerty") + driver.find_element( + By.XPATH, '//*[@id="content"]/div/form/button').click() + time.sleep(2) + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont + 1 + return cont + + +def log_out(driver, cont): + try: + print("Test LogOut") + driver.get('http://localhost:8000/administration/') + time.sleep(2) + driver.find_element( + By.XPATH, '//*[@id="root"]/div/div[1]/button').click() + time.sleep(1) + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont + 1 + return cont + + +def incorrect_log_in(driver, cont): + try: + print("Test LogIn Incorrecto") + driver.get('http://localhost:8000/administration/') + driver.find_element( + By.XPATH, '//*[@id="content"]/div/form/div[1]/div/input').send_keys("badadmin") + driver.find_element( + By.XPATH, '//*[@id="content"]/div/form/div[2]/div/input').send_keys("qwerty") + driver.find_element( + By.XPATH, '//*[@id="content"]/div/form/button').click() + time.sleep(1) + elemento = driver.find_element( + By.XPATH, '//*[@id="content"]/div/form/div[2]/p') + error_text = 'Unable to log in with provided credentials.' + if elemento.text == error_text: + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont + 1 + return cont + + +def create_user(driver, cont): + try: + print("Test Create User") + time.sleep(1) + driver.get("http://localhost:8000/administration/users") + time.sleep(4) + driver.find_element( + By.XPATH, '//*[@id="actions"]/div/button[1]').click() + time.sleep(4) + numalea = str(random.randint(0, 9)) + \ + str(random.randint(0, 9)) + str(random.randint(0, 9)) + username = str("nuevouser" + str(numalea)) + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[1]/div/input').send_keys(username) + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[2]/div/input').send_keys("passwordNew") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[3]/div/input').send_keys("Nueva") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[4]/div/input').send_keys("Cuenta") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[5]/div/input').send_keys("email@gmail.com") + time.sleep(2) + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[2]/button').click() + time.sleep(5) + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont + 1 + return cont + + +def make_staff(driver, cont): + try: + driver.get("http://localhost:8000/administration/users") + print("Test hacer staff") + driver.find_element( + By.XPATH, '//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() + time.sleep(2) + driver.find_element( + By.XPATH, '//*[@id="actions"]/div/button[5]').click() + #driver.find_element(By.XPATH, '') + print("Test correctamente realizado\n") + + return cont + except Exception as e: + print("Error") + print(e) + cont = cont + 1 + return cont + + +def make_superuser(driver, cont): + try: + driver.get("http://localhost:8000/administration/users") + print("Test hacer superuser") + driver.find_element( + By.XPATH, '//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() + time.sleep(2) + driver.find_element( + By.XPATH, '//*[@id="actions"]/div/button[6]').click() + # print(element) + #driver.find_element(By.XPATH, '') + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont + 1 + return cont + + +def delete_user(driver, cont): + try: + driver.get("http://localhost:8000/administration/users") + print("Test borrar usuario") + driver.find_element( + By.XPATH, '//*[@id="content"]/div/div/div[2]/div[2]/div/div/div/div[4]/div[1]/span/input').click() + time.sleep(2) + driver.find_element( + By.XPATH, '//*[@id="actions"]/div/button[3]').click() + time.sleep(1) + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont + 1 + return cont + + +#VOTING TESTS +def create_voting(driver, cont): + try: + print("Test Create Voting") + time.sleep(1) + driver.get("http://localhost:8000/administration/votings") + time.sleep(4) + driver.find_element( + By.XPATH, '//*[@id="actions"]/div/button[1]').click() + time.sleep(4) + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[1]/div/input').send_keys("Nueva votacion") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[2]/div/input').send_keys("descripcion") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[5]/div/button[2]').click() + time.sleep(2) + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[2]/div/div/div[1]/div/input').send_keys("Pregunta") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[2]/div/div/div[2]/div/div/input').send_keys("Opcion A") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[2]/div/div/div[3]/div/div/input').send_keys("Opcion B") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[5]/div/button[2]').click() + time.sleep(2) + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[3]/div/div/div/div/div[2]/div[2]/div/div/div/div/div[1]/span/input').click() + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[5]/div/button[2]').click() + time.sleep(2) + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[4]/div/div/div/label[1]/span[1]/input').click() + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[5]/button').click() + time.sleep(5) + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont + 1 + return cont + +def update_voting(driver, cont): + try: + print("Test Update Voting") + time.sleep(1) + driver.get("http://localhost:8000/administration/votings") + time.sleep(4) + driver.find_element( + By.XPATH, '/html/body/div/div/div[2]/div[1]/div/div/div[2]/div[2]/div/div/div/div[1]/div[1]/span/input').click() + driver.find_element( + By.XPATH, '//*[@id="actions"]/div/button[1]').click() + time.sleep(4) + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[1]/div/input').send_keys(" editada") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[2]/div/input').send_keys(" editada") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[5]/div/button[2]').click() + time.sleep(2) + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[2]/div/div/div[1]/div/input').send_keys(" editada") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[2]/div/div/div[2]/div/div/input').send_keys(" 2") + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[2]/div/div/div[3]/div/div/input').send_keys(" 2") + time.sleep(2) + driver.find_element( + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[5]/button').click() + time.sleep(5) + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont + 1 + return cont + +def delete_voting(driver, cont): + try: + print("Test Delete Voting") + time.sleep(1) + driver.get("http://localhost:8000/administration/votings") + time.sleep(4) + driver.find_element( + By.XPATH, '/html/body/div/div/div[2]/div[1]/div/div/div[2]/div[2]/div/div/div/div[1]/div[1]/span/input').click() + driver.find_element( + By.XPATH, '//*[@id="actions"]/div/button[3]').click() + time.sleep(4) + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont + 1 + return cont + +def start_voting(driver, cont): + try: + print("Test Start Voting") + time.sleep(1) + driver.get("http://localhost:8000/administration/votings") + time.sleep(4) + driver.find_element( + By.XPATH, '/html/body/div/div/div[2]/div[1]/div/div/div[2]/div[2]/div/div/div/div[1]/div[1]/span/input').click() + driver.find_element( + By.XPATH, '//*[@id="actions"]/div/button[4]').click() + time.sleep(4) + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont + 1 + return cont + +def stop_voting(driver, cont): + try: + print("Test Stop Voting") + time.sleep(1) + driver.get("http://localhost:8000/administration/votings") + time.sleep(4) + driver.find_element( + By.XPATH, '/html/body/div/div/div[2]/div[1]/div/div/div[2]/div[2]/div/div/div/div[1]/div[1]/span/input').click() + driver.find_element( + By.XPATH, '//*[@id="actions"]/div/button[4]').click() + time.sleep(4) + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont + 1 + return cont + +def tally_voting(driver, cont): + try: + print("Test Tally Voting") + time.sleep(1) + driver.get("http://localhost:8000/administration/votings") + time.sleep(4) + driver.find_element( + By.XPATH, '/html/body/div/div/div[2]/div[1]/div/div/div[2]/div[2]/div/div/div/div[1]/div[1]/span/input').click() + driver.find_element( + By.XPATH, '//*[@id="actions"]/div/button[4]').click() + time.sleep(4) + print("Test correctamente realizado\n") + return cont + except Exception as e: + print("Error") + print(e) + cont = cont + 1 + return cont + + +if __name__ == "__main__": + cont = 0 + options = webdriver.ChromeOptions() + options.headless = True + driver = webdriver.Chrome(options=options) + + # USER TESTS + cont = incorrect_log_in(driver, cont) + cont = log_in(driver, cont) + cont = create_user(driver, cont) + cont = create_user(driver, cont) + cont = create_user(driver, cont) + cont = create_user(driver, cont) + time.sleep(2) + cont = make_staff(driver, cont) + time.sleep(2) + cont = make_superuser(driver, cont) + time.sleep(3) + cont = delete_user(driver, cont) + cont = log_out(driver, cont) + print("Se han realizado los test de User") + print("Se han encontrado: " + str(cont) + " errores ") + + + #VOTING TESTS + cont2 = 0 + cont2 = log_in(driver, cont2) + cont2 = create_voting(driver, cont2) + update_voting(driver, cont2) + cont2 = start_voting(driver, cont2) + time.sleep(3) + cont2 = stop_voting(driver, cont2) + time.sleep(3) + cont2 = tally_voting(driver, cont2) + time.sleep(3) + cont2 = delete_voting(driver, cont2) + print("Se han realizado los test de Votings") + print("Se han encontrado: " + str(cont2) + " errores ") \ No newline at end of file From 8387186d459d7c6e8098ba761e6888f56280f772 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 12:16:27 +0100 Subject: [PATCH 26/38] #43-fix: use decide settings for tests --- .github/workflows/django.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 7692fa2..6b0bc5f 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -53,7 +53,7 @@ jobs: - name: Test administration module run: | cd decide - coverage run --branch --source=./administration/ ./manage.py test administration --keepdb -v 2 + coverage run --branch --source=./administration/ ./manage.py test administration --settings=decide.settings --keepdb -v 2 coverage xml - name: Codacy Coverage Reporter uses: codacy/codacy-coverage-reporter-action@v1.1.0 From faa22589ea8d70060ba5dcda1e38139fc302b6ec Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 12:25:53 +0100 Subject: [PATCH 27/38] #43-fix: flush db before migrating and testing in the workflow --- .github/workflows/django.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 6b0bc5f..ef226e4 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -48,12 +48,14 @@ jobs: - name: Migrate run: | cd decide + python manage.py flush --noinput + python manage.py sqlflush python manage.py makemigrations python manage.py migrate - name: Test administration module run: | cd decide - coverage run --branch --source=./administration/ ./manage.py test administration --settings=decide.settings --keepdb -v 2 + coverage run --branch --source=./administration/ ./manage.py test administration --settings=decide.settings -v 2 coverage xml - name: Codacy Coverage Reporter uses: codacy/codacy-coverage-reporter-action@v1.1.0 From 713e98d3e4c19a25b76bfcfb3340fef6171a529b Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 12:35:39 +0100 Subject: [PATCH 28/38] #43-fix: add noinput --- .github/workflows/django.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index ef226e4..c0570a9 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -55,7 +55,7 @@ jobs: - name: Test administration module run: | cd decide - coverage run --branch --source=./administration/ ./manage.py test administration --settings=decide.settings -v 2 + coverage run --branch --source=./administration/ ./manage.py test administration --noinput -v 2 coverage xml - name: Codacy Coverage Reporter uses: codacy/codacy-coverage-reporter-action@v1.1.0 From ad962f11662bd877ad12a4602979dde9a2403044 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 12:45:26 +0100 Subject: [PATCH 29/38] #43-fix: remove mongo version --- .github/workflows/django.yml | 4 +- decide/decide/test_settings.py | 210 +++++++++++++++++++++++++++++++++ 2 files changed, 212 insertions(+), 2 deletions(-) create mode 100644 decide/decide/test_settings.py diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index c0570a9..4f02ad7 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -16,7 +16,7 @@ jobs: services: mongodb: - image: mongo:3.4.23 + image: mongo env: MONGO_INITDB_DATABASE: decide ports: @@ -55,7 +55,7 @@ jobs: - name: Test administration module run: | cd decide - coverage run --branch --source=./administration/ ./manage.py test administration --noinput -v 2 + coverage run --branch --source=./administration/ ./manage.py test administration --keepdb -v 2 coverage xml - name: Codacy Coverage Reporter uses: codacy/codacy-coverage-reporter-action@v1.1.0 diff --git a/decide/decide/test_settings.py b/decide/decide/test_settings.py new file mode 100644 index 0000000..d498f6b --- /dev/null +++ b/decide/decide/test_settings.py @@ -0,0 +1,210 @@ +""" +Django settings for decide project. + +Generated by 'django-admin startproject' using Django 2.0. + +For more information on this file, see +https://docs.djangoproject.com/en/2.0/topics/settings/ + +For the full list of settings and their values, see +https://docs.djangoproject.com/en/2.0/ref/settings/ +""" + +import os +import django_heroku + +# Build paths inside the project like this: os.path.join(BASE_DIR, ...) +BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + +# Quick-start development settings - unsuitable for production +# See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ + +# SECURITY WARNING: keep the secret key used in production secret! +SECRET_KEY = '^##ydkswfu0+=ofw0l#$kv^8n)0$i(qd&d&ol#p9!b$8*5%j1+' + +# SECURITY WARNING: don't run with debug turned on in production! +DEBUG = True +ALLOWED_HOSTS = ["*"] + +# Login redirect +LOGIN_URL = '/authentication/login_form/' +LOGIN_REDIRECT_URL = '/authentication/bienvenida/' + +# Application definition + +INSTALLED_APPS = [ + 'django.contrib.admin', + 'django.contrib.auth', + 'django.contrib.contenttypes', + 'django.contrib.sessions', + 'django.contrib.messages', + 'django.contrib.staticfiles', + + 'corsheaders', + 'django_filters', + 'rest_framework', + 'rest_framework.authtoken', + 'rest_framework_swagger', + 'gateway', +] + +REST_FRAMEWORK = { + 'DEFAULT_AUTHENTICATION_CLASSES': ( + 'rest_framework.authentication.BasicAuthentication', + 'rest_framework.authentication.TokenAuthentication', + ), + 'DEFAULT_VERSIONING_CLASS': 'rest_framework.versioning.QueryParameterVersioning' +} + +AUTHENTICATION_BACKENDS = [ + 'base.backends.AuthBackend', +] + + +MODULES = [ + 'administration', + 'authentication', + 'base', + 'booth', + 'census', + 'voting', + 'mixnet', + 'postproc', + 'store', + 'visualizer', +] + +ENV_DEVELOP = os.environ.get('ENV_DEVELOP', False) +ENV_MAIN = os.environ.get('ENV_MAIN', False) + +if ENV_DEVELOP: + BASEURL = 'https://decide-full-tortuga-admin-dev.herokuapp.com' +elif ENV_MAIN: + BASEURL = 'https://decide-full-tortuga-admin.herokuapp.com' +else: + BASEURL = 'http://localhost:8000' + +APIS = { + 'administration': BASEURL, + 'authentication': BASEURL, + 'base': BASEURL, + 'booth': BASEURL, + 'census': BASEURL, + 'mixnet': BASEURL, + 'postproc': BASEURL, + 'store': BASEURL, + 'visualizer': BASEURL, + 'voting': BASEURL, +} + +MIDDLEWARE = [ + 'corsheaders.middleware.CorsMiddleware', # added to solve CORS + 'django.middleware.common.CommonMiddleware', # added to solve CORS + 'django.middleware.security.SecurityMiddleware', + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', + 'corsheaders.middleware.CorsMiddleware' +] + +ROOT_URLCONF = 'decide.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, 'administration', 'frontend')], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +STATIC_URL = '/static/' +STATICFILES_DIRS = ( + os.path.join(BASE_DIR, 'administration', 'frontend', 'build', 'static'), +) + +WSGI_APPLICATION = 'decide.wsgi.application' + +# Database +# https://docs.djangoproject.com/en/2.0/ref/settings/#databases + +DATABASES = { + 'default': { + 'ENGINE': 'djongo', + 'NAME': 'decide', + 'CLIENT': { + 'host': '127.0.0.1', + } + } +} + +# Password validation +# https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators + +AUTH_PASSWORD_VALIDATORS = [ + { + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + }, + { + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + }, +] + +# Internationalization +# https://docs.djangoproject.com/en/2.0/topics/i18n/ + +LANGUAGE_CODE = 'en-us' + +TIME_ZONE = 'UTC' + +USE_I18N = True + +USE_L10N = True + +USE_TZ = True + +TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' + +# Static files (CSS, JavaScript, Images) +# https://docs.djangoproject.com/en/2.0/howto/static-files/ + +STATIC_URL = '/static/' + +# number of bits for the key, all auths should use the same number of bits +KEYBITS = 256 + +# Versioning +ALLOWED_VERSIONS = ['v1', 'v2'] +DEFAULT_VERSION = 'v1' + +try: + from local_settings import * +except ImportError: + print("local_settings.py not found") + +# loading jsonnet config +if os.path.exists("config.jsonnet"): + import json + from _jsonnet import evaluate_file + + config = json.loads(evaluate_file("config.jsonnet")) + for k, v in config.items(): + vars()[k] = v + +INSTALLED_APPS = INSTALLED_APPS + MODULES +django_heroku.settings(locals()) From d61ca41ce05f4975ac0e35280a074cf0c1f59e8f Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 12:57:00 +0100 Subject: [PATCH 30/38] #43-fix: add selenium log spacings --- decide/administration/seleniumT.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/decide/administration/seleniumT.py b/decide/administration/seleniumT.py index 7145cea..d1ac88c 100644 --- a/decide/administration/seleniumT.py +++ b/decide/administration/seleniumT.py @@ -3,13 +3,16 @@ import time import random -'''Para poder ejecutar este test, se debe crear un superusuario +''' +README: + +Para poder ejecutar este test, se debe crear un superusuario con el siguiente comando: ./manage.py createsuperuser con datos: - Username: admin + username: admin password: qwerty y hacer bypass de la restriccion de contraseña @@ -17,6 +20,7 @@ iniciar sesión con el usuario admin y si hubiera más usuarios creados, hay que eliminarlos antes de realizar los tests + ''' @@ -178,7 +182,7 @@ def delete_user(driver, cont): return cont -#VOTING TESTS +# VOTING TESTS def create_voting(driver, cont): try: print("Test Create Voting") @@ -191,7 +195,7 @@ def create_voting(driver, cont): driver.find_element( By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[1]/div/input').send_keys("Nueva votacion") driver.find_element( - By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[2]/div/input').send_keys("descripcion") + By.XPATH, '/html/body/div[2]/div[3]/div/form/div[1]/div/div/div[2]/div/input').send_keys("descripcion") driver.find_element( By.XPATH, '/html/body/div[2]/div[3]/div/form/div[5]/div/button[2]').click() time.sleep(2) @@ -222,6 +226,7 @@ def create_voting(driver, cont): cont = cont + 1 return cont + def update_voting(driver, cont): try: print("Test Update Voting") @@ -258,6 +263,7 @@ def update_voting(driver, cont): cont = cont + 1 return cont + def delete_voting(driver, cont): try: print("Test Delete Voting") @@ -277,6 +283,7 @@ def delete_voting(driver, cont): cont = cont + 1 return cont + def start_voting(driver, cont): try: print("Test Start Voting") @@ -296,6 +303,7 @@ def start_voting(driver, cont): cont = cont + 1 return cont + def stop_voting(driver, cont): try: print("Test Stop Voting") @@ -315,6 +323,7 @@ def stop_voting(driver, cont): cont = cont + 1 return cont + def tally_voting(driver, cont): try: print("Test Tally Voting") @@ -342,6 +351,7 @@ def tally_voting(driver, cont): driver = webdriver.Chrome(options=options) # USER TESTS + print("USER TESTS START \n") cont = incorrect_log_in(driver, cont) cont = log_in(driver, cont) cont = create_user(driver, cont) @@ -356,10 +366,10 @@ def tally_voting(driver, cont): cont = delete_user(driver, cont) cont = log_out(driver, cont) print("Se han realizado los test de User") - print("Se han encontrado: " + str(cont) + " errores ") - + print("Se han encontrado: " + str(cont) + " errores \n\n") - #VOTING TESTS + # VOTING TESTS + print("VOTING TESTS START \n") cont2 = 0 cont2 = log_in(driver, cont2) cont2 = create_voting(driver, cont2) @@ -372,4 +382,4 @@ def tally_voting(driver, cont): time.sleep(3) cont2 = delete_voting(driver, cont2) print("Se han realizado los test de Votings") - print("Se han encontrado: " + str(cont2) + " errores ") \ No newline at end of file + print("Se han encontrado: " + str(cont2) + " errores \n\n") From 3755054fe062d76f12c15afcd382943e5ace4cfd Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 14:03:19 +0100 Subject: [PATCH 31/38] #43-fix: add telegram token to the migrate env --- .github/workflows/django.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index ec1c85b..a1a81ef 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -46,6 +46,8 @@ jobs: run: | cp ./decide/local_settings.example.py ./decide/local_settings.py - name: Migrate + env: + TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} run: | cd decide python manage.py flush --noinput From 5a5ce29cbbb5b43ba2cf64bef0d441e4480388dc Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 14:39:32 +0100 Subject: [PATCH 32/38] #43: add linux dependency --- .github/workflows/django.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index a1a81ef..6d81cf1 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -32,7 +32,7 @@ jobs: - uses: actions/checkout@v2 - name: Install linux dependencies run: | - sudo apt-get install build-essential python3-dev python2.7-dev libldap2-dev libsasl2-dev tox lcov valgrind + sudo apt-get install build-essential python3-dev python2.7-dev libldap2-dev libsasl2-dev tox lcov valgrind libpq-dev - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: @@ -59,7 +59,7 @@ jobs: TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} run: | cd decide - coverage run --branch --source=./administration/ ./manage.py test administration --keepdb -v 2 + coverage run --branch --source=./administration/ ./manage.py test administration --noinput -v 2 coverage xml - name: Codacy Coverage Reporter uses: codacy/codacy-coverage-reporter-action@v1.1.0 From 3b6956ab177657baa51aa30d9dd2a03f32bdd7a4 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 14:49:14 +0100 Subject: [PATCH 33/38] #43-fix: re-add test settings --- .github/workflows/django.yml | 2 +- decide/decide/test_settings.py | 88 ++++++++++++---------------------- 2 files changed, 32 insertions(+), 58 deletions(-) diff --git a/.github/workflows/django.yml b/.github/workflows/django.yml index 6d81cf1..86cdc7e 100644 --- a/.github/workflows/django.yml +++ b/.github/workflows/django.yml @@ -59,7 +59,7 @@ jobs: TELEGRAM_TOKEN: ${{ secrets.TELEGRAM_TOKEN }} run: | cd decide - coverage run --branch --source=./administration/ ./manage.py test administration --noinput -v 2 + coverage run --branch --source=./administration/ ./manage.py test --settings=decide.test_settings administration --noinput -v 2 coverage xml - name: Codacy Coverage Reporter uses: codacy/codacy-coverage-reporter-action@v1.1.0 diff --git a/decide/decide/test_settings.py b/decide/decide/test_settings.py index d498f6b..95e0a0e 100644 --- a/decide/decide/test_settings.py +++ b/decide/decide/test_settings.py @@ -1,21 +1,9 @@ -""" -Django settings for decide project. - -Generated by 'django-admin startproject' using Django 2.0. - -For more information on this file, see -https://docs.djangoproject.com/en/2.0/topics/settings/ - -For the full list of settings and their values, see -https://docs.djangoproject.com/en/2.0/ref/settings/ -""" - import os -import django_heroku # Build paths inside the project like this: os.path.join(BASE_DIR, ...) BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) + # Quick-start development settings - unsuitable for production # See https://docs.djangoproject.com/en/2.0/howto/deployment/checklist/ @@ -24,11 +12,9 @@ # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True + ALLOWED_HOSTS = ["*"] -# Login redirect -LOGIN_URL = '/authentication/login_form/' -LOGIN_REDIRECT_URL = '/authentication/bienvenida/' # Application definition @@ -60,7 +46,6 @@ 'base.backends.AuthBackend', ] - MODULES = [ 'administration', 'authentication', @@ -72,36 +57,39 @@ 'postproc', 'store', 'visualizer', + 'backups', ] -ENV_DEVELOP = os.environ.get('ENV_DEVELOP', False) -ENV_MAIN = os.environ.get('ENV_MAIN', False) - -if ENV_DEVELOP: - BASEURL = 'https://decide-full-tortuga-admin-dev.herokuapp.com' -elif ENV_MAIN: - BASEURL = 'https://decide-full-tortuga-admin.herokuapp.com' -else: - BASEURL = 'http://localhost:8000' APIS = { - 'administration': BASEURL, - 'authentication': BASEURL, - 'base': BASEURL, - 'booth': BASEURL, - 'census': BASEURL, - 'mixnet': BASEURL, - 'postproc': BASEURL, - 'store': BASEURL, - 'visualizer': BASEURL, - 'voting': BASEURL, + 'authentication': 'http://localhost:8000', + 'base': 'http://localhost:8000', + 'booth': 'http://localhost:8000', + 'census': 'http://localhost:8000', + 'mixnet': 'http://localhost:8000', + 'postproc': 'http://localhost:8000', + 'store': 'http://localhost:8000', + 'visualizer': 'http://localhost:8000', + 'voting': 'http://localhost:8000', +} + +BASEURL = 'http://localhost:8000' + +DATABASES = { + 'default': { + 'ENGINE': 'djongo', + 'NAME': 'decide', + 'CLIENT': { + 'host': '127.0.0.1', + } + + } } MIDDLEWARE = [ - 'corsheaders.middleware.CorsMiddleware', # added to solve CORS - 'django.middleware.common.CommonMiddleware', # added to solve CORS 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', @@ -127,25 +115,8 @@ }, ] -STATIC_URL = '/static/' -STATICFILES_DIRS = ( - os.path.join(BASE_DIR, 'administration', 'frontend', 'build', 'static'), -) - WSGI_APPLICATION = 'decide.wsgi.application' -# Database -# https://docs.djangoproject.com/en/2.0/ref/settings/#databases - -DATABASES = { - 'default': { - 'ENGINE': 'djongo', - 'NAME': 'decide', - 'CLIENT': { - 'host': '127.0.0.1', - } - } -} # Password validation # https://docs.djangoproject.com/en/2.0/ref/settings/#auth-password-validators @@ -165,6 +136,7 @@ }, ] + # Internationalization # https://docs.djangoproject.com/en/2.0/topics/i18n/ @@ -178,6 +150,7 @@ USE_TZ = True + TEST_RUNNER = 'django_nose.NoseTestSuiteRunner' # Static files (CSS, JavaScript, Images) @@ -201,10 +174,11 @@ if os.path.exists("config.jsonnet"): import json from _jsonnet import evaluate_file - config = json.loads(evaluate_file("config.jsonnet")) for k, v in config.items(): vars()[k] = v + INSTALLED_APPS = INSTALLED_APPS + MODULES -django_heroku.settings(locals()) + +PANEL_URI = "http://localhost:3000" From e7edfb0358e66e263bc39bd77f713a6858db7f66 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 14:55:45 +0100 Subject: [PATCH 34/38] #43-fix: recover react.yml --- .github/workflows/react.yml | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 .github/workflows/react.yml diff --git a/.github/workflows/react.yml b/.github/workflows/react.yml new file mode 100644 index 0000000..20af1bf --- /dev/null +++ b/.github/workflows/react.yml @@ -0,0 +1,34 @@ +name: React CI + +on: + push: + branches: [master, main, develop] + pull_request: + branches: [master, main, develop] + +jobs: + build: + runs-on: ubuntu-latest + + strategy: + matrix: + node-version: [14.x] + + steps: + - uses: actions/checkout@v2 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v1 + with: + node-version: ${{ matrix.node-version }} + - name: Install dependencies + run: | + cd decide/administration/frontend && + npm install + - name: Build app + run: | + cd decide/administration/frontend && + npm run build --if-present + - name: Test app + run: | + cd decide/administration/frontend && + npm run test From 8314788c879046ecb7a8cec8e11a3227b7263560 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 15:38:43 +0100 Subject: [PATCH 35/38] #43-fix: selenium tests --- decide/administration/seleniumT.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/decide/administration/seleniumT.py b/decide/administration/seleniumT.py index d1ac88c..de3e56e 100644 --- a/decide/administration/seleniumT.py +++ b/decide/administration/seleniumT.py @@ -3,8 +3,7 @@ import time import random -''' -README: +'''README: Para poder ejecutar este test, se debe crear un superusuario con el siguiente comando: @@ -76,8 +75,8 @@ def incorrect_log_in(driver, cont): By.XPATH, '//*[@id="content"]/div/form/button').click() time.sleep(1) elemento = driver.find_element( - By.XPATH, '//*[@id="content"]/div/form/div[2]/p') - error_text = 'Unable to log in with provided credentials.' + By.XPATH, '//*[@id="Notifications"]/div/div/div[2]') + error_text = 'ERRORS: non_field_errors:Unable to log in with provided credentials.' if elemento.text == error_text: print("Test correctamente realizado\n") return cont @@ -132,7 +131,7 @@ def make_staff(driver, cont): time.sleep(2) driver.find_element( By.XPATH, '//*[@id="actions"]/div/button[5]').click() - #driver.find_element(By.XPATH, '') + # driver.find_element(By.XPATH, '') print("Test correctamente realizado\n") return cont @@ -153,7 +152,7 @@ def make_superuser(driver, cont): driver.find_element( By.XPATH, '//*[@id="actions"]/div/button[6]').click() # print(element) - #driver.find_element(By.XPATH, '') + # driver.find_element(By.XPATH, '') print("Test correctamente realizado\n") return cont except Exception as e: @@ -383,3 +382,6 @@ def tally_voting(driver, cont): cont2 = delete_voting(driver, cont2) print("Se han realizado los test de Votings") print("Se han encontrado: " + str(cont2) + " errores \n\n") + + print("TESTS FINISHED") + print("Se han encontrado: " + str(cont + cont2) + " errores \n\n") From 4ed9107d651b28f27e81f22ed27c0db840bfba27 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 18:54:37 +0100 Subject: [PATCH 36/38] ci: add remote mongo database --- decide/decide/settings.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/decide/decide/settings.py b/decide/decide/settings.py index c2788fa..b9d5778 100644 --- a/decide/decide/settings.py +++ b/decide/decide/settings.py @@ -154,10 +154,13 @@ DATABASES = { 'default': { 'ENGINE': 'djongo', - 'NAME': 'decide', - 'CLIENT': { - 'host': '127.0.0.1', - } + "CLIENT": { + "name": 'decide', + "host": 'mongodb+srv://decide:@decide.3vypb.mongodb.net/decide?retryWrites=true&w=majority', + "username": 'decide', + "password": 'decide', + "authMechanism": "SCRAM-SHA-1", + }, } } From 544081e33992718f684d8c45e2411f99c7981831 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 19:13:46 +0100 Subject: [PATCH 37/38] test: improve selenium tests guide comment --- decide/administration/seleniumT.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/decide/administration/seleniumT.py b/decide/administration/seleniumT.py index de3e56e..c987b3d 100644 --- a/decide/administration/seleniumT.py +++ b/decide/administration/seleniumT.py @@ -4,22 +4,22 @@ import random '''README: +Preconfiguración: -Para poder ejecutar este test, se debe crear un superusuario -con el siguiente comando: +- ./manage.py flush +- ./manage.py makemigrations +- ./manage.py migrate -./manage.py createsuperuser +- ./manage.py createsuperuser + +- ./manage.py runserver con datos: username: admin password: qwerty y hacer bypass de la restriccion de contraseña -Entrar en http://localhost:8000/administration/users -iniciar sesión con el usuario admin -y si hubiera más usuarios creados, hay que eliminarlos -antes de realizar los tests - +- python seleniumT.py ''' From 45b9ad9545c360e2b8dcaf6109687ca572b12583 Mon Sep 17 00:00:00 2001 From: Jose Nieves Date: Sun, 9 Jan 2022 19:25:07 +0100 Subject: [PATCH 38/38] fix: codacy smells --- decide/administration/frontend/src/api/axios.ts | 2 -- decide/administration/frontend/src/api/userApiUtils.ts | 6 +++--- .../administration/frontend/src/api/votingApiUtils.ts | 10 +++++----- .../frontend/src/components/pages/base/login.tsx | 1 - .../frontend/src/components/pages/users/users.tsx | 4 ---- .../src/components/templates/users/userForm.tsx | 2 -- .../src/components/templates/votings/censusInput.tsx | 3 +-- .../src/components/templates/votings/votingForm.tsx | 1 - decide/administration/frontend/src/index.css | 10 ---------- 9 files changed, 9 insertions(+), 30 deletions(-) diff --git a/decide/administration/frontend/src/api/axios.ts b/decide/administration/frontend/src/api/axios.ts index 01afec1..e48e86f 100644 --- a/decide/administration/frontend/src/api/axios.ts +++ b/decide/administration/frontend/src/api/axios.ts @@ -37,8 +37,6 @@ axios.interceptors.response.use( return response; }, (error) => { - const message = error.response?.data?.message || error.message; - console.warn(message); return Promise.reject(error); } ); diff --git a/decide/administration/frontend/src/api/userApiUtils.ts b/decide/administration/frontend/src/api/userApiUtils.ts index 5e8e179..77eeddc 100644 --- a/decide/administration/frontend/src/api/userApiUtils.ts +++ b/decide/administration/frontend/src/api/userApiUtils.ts @@ -6,13 +6,13 @@ const userApi = { getUsers: () => axios.get("/users"), deleteUsers: (idList: number[]) => axios.delete("/users", { - data: { idList: idList }, + data: { idList }, }), // bulk role/status operations updateUsersActive: (idList: number[], value: boolean) => axios.post("/users/state", { - idList: idList, + idList, state: "Active", value: value ? "True" : "False", }), @@ -22,7 +22,7 @@ const userApi = { role: "Staff" | "Superuser" ) => axios.post("/users/state", { - idList: idList, + idList, state: role, value: value ? "True" : "False", }), diff --git a/decide/administration/frontend/src/api/votingApiUtils.ts b/decide/administration/frontend/src/api/votingApiUtils.ts index 4a0bb3e..cf487b0 100644 --- a/decide/administration/frontend/src/api/votingApiUtils.ts +++ b/decide/administration/frontend/src/api/votingApiUtils.ts @@ -7,7 +7,7 @@ const votingApi = { getQuestions: () => axios.get("/voting/question"), deleteQuestions: (idList: number[]) => axios.delete("/voting/questions", { - data: { idList: idList }, + data: { idList }, }), deleteAllQuestions: () => axios.delete(`/voting/question`), @@ -26,25 +26,25 @@ const votingApi = { getVotings: () => axios.get(`/votings`), deleteVotings: (idList: number[]) => axios.delete("/votings", { - data: { idList: idList }, + data: { idList }, }), deleteAllVotings: () => axios.delete(`/votings`), startVotings: (idList: number[]) => axios.put("/votings", { - idList: idList, + idList, action: "start", }), stopVotings: (idList: number[]) => axios.put("/votings", { - idList: idList, + idList, action: "stop", }), tallyVotings: (idList: number[]) => axios.put("/votings", { - idList: idList, + idList, action: "tally", }), diff --git a/decide/administration/frontend/src/components/pages/base/login.tsx b/decide/administration/frontend/src/components/pages/base/login.tsx index d3d2134..a04160d 100644 --- a/decide/administration/frontend/src/components/pages/base/login.tsx +++ b/decide/administration/frontend/src/components/pages/base/login.tsx @@ -55,7 +55,6 @@ const LoginPage = () => { }; const onSubmit: SubmitHandler = (data) => { - console.log("Login:", data.username); authApi .login(data.username, data.password) .then((r) => { diff --git a/decide/administration/frontend/src/components/pages/users/users.tsx b/decide/administration/frontend/src/components/pages/users/users.tsx index d27c139..5d170dc 100644 --- a/decide/administration/frontend/src/components/pages/users/users.tsx +++ b/decide/administration/frontend/src/components/pages/users/users.tsx @@ -137,7 +137,6 @@ const UsersPage = () => { icon: , title: "Delete", onClick: () => { - console.log("delete"); handleDelete(); }, }, @@ -154,7 +153,6 @@ const UsersPage = () => { : "Mark as Active", disabled: selectionState.active === "mixed", onClick: () => { - console.log("switch active"); selectionState.active === "true" ? handleChangeActive(false) : handleChangeActive(true); @@ -171,7 +169,6 @@ const UsersPage = () => { selectionState.staff === "true" ? "Remove Staff" : "Make Staff", disabled: selectionState.staff === "mixed", onClick: () => { - console.log("switch staff"); selectionState.staff === "true" ? handleChangeRole(false, "Staff") : handleChangeRole(true, "Staff"); @@ -190,7 +187,6 @@ const UsersPage = () => { : "Make SuperUser", disabled: selectionState.su === "mixed", onClick: () => { - console.log("switch staff"); selectionState.su === "true" ? handleChangeRole(false, "Superuser") : handleChangeRole(true, "Superuser"); diff --git a/decide/administration/frontend/src/components/templates/users/userForm.tsx b/decide/administration/frontend/src/components/templates/users/userForm.tsx index 78ff463..baee79c 100644 --- a/decide/administration/frontend/src/components/templates/users/userForm.tsx +++ b/decide/administration/frontend/src/components/templates/users/userForm.tsx @@ -57,8 +57,6 @@ const Component = (props: { }; const onSubmit: SubmitHandler = (data) => { - console.log("submit:", data); - if (Object.keys(errors).length === 0) if (editMode && props.initialUser?.id) { userApi diff --git a/decide/administration/frontend/src/components/templates/votings/censusInput.tsx b/decide/administration/frontend/src/components/templates/votings/censusInput.tsx index 9a6e83a..3b9fac4 100644 --- a/decide/administration/frontend/src/components/templates/votings/censusInput.tsx +++ b/decide/administration/frontend/src/components/templates/votings/censusInput.tsx @@ -21,11 +21,10 @@ const Component = (props: { control: any }) => { userApi .getUsers() .then((response) => { - console.log(response); setUsers(response.data); }) .catch((error) => { - console.log(error); + setUsers([]); }); }, [refetch]); diff --git a/decide/administration/frontend/src/components/templates/votings/votingForm.tsx b/decide/administration/frontend/src/components/templates/votings/votingForm.tsx index e2a3ae2..3622a28 100644 --- a/decide/administration/frontend/src/components/templates/votings/votingForm.tsx +++ b/decide/administration/frontend/src/components/templates/votings/votingForm.tsx @@ -60,7 +60,6 @@ const Component = (props: { }; const onSubmit: SubmitHandler = (data) => { - console.log("submit:", data); if (Object.keys(errors).length === 0) if (editMode && props.initialVoting?.id) { votingApi diff --git a/decide/administration/frontend/src/index.css b/decide/administration/frontend/src/index.css index 4a1df4d..293d3b1 100644 --- a/decide/administration/frontend/src/index.css +++ b/decide/administration/frontend/src/index.css @@ -1,13 +1,3 @@ body { margin: 0; - font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", - "Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue", - sans-serif; - -webkit-font-smoothing: antialiased; - -moz-osx-font-smoothing: grayscale; -} - -code { - font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", - monospace; }