Skip to content

Commit a9c9f24

Browse files
author
Tomasz-Kluczkowski
committed
Add find_items method and initial test.
1 parent ae0ca37 commit a9c9f24

3 files changed

Lines changed: 53 additions & 0 deletions

File tree

data_extractor.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from websites.resources.data import WEBSITES
2+
3+
4+
class DataExtractor:
5+
"""
6+
Use to extract, cleanse and amend incorrect website data collection.
7+
"""
8+
def __init__(self):
9+
self.data = WEBSITES
10+
11+
def find_items(self, value):
12+
"""
13+
Find and return a new list of items where key "value" is greater than or equal to parameter value.
14+
:return: list(dict), list of dictionaries matching the above filtering rule.
15+
"""
16+
return [item for item in self.data if item.get('value') and item.get('value') >= value]
17+
18+
19+
# data_extractor = DataExtractor()
20+
# print(data_extractor.find_items(4))
21+
# print(len(data_extractor.find_items(4)))

tests/__init__.py

Whitespace-only changes.

tests/test_data_extractor.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import pytest
2+
3+
from data_extractor import DataExtractor
4+
5+
data_extractor = DataExtractor()
6+
7+
8+
class TestDataExtractor:
9+
10+
def test_find_items(self):
11+
expected = [
12+
{
13+
'name': 'Google',
14+
'url': 'https://www.google.co.uk',
15+
'domain': 'google.co.uk',
16+
'secure': True,
17+
'value': 5},
18+
{
19+
'name': 'Facebook',
20+
'url': 'https://developers.facebook.com/blog/post/2018/10/02/facebook-login-update/',
21+
'domain': 'facebook.com',
22+
'secure': True,
23+
'value': 4},
24+
{
25+
'name': 'YouTube',
26+
'url': 'https://www.youtube.com/watch?v=09Cd7NKKvDc',
27+
'domain': 'youtube.com',
28+
'secure': True,
29+
'value': 5
30+
}
31+
]
32+
assert data_extractor.find_items(4) == expected

0 commit comments

Comments
 (0)