Skip to content
Snippets Groups Projects
Commit 748e606f authored by Mohammad Torkashvand's avatar Mohammad Torkashvand
Browse files

fixed tests and linter problems at develop

parent 7c67a1c7
Branches
Tags
No related merge requests found
import re import re
from typing import List
from sqlalchemy import select from sqlalchemy import select
from compendium_v2.db import db, model from compendium_v2.db import db, model
URL_PATTERN = re.compile( URL_PATTERN = re.compile(
r'\b(https?://[^\s<>";,(){}\[\]!\\]+|www\.[^\s<>";,(){}\[\]!\\]+|[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})\b(?=\s|\b|[,!?.;:\\])' (r'\b(https?://[^\s<>";,(){}\[\]!\\]+'
r'|www\.[^\s<>";,(){}\[\]!\\]+'
r'|[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4})'
r'\b(?=\s|\b|[,!?.;:\\])')
) )
...@@ -30,5 +34,5 @@ def get_uppercase_nren_dict(): ...@@ -30,5 +34,5 @@ def get_uppercase_nren_dict():
return nren_dict return nren_dict
def extract_urls(text: str) -> list[str]: def extract_urls(text: str) -> List[str]:
return re.findall(URL_PATTERN, text) return re.findall(URL_PATTERN, text)
...@@ -68,16 +68,13 @@ INSTITUTIONS_URLS_QUERY_UNTIL_2022 = """ ...@@ -68,16 +68,13 @@ INSTITUTIONS_URLS_QUERY_UNTIL_2022 = """
JOIN sections s ON q.section_id = s.id JOIN sections s ON q.section_id = s.id
JOIN compendia c ON s.compendium_id = c.id JOIN compendia c ON s.compendium_id = c.id
WHERE q.id = 16507 WHERE q.id = 16507
UNION ALL UNION ALL
-- Recursive case -- Recursive case
SELECT q.id, q.equivalent_question_id, c.year, q.title SELECT q.id, q.equivalent_question_id, c.year, q.title
FROM questions q FROM questions q
INNER JOIN parent_questions pq ON q.id = pq.equivalent_question_id INNER JOIN parent_questions pq ON q.id = pq.equivalent_question_id
JOIN sections s ON q.section_id = s.id JOIN sections s ON q.section_id = s.id
JOIN compendia c ON s.compendium_id = c.id) JOIN compendia c ON s.compendium_id = c.id)
SELECT DISTINCT ON (n.id, answers.question_id) answers.id, SELECT DISTINCT ON (n.id, answers.question_id) answers.id,
UPPER(n.abbreviation) AS nren, UPPER(n.abbreviation) AS nren,
parent_questions.year, parent_questions.year,
......
...@@ -33,7 +33,10 @@ from compendium_v2.publishers.helpers import extract_urls ...@@ -33,7 +33,10 @@ from compendium_v2.publishers.helpers import extract_urls
("URL with encoded characters: https://example.com/path%20to%20page", ["https://example.com/path%20to%20page"]), ("URL with encoded characters: https://example.com/path%20to%20page", ["https://example.com/path%20to%20page"]),
("URL with encoded query: https://example.com/path?query=value%20with%20space", ("URL with encoded query: https://example.com/path?query=value%20with%20space",
["https://example.com/path?query=value%20with%20space"]), ["https://example.com/path?query=value%20with%20space"]),
("[URL with encoded hash: https://example.com/path#section%20two;]", ["https://example.com/path#section%20two"]), (
"[URL with encoded hash: https://example.com/path#section%20two;]",
["https://example.com/path#section%20two"]
),
] ]
) )
def test_extract_urls_from_a_text(text, expected): def test_extract_urls_from_a_text(text, expected):
......
...@@ -194,10 +194,17 @@ def test_publisher(app_with_survey_db, mocker, dummy_config): ...@@ -194,10 +194,17 @@ def test_publisher(app_with_survey_db, mocker, dummy_config):
('nren3', 'n.a. online'), ('nren3', 'n.a. online'),
] ]
def institutions_urls_data():
return [
(87483, 'ANA', 2013, "http://www.rash.al/index.php/network/points-of-presence-pop"),
(163286, 'ANA', 2014, "http://www.rash.al/index.php/network/points-of-presence-pop"),
]
mocker.patch('compendium_v2.publishers.survey_publisher_2022.query_budget', get_rows_as_tuples) mocker.patch('compendium_v2.publishers.survey_publisher_2022.query_budget', get_rows_as_tuples)
mocker.patch('compendium_v2.publishers.survey_publisher_2022.query_funding_sources', funding_source_data) mocker.patch('compendium_v2.publishers.survey_publisher_2022.query_funding_sources', funding_source_data)
mocker.patch('compendium_v2.publishers.survey_publisher_2022.query_question', question_data) mocker.patch('compendium_v2.publishers.survey_publisher_2022.query_question', question_data)
mocker.patch('compendium_v2.publishers.survey_publisher_2022.query_question_id', question_id_data) mocker.patch('compendium_v2.publishers.survey_publisher_2022.query_question_id', question_id_data)
mocker.patch('compendium_v2.publishers.survey_publisher_2022.query_institutions_urls', institutions_urls_data)
nren_names = ['Nren1', 'Nren2', 'Nren3', 'Nren4', 'SURF', 'KIFU', 'University of Malta', 'ASNET-AM', nren_names = ['Nren1', 'Nren2', 'Nren3', 'Nren4', 'SURF', 'KIFU', 'University of Malta', 'ASNET-AM',
'SIKT', 'LAT', 'RASH', 'ANAS', 'GRNET', 'CSC'] 'SIKT', 'LAT', 'RASH', 'ANAS', 'GRNET', 'CSC']
...@@ -302,3 +309,14 @@ def test_publisher(app_with_survey_db, mocker, dummy_config): ...@@ -302,3 +309,14 @@ def test_publisher(app_with_survey_db, mocker, dummy_config):
assert len(policy_data_2022) == 2 assert len(policy_data_2022) == 2
assert policy_data_2020[0].strategic_plan == 'www.nren.com/somepolicy2020.pdf' assert policy_data_2020[0].strategic_plan == 'www.nren.com/somepolicy2020.pdf'
assert policy_data_2020[1].strategic_plan == 'policyemail@nren.com' assert policy_data_2020[1].strategic_plan == 'policyemail@nren.com'
_institution_urls_data = db.session.scalars(
select(model.InstitutionURLs).order_by(model.InstitutionURLs.nren_id.asc())
).all()
assert len(_institution_urls_data) == 2
assert _institution_urls_data[0].nren.name.lower() == 'rash'
assert _institution_urls_data[0].year == 2013
assert _institution_urls_data[0].urls == ["http://www.rash.al/index.php/network/points-of-presence-pop"]
assert _institution_urls_data[1].nren.name.lower() == 'rash'
assert _institution_urls_data[1].year == 2014
assert _institution_urls_data[1].urls == ["http://www.rash.al/index.php/network/points-of-presence-pop"]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment