Skip to content

Commit

Permalink
add finction for getting active releases and unit test for it
Browse files Browse the repository at this point in the history
  • Loading branch information
vlaszdunov committed Jun 4, 2024
1 parent da2eea6 commit dfbe49a
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/source.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
response = requests.get(URL, request_headers).text

page_data = bs(response, 'lxml')
page_data.con

actual_versions_raw_list = page_data.find_all(
'span', attrs={'class': 'release-version'})

Expand Down
14 changes: 12 additions & 2 deletions src/version_parser.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
from pathlib import Path
import re

import requests
from bs4 import BeautifulSoup as bs
Expand All @@ -13,5 +14,14 @@ def get_page_content(internal_page: str = '') -> bs:
return bs(page_content, 'lxml')


def get_active_versions(versions_page_internal_url: str):
pass
def get_active_versions(internal_url: str) -> list[str]:
page_content = get_page_content(internal_url)
active_versions_raw_list = page_content.find_all(
'span', attrs={'class': 'release-version'})

active_versions_list = []
for element in active_versions_raw_list:
if re.match(r'\d+.\d+', element.text):
active_versions_list.append(element.text)

return active_versions_list
8 changes: 8 additions & 0 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import pytest

from src.version_parser import *

BASE_URL = 'https://www.python.org/'
Expand All @@ -7,3 +8,10 @@
def test_get_page_content():
page_content = get_page_content(BASE_URL)
assert len(page_content.contents) != 0


def test_get_versions():
# Проверяем, что функция get_versions() использует результаты get_data()
actual_versions = get_active_versions('downloads/')
# Предположим, что это версии, которые мы ожидаем получить
assert actual_versions.__class__==list

0 comments on commit dfbe49a

Please sign in to comment.