Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Juamarher7 #85

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
name: Python application

on: [push]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
pyversion: ['3.8', '3.5']
pgversion: ['10.8', '12']

services:
postgres:
image: postgres:${{matrix.pgversion}}
env:
POSTGRES_USER: decide
POSTGRES_PASSWORD: decide
POSTGRES_DB: decide
ports:
- 5432:5432
# needed because the postgres container does not provide a healthcheck
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{matrix.pyversion}}
uses: actions/setup-python@v2
with:
python-version: ${{matrix.pyversion}}
- name: psycopg2 prerequisites
run: sudo apt-get install libpq-dev
- name: Install dependencies and config
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install codacy-coverage
cp decide/local_settings.gactions.py decide/local_settings.py
- name: Run migrations (unnecessary)
run: |
cd decide
python manage.py migrate
- name: Run tests
run: |
cd decide
coverage run --branch --source=. ./manage.py test --keepdb
coverage xml
- name: Codacy Coverage Reporter
uses: codacy/codacy-coverage-reporter-action@v1
with:
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
coverage-reports: decide/coverage.xml
19 changes: 19 additions & 0 deletions .github/workflows/simpleWF.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: GitHub Actions Demo
on: [push]
jobs:
Explore-GitHub-Actions:
runs-on: ubuntu-latest
steps:
- run: echo "🎉 The job was automatically triggered by a ${{ github.event_name }} event."
- run: echo "🐧 This job is now running on a ${{ runner.os }} server hosted by GitHub!"
- run: echo "🔎 The name of your branch is ${{ github.ref }} and your repository is ${{ github.repository }}."
- name: Check out repository code
uses: actions/checkout@v1
- run: echo "💡 The ${{ github.repository }} repository has been cloned to the runner."
- run: echo "🖥️ The workflow is now ready to test your code on the runner."
- name: List files in the repository
run: |
ls ${{ github.workspace }}
- run: echo "🍏 This job's status is ${{ job.status }}."
- name: Contains expresion in a step
run: echo "Is this branch master or develop? ${{ contains('refs/heads/master refs/heads/develop',github.ref)}}"
65 changes: 65 additions & 0 deletions decide/authentication/tests_auth.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from pyexpat import model
from django.test import TestCase
from django.contrib.staticfiles.testing import StaticLiveServerTestCase

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys

from base.tests import BaseTestCase
from voting.models import Question, Voting

class AdminTestCase(StaticLiveServerTestCase):


def setUp(self):
#Load base test functionality for decide
self.base = BaseTestCase()
self.base.setUp()

options = webdriver.ChromeOptions()
options.headless = False
self.driver = webdriver.Chrome(options=options)

super().setUp()

def tearDown(self):
super().tearDown()
self.driver.quit()

self.base.tearDown()

def test_simpleVisualizer(self):
q = Question(desc='test question')
q.save()
v = Voting(name='test voting', question=q)
v.save()
response =self.driver.get(f'{self.live_server_url}/visualizer/{v.pk}/')
vState= self.driver.find_element(By.TAG_NAME,"h2").text
self.assertTrue(vState, "Votación no comenzada")

def test_simpleCorrectLogin(self):
self.driver.get(f'{self.live_server_url}/admin/')
self.driver.find_element(By.ID,'id_username').send_keys("admin")
self.driver.find_element(By.ID,'id_password').send_keys("qwerty",Keys.ENTER)

print(self.driver.current_url)
#In case of a correct loging, a element with id 'user-tools' is shown in the upper right part
self.assertTrue(len(self.driver.find_elements(By.ID,'user-tools'))==1)

def test_Admin_Login_fail(self):
self.driver.get(f'{self.live_server_url}/admin/')
data = {'id_username': 'voter1', 'id_password': '321'}
response = self.client.post('/authentication/login/', data, format='json')

self.assertEqual(response.status_code, 400)


class SimpleTest(TestCase):
def test_basic_addition(self):
self.assertEqual(1 + 1, 2)



2 changes: 1 addition & 1 deletion decide/booth/templates/booth/booth.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ <h2>[[ voting.question.desc ]]</h2>
<script src="{% static "crypto/elgamal.js" %}"></script>

<!-- Vuejs -->
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vue@2.7.3"></script>
<script src="https://unpkg.com/babel-polyfill@latest/dist/polyfill.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>

Expand Down
2 changes: 2 additions & 0 deletions decide/census/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@


class CensusAdmin(admin.ModelAdmin):
#list_display = ('voting_id', 'voter_id','adscripcion_id')
list_display = ('voting_id', 'voter_id')
list_filter = ('voting_id', )

#search_fields = ('voter_id','adscripcion_id', )
search_fields = ('voter_id', )


Expand Down
3 changes: 2 additions & 1 deletion decide/census/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class Census(models.Model):
voting_id = models.PositiveIntegerField()
voter_id = models.PositiveIntegerField()

#adscripcion_id = models.PositiveIntegerField()
class Meta:
#unique_together = (('voting_id', 'voter_id','adscripcion_id'),)
unique_together = (('voting_id', 'voter_id'),)
3 changes: 3 additions & 0 deletions decide/census/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ class CensusCreate(generics.ListCreateAPIView):
def create(self, request, *args, **kwargs):
voting_id = request.data.get('voting_id')
voters = request.data.get('voters')
#adscripcion_id = request.data.get('adscripcion_id')
try:
for voter in voters:
#census = Census(voting_id=voting_id, voter_id=voter, adscripcion_id=adscripcion_id)
census = Census(voting_id=voting_id, voter_id=voter)
census.save()
except IntegrityError:
Expand All @@ -30,6 +32,7 @@ def create(self, request, *args, **kwargs):

def list(self, request, *args, **kwargs):
voting_id = request.GET.get('voting_id')
#adscripcion_id = request.GET.get('adscripcion_id')
voters = Census.objects.filter(voting_id=voting_id).values_list('voter_id', flat=True)
return Response({'voters': voters})

Expand Down
13 changes: 13 additions & 0 deletions decide/decide/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
Expand Down Expand Up @@ -151,6 +152,9 @@
USE_TZ = True





TEST_RUNNER = 'django_nose.NoseTestSuiteRunner'

# Static files (CSS, JavaScript, Images)
Expand Down Expand Up @@ -180,3 +184,12 @@


INSTALLED_APPS = INSTALLED_APPS + MODULES
from django.utils.translation import ugettext_lazy as _
LANGUAGES = [
('es', _('Español')),
('en-us', _('English')),
('de', _('German'))
]
LOCALE_PATHS = [
os.path.join(BASE_DIR, 'locale')
]
42 changes: 42 additions & 0 deletions decide/local_settings.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
ALLOWED_HOSTS = ["*"]

# Modules in use, commented modules that you won't use
MODULES = [
'authentication',
'base',
'booth',
'census',
'mixnet',
'postproc',
'store',
'visualizer',
'voting',
]

APIS = {
'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': 'django.db.backends.postgresql',
'NAME': 'postgres',
'USER': 'decide',
'PASSWORD': 'complexpassword',
'HOST': 'localhost',
'PORT': '5432',
}
}

# number of bits for the key, all auths should use the same number of bits
KEYBITS = 256
64 changes: 64 additions & 0 deletions decide/locale/es/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# SOME DESCRIPTIVE TITLE.
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
# This file is distributed under the same license as the PACKAGE package.
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
#
#, fuzzy
msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-17 19:27+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"Language: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n != 1);\n"

#: booth/templates/booth/booth.html:19
msgid "logout"
msgstr ""

#: booth/templates/booth/booth.html:33
msgid "Username"
msgstr "Que"

#: booth/templates/booth/booth.html:41
msgid "Password"
msgstr "Pasa"

#: booth/templates/booth/booth.html:49
msgid "Login"
msgstr "Perro"

#: booth/templates/booth/booth.html:64
msgid "Vote"
msgstr ""

#: booth/templates/booth/booth.html:160 booth/templates/booth/booth.html:170
#: booth/templates/booth/booth.html:201
msgid "Error: "
msgstr ""

#: booth/templates/booth/booth.html:198
msgid "Conglatulations. Your vote has been sent"
msgstr ""

#: decide/settings.py:189
msgid "Español"
msgstr ""

#: decide/settings.py:190
msgid "English"
msgstr ""

#: decide/settings.py:191
msgid "German"
msgstr ""

#: visualizer/templates/visualizer/visualizer.html:25
msgid "result"
msgstr "Resultado de la votación"
4 changes: 2 additions & 2 deletions decide/visualizer/templates/visualizer/visualizer.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ <h1>[[ voting.id ]] - [[ voting.name ]]</h1>
<h2 v-if="!voting.start_date">Votación no comenzada</h2>
<h2 v-else-if="!voting.end_date">Votación en curso</h2>
<div v-else>
<h2 class="heading">Resultados:</h2>
<h2 class="heading">{% trans "result" %}</h2>

<table class="table table-bordered table-striped">
<thead>
Expand All @@ -48,7 +48,7 @@ <h2 class="heading">Resultados:</h2>

{% block extrabody %}
<!-- Vuejs -->
<script src="https://unpkg.com/vue"></script>
<script src="https://unpkg.com/vue@2.7.3"></script>
<script src="https://unpkg.com/babel-polyfill@latest/dist/polyfill.min.js"></script>
<script src="https://unpkg.com/bootstrap-vue@latest/dist/bootstrap-vue.js"></script>

Expand Down
2 changes: 2 additions & 0 deletions decide/voting/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,5 @@ def do_postproc(self):

def __str__(self):
return self.name


Loading