Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
damklis committed Aug 3, 2020
1 parent 54f5b30 commit 83caa33
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ services:
before_script: pip install docker-compose

script:
- docker-compose run airflow sh -c "python -m pytest --show-capture=no"
- docker-compose run airflow sh -c "python -m pytest -v --show-capture=no"
10 changes: 4 additions & 6 deletions airflow/modules/rss_news/rss_news_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ class NewsFormatter:
def format_entry(self, entry):
_id = self.construct_id(entry.title)
published_date = self.unify_date(entry.pub_date)
description = self.format_description(
entry.description, entry.title
)
description = self.format_description(entry)
author = self.assign_author(entry.author)
return News(
_id,
Expand All @@ -63,13 +61,13 @@ def unify_date(date):
return date.strftime("%Y-%m-%d %H:%M:%S")

@staticmethod
def format_description(description, title):
tmp_description = re.sub("<.*?>", "", description[:1000])
def format_description(entry):
tmp_description = re.sub("<.*?>", "", entry.description[:1000])
index = tmp_description.rfind(".")
short_description = tmp_description[:index+1]
return (
short_description if short_description
else title
else entry.title
)

@staticmethod
Expand Down
21 changes: 12 additions & 9 deletions airflow/modules/tests/rss_news/test_rss_news_producer.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,23 @@ def test_unify_date(formatter):

def test_format_description(formatter):
expected = """Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."""
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."""

description = """Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation"""
class Entry:
description = """Lorem ipsum dolor sit amet, consectetur adipiscing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation"""
title = "Lorem ipsum"

title = "Lorem ipsum"
class EmptyEntry:
description = ""
title = "Lorem ipsum"

empty_description = ""
result = formatter.format_description(Entry)
result_empty = formatter.format_description(EmptyEntry)

result = formatter.format_description(description, title)
result_empty = formatter.format_description(empty_description, title)
assert result == expected
assert result_empty == title
assert result_empty == EmptyEntry.title


@pytest.mark.parametrize(
Expand Down

0 comments on commit 83caa33

Please sign in to comment.