Skip to content

Commit

Permalink
Merge pull request #109 from ICESI-PI1-2024A-G1/test-refactoring
Browse files Browse the repository at this point in the history
Test refactoring
  • Loading branch information
Mendo6472 authored May 13, 2024
2 parents 0698264 + 93bcb16 commit 4e4956a
Show file tree
Hide file tree
Showing 18 changed files with 818 additions and 123 deletions.
53 changes: 26 additions & 27 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,39 @@ name: Django CI

on:
push:
branches: [ "main", "develop" ]
branches: ["main", "develop"]
pull_request:
branches: [ "main", "develop"]
branches: ["main", "develop"]

jobs:
build:

runs-on: ubuntu-latest
strategy:
max-parallel: 4
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: [3.12.2, 3.11.9, 3.10.14]

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
cd hiring_module
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Copy .env file
run: |
cd hiring_module
cp .example.env .env
- name: Run Tests
run: |
export DISPLAY=:99
chromedriver --url-base=/wd/hub &
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional
cd hiring_module
python manage.py makemigrations hiring_app
python manage.py migrate
python manage.py test
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
cd hiring_module
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: Copy .env file
run: |
cd hiring_module
cp .example.env .env
- name: Run Tests
run: |
export DISPLAY=:99
chromedriver --url-base=/wd/hub &
sudo Xvfb -ac :99 -screen 0 1280x1024x24 > /dev/null 2>&1 & # optional
cd hiring_module
python manage.py makemigrations hiring_app
python manage.py migrate
python manage.py test
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends 'base.html' %}
{% load static %}
{% block title %}
Panel de control
Lista de usuarios
{% endblock %}


Expand Down Expand Up @@ -60,7 +60,7 @@

<!-- Page Heading -->
<div class="d-sm-flex align-items-center justify-content-between mb-4">
<h1 class="h3 mb-0 text-gray-800">Panel de control</h1>
<h1 class="h3 mb-0 text-gray-800">Lista de usuarios</h1>
</div>

<!-- Content center -->
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<div class="container-fluid p-0">

<!-- Page Heading -->
<h1 class="h3 mb-2 text-gray-800">Solicitudes de contratación</h1>
<h1 class="h3 mb-2 text-gray-800">Lista de usuarios</h1>
<!-- DataTales Example -->
<div class="card shadow mb-4">
<div class="card-header py-3 d-flex justify-content-between align-items-center">
<h6 class="m-0 font-weight-bold text-primary">Listado de solicitudes de contratación</h6>
<h6 class="m-0 font-weight-bold text-primary">Listado de usuarios del equipo</h6>
<a id="addUser" href="add_user/" class="btn btn-primary btn-icon-split">
<span class="text">Agregar usuario</span>
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<li class="nav-item active">

<a class="nav-link" href="{% url 'hiring_app:administrator_dashboard' %}">
<a id="ControlPanel" class="nav-link" href="{% url 'hiring_app:administrator_dashboard' %}">
<i class="fas fa-fw fa-tachometer-alt"></i>
<span>Panel de control</span>
</a>
Expand All @@ -29,7 +29,7 @@
{% endif %}

{% if actualgroup != "external" %}
<a class="nav-link" href="{% url 'hiring_app:statistics' %}">
<a id="Statistics" class="nav-link" href="{% url 'hiring_app:statistics' %}">
<i class="fas fa-fw fa-file-contract"></i>
<span>Estadisticas</span>
</a>
Expand Down
2 changes: 1 addition & 1 deletion hiring_module/hiring_app/tests/functionality/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from .auth import *

from .control_board import *
from .left_panel import *

from .request_creation import *

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .admin_user import *
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def tearDownClass(cls):
super().tearDownClass()


def test_add_user(self):
def test_external_to_manager(self):
self.selenium.get(self.live_server_url)

username_input = self.selenium.find_element(By.NAME,'id')
Expand All @@ -38,7 +38,7 @@ def test_add_user(self):
self.selenium.find_element(By.ID, 'UserList').click()

time.sleep(2)
self.assertEqual('Panel de control', self.selenium.title)
self.assertEqual('Lista de usuarios', self.selenium.title)


self.selenium.find_element(By.ID, 'addUser').click()
Expand All @@ -52,10 +52,69 @@ def test_add_user(self):
time.sleep(2)


user = self.selenium.find_element(By.ID, '1106293874').text
user = self.selenium.find_element(By.ID, '1106293874_id').text

self.assertIn('1106293874', user)

def test_manager_to_leader(self):
self.selenium.get(self.live_server_url)

username_input = self.selenium.find_element(By.NAME, 'id')
password_input = self.selenium.find_element(By.NAME, 'password')
username_input.send_keys('1116070867')
password_input.send_keys('juandiaz123')

password_input.send_keys(Keys.RETURN)
self.assertIn('Panel de control de Administrador', self.selenium.title)

self.selenium.find_element(By.ID, 'UserList').click()

time.sleep(2)
self.assertEqual('Lista de usuarios', self.selenium.title)

self.selenium.find_element(By.ID, 'roleSelect_1111539567').send_keys('leader')

time.sleep(2)

self.assertEqual('1111539567', self.selenium.find_element(By.ID, '1111539567_id').text)

select_element = self.selenium.find_element(By.ID, "roleSelect_1111539567")

selected_option = select_element.find_element(By.CSS_SELECTOR, "option:checked")

selected_value = selected_option.get_attribute("value")

self.assertEqual('leader', selected_value)

def test_leader_to_admin(self):
self.selenium.get(self.live_server_url)

username_input = self.selenium.find_element(By.NAME, 'id')
password_input = self.selenium.find_element(By.NAME, 'password')
username_input.send_keys('1116070867')
password_input.send_keys('juandiaz123')

password_input.send_keys(Keys.RETURN)
self.assertIn('Panel de control de Administrador', self.selenium.title)

self.selenium.find_element(By.ID, 'UserList').click()

time.sleep(2)
self.assertEqual('Lista de usuarios', self.selenium.title)

self.selenium.find_element(By.ID, 'roleSelect_1109185879').send_keys('administrator')

time.sleep(2)

self.assertEqual('1109185879', self.selenium.find_element(By.ID, '1109185879_id').text)

select_element = self.selenium.find_element(By.ID, "roleSelect_1109185879")

selected_option = select_element.find_element(By.CSS_SELECTOR, "option:checked")

selected_value = selected_option.get_attribute("value")

self.assertEqual('admin', selected_value)


def test_delete_user(self):
Expand All @@ -75,15 +134,13 @@ def test_delete_user(self):
self.selenium.find_element(By.ID, 'UserList').click()

time.sleep(2)
self.assertEqual('Panel de control', self.selenium.title)
self.assertEqual('Lista de usuarios', self.selenium.title)

self.selenium.find_element(By.ID, 'roleSelect_1109185879').send_keys('remove')

time.sleep(2)


try:
self.selenium.find_element(By.ID, 'addUser').click()
except StaleElementReferenceException:
self.selenium.find_element(By.ID, 'addUser').click()
self.selenium.find_element(By.ID, 'addUser').click()

self.assertEqual('1109185879', self.selenium.find_element(By.ID, '1109185879_id').text)

24 changes: 24 additions & 0 deletions hiring_module/hiring_app/tests/functionality/auth/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,27 @@ def test_login_external_user(self):
password_input.send_keys(Keys.RETURN)

self.assertIn('Panel de control de usuario externo', self.selenium.title)

def test_login_wrong_password(self):
self.selenium.get(self.live_server_url)

username_input = self.selenium.find_element(By.NAME,'id')
password_input = self.selenium.find_element(By.NAME, 'password')
username_input.send_keys('1116070867')
password_input.send_keys('juandiaz')

password_input.send_keys(Keys.RETURN)

self.assertIn('Log In', self.selenium.title)

def test_login_wrong_username(self):
self.selenium.get(self.live_server_url)

username_input = self.selenium.find_element(By.NAME,'id')
password_input = self.selenium.find_element(By.NAME, 'password')
username_input.send_keys('111607086')
password_input.send_keys('juandiaz123')

password_input.send_keys(Keys.RETURN)

self.assertIn('Log In', self.selenium.title)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .left_panel_navitagion import *
Loading

0 comments on commit 4e4956a

Please sign in to comment.