Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove sort_field option and related tests in story_list #90

Merged
merged 1 commit into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions mediacloud/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _prep_default_params(self, query: str, start_date: dt.date, end_date: dt.dat
collection_ids: Optional[List[int]] = [], source_ids: Optional[List[int]] = [],
platform: Optional[str] = None):
params: Dict[Any, Any] = dict(start=start_date.isoformat(), end=end_date.isoformat(), q=query,
platform=self.PROVIDER)
platform=(platform or self.PROVIDER))
if len(source_ids):
params['ss'] = ",".join([str(sid) for sid in source_ids]),
if len(collection_ids):
Expand All @@ -140,15 +140,13 @@ def story_count_over_time(self, query: str, start_date: dt.date, end_date: dt.da
def story_list(self, query: str, start_date: dt.date, end_date: dt.date, collection_ids: Optional[List[int]] = [],
source_ids: Optional[List[int]] = [], platform: Optional[str] = None,
expanded: Optional[bool] = None, pagination_token: Optional[str] = None,
sort_field: Optional[str] = None, sort_order: Optional[str] = None,
sort_order: Optional[str] = None,
page_size: Optional[int] = None) -> tuple[List[Dict], Optional[str]]:
params = self._prep_default_params(query, start_date, end_date, collection_ids, source_ids, platform)
if expanded:
params['expanded'] = 1
if pagination_token:
params['pagination_token'] = pagination_token
if sort_field:
params['sort_field'] = sort_field
if sort_order:
params['sort_order'] = sort_order
if page_size:
Expand Down
33 changes: 7 additions & 26 deletions mediacloud/test/api_search_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

COLLECTION_US_NATIONAL = 34412234
AU_BROADCAST_COMPANY = 20775
TOMORROW = dt.date.today() + dt.timedelta(days=1)
TOMORROW_TIME = dt.datetime.today() + dt.timedelta(days=1)


Expand Down Expand Up @@ -118,37 +117,19 @@ def test_story_list_sort_order(self):
# desc
page, _ = self._search.story_list(query="weather", start_date=self.START_DATE, end_date=self.END_DATE,
collection_ids=[COLLECTION_US_NATIONAL])
last_pub_date = TOMORROW
last_date = TOMORROW_TIME
for story in page:
assert 'publish_date' in story
assert story['publish_date'] <= last_pub_date
last_pub_date = story['publish_date']
assert 'indexed_date' in story
assert story['indexed_date'] <= last_date
last_date = story['indexed_date']
# asc
page, _ = self._search.story_list(query="weather", start_date=self.START_DATE, end_date=self.END_DATE,
collection_ids=[COLLECTION_US_NATIONAL], sort_order='asc')
a_long_time_ago = dt.date(2000, 1, 1)
last_pub_date = a_long_time_ago
for story in page:
assert 'publish_date' in story
assert story['publish_date'] >= last_pub_date
last_pub_date = story['publish_date']

def test_story_list_sort_field(self):
# publish_date
page, _ = self._search.story_list(query="weather", start_date=self.START_DATE, end_date=self.END_DATE,
collection_ids=[COLLECTION_US_NATIONAL])
last_date = TOMORROW
for story in page:
assert 'publish_date' in story
assert story['publish_date'] <= last_date
last_date = story['publish_date']
# indexed date
page, _ = self._search.story_list(query="weather", start_date=self.START_DATE, end_date=self.END_DATE,
collection_ids=[COLLECTION_US_NATIONAL], sort_field="indexed_date")
last_date = TOMORROW_TIME
a_long_time_ago = dt.datetime(2000, 1, 1, 0, 0, 0)
last_date = a_long_time_ago
for story in page:
assert 'indexed_date' in story
assert story['indexed_date'] <= last_date
assert story['indexed_date'] >= last_date
last_date = story['indexed_date']

def test_search_by_indexed_date(self):
Expand Down
Loading