File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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)))
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments