diff --git a/.travis.yml b/.travis.yml index 7fea960..9b39621 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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" diff --git a/airflow/modules/rss_news/rss_news_producer.py b/airflow/modules/rss_news/rss_news_producer.py index bb968ca..ff0bb42 100644 --- a/airflow/modules/rss_news/rss_news_producer.py +++ b/airflow/modules/rss_news/rss_news_producer.py @@ -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, @@ -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 diff --git a/airflow/modules/tests/rss_news/test_rss_news_producer.py b/airflow/modules/tests/rss_news/test_rss_news_producer.py index 40505e1..39e990d 100644 --- a/airflow/modules/tests/rss_news/test_rss_news_producer.py +++ b/airflow/modules/tests/rss_news/test_rss_news_producer.py @@ -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(