-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from unb-mds/test/webscraping
refactor(utils): cria um app django separado p/ funções do web scraping
- Loading branch information
Showing
15 changed files
with
558 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django.apps import AppConfig | ||
|
||
|
||
class UtilsConfig(AppConfig): | ||
default_auto_field = 'django.db.models.BigAutoField' | ||
name = 'utils' |
File renamed without changes.
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from typing import Any | ||
from utils.sessions import get_response, create_request_session | ||
from django.core.management.base import BaseCommand | ||
from pathlib import Path | ||
import os | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Comando para atualizar os arquivos de mock do SIGAA.""" | ||
|
||
help = "Atualiza os arquivos do mock com as informações do SIGAA requisitadas." | ||
|
||
def handle(self, *args: Any, **options: Any): | ||
current_path = Path(__file__).parent.parent.parent.absolute() | ||
|
||
os.remove(current_path / "mock/departments.html") | ||
with open(current_path / "mock/departments.html", "a") as mockfile: | ||
response = get_response(create_request_session()) | ||
encoding = response.encoding if response.encoding else 'utf-8' | ||
|
||
mockfile.write(response.content.decode(encoding)) |
Large diffs are not rendered by default.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
from rest_framework.test import APITestCase | ||
from .web_scraping import get_list_of_departments | ||
from django.urls import reverse | ||
|
||
|
||
class WebScrapingTest(APITestCase): | ||
|
||
url = reverse('utils:departments') | ||
|
||
def test_get_list_of_departments(self): | ||
response = self.client.get(self.url) | ||
|
||
departments = get_list_of_departments(response) | ||
self.assertEqual(type(list()), type(departments)) | ||
if len(departments): | ||
self.assertEqual(type(str()), type(departments[0])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from django.urls import path | ||
from .views import mocked_departments | ||
|
||
app_name = 'utils' | ||
|
||
urlpatterns = [ | ||
path('mock/departments/', mocked_departments, name='departments'), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django.http import HttpResponse | ||
from pathlib import Path | ||
|
||
|
||
def mocked_departments(request): | ||
mocked_html_path = Path(__file__).parent.absolute() | ||
|
||
with open(mocked_html_path / 'mock/departments.html', 'r') as html_file: | ||
content = html_file.read() | ||
|
||
return HttpResponse(content, content_type='text/html') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters