diff --git a/setup.py b/setup.py
index 758caec..8899294 100644
--- a/setup.py
+++ b/setup.py
@@ -61,7 +61,7 @@
install_requires=[
"click>=5.1", "Pillow==6.0.0", "pytesseract==0.2.6",
"requests==2.22.0", "scikit-learn==0.21.2", "nltk>=3.4.3",
- "python-dateutil==2.8.0",
+ "python-dateutil==2.8.0", "werkzeug==0.15.4",
"twint @ git+https://github.com/twintproject/twint.git"
],
entry_points={
diff --git a/tests/static/real-tweet.png b/tests/static/real-tweet.png
index 6c8a2ca..9a3eaaf 100644
Binary files a/tests/static/real-tweet.png and b/tests/static/real-tweet.png differ
diff --git a/tests/test_controller.py b/tests/test_controller.py
new file mode 100644
index 0000000..bf23146
--- /dev/null
+++ b/tests/test_controller.py
@@ -0,0 +1,67 @@
+# Verify Tweet verifies tweets of a public user
+# from tweet screenshots: real or generated from
+# tweet generators.
+# Copyright (C) 2019 Preetham Kamidi
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see .
+
+import pytest
+
+from verifytweet import controller
+from verifytweet import result
+
+non_api_approach = controller.NonAPIApproach()
+
+
+def test_exec_empty_input():
+ """Test exec for empty input
+ """
+ with pytest.raises(TypeError):
+ non_api_approach.exec()
+
+
+def test_exec_invalid_type_input():
+ """Test exec for invalid type input
+ """
+ with pytest.raises(TypeError):
+ non_api_approach.exec(None)
+ non_api_approach.exec(123)
+ non_api_approach.exec(['/home/'])
+
+
+def test_exec_invalid_input():
+ """Test exec for valid type invalid input
+ """
+ with pytest.raises(ValueError):
+ non_api_approach.exec('')
+ assert non_api_approach.exec(
+ '123')[1] == result.ResultStatus.MODULE_FAILURE
+ assert non_api_approach.exec(
+ '/home')[1] == result.ResultStatus.MODULE_FAILURE
+ assert non_api_approach.exec(
+ 'tmp.png')[1] == result.ResultStatus.MODULE_FAILURE
+
+
+def test_exec_valid_input(file_path):
+ """Test exec for valid input
+ """
+ from twint.tweet import tweet
+
+ test_result_tweet = 'ey send me stolen pdp wave designs'
+ test_result_username = 'pewdiepie'
+ module_result, module_status = non_api_approach.exec(file_path)
+ assert module_status == result.ResultStatus.ALL_OKAY
+ assert isinstance(module_result, tweet)
+ assert test_result_tweet in module_result.tweet
+ assert test_result_username == module_result.username
diff --git a/tests/test_uploader.py b/tests/test_uploader.py
index 018a171..b3c3fe5 100644
--- a/tests/test_uploader.py
+++ b/tests/test_uploader.py
@@ -21,6 +21,7 @@
from werkzeug.datastructures import FileStorage
from verifytweet import uploader
+from verifytweet import settings
def test_save_to_disk_empty_input():
@@ -51,6 +52,9 @@ def test_save_to_disk_invalid_input():
def test_save_to_disk_valid_input(file_path):
"""Test save to disk for valid file object
"""
+ app_config = settings.app_config
+ app_config.ALLOWED_EXTENSIONS = set(["png", "jpg", "jpeg"])
+
with open(file_path, 'rb') as f:
test_file_obj = FileStorage(f)
test_file_name = uploader.save_to_disk(test_file_obj)
diff --git a/verifytweet/cli.py b/verifytweet/cli.py
index b4e9538..eebd571 100644
--- a/verifytweet/cli.py
+++ b/verifytweet/cli.py
@@ -17,11 +17,8 @@
# along with this program. If not, see .
import os
-
import click
-os.environ["VERIFYTWEET_RUN_FROM_CLI"] = "true"
-
from .services import controller
from .config.settings import app_config
from .util.logging import logger
diff --git a/verifytweet/config/settings.py b/verifytweet/config/settings.py
index e364a84..721523f 100644
--- a/verifytweet/config/settings.py
+++ b/verifytweet/config/settings.py
@@ -43,7 +43,7 @@ class Config(object):
FILE_DIRECTORY = tempfile.mkdtemp()
TWEET_MAX_STORE = 150
RUN_METHOD = "cli"
- LOG_LEVEL = logging.DEBUG if os.getenv('VERBOSE_LOGS') else logging.INFO
+ LOG_LEVEL = logging.DEBUG if os.getenv('DEBUG') else logging.INFO
class TwitterAPIConfig(Config):
@@ -77,7 +77,7 @@ class WebConfig(Config):
ALLOWED_EXTENSIONS = set(["png", "jpg", "jpeg"])
-run_method = "cli" if "VERIFYTWEET_RUN_FROM_CLI" in os.environ else "web"
+run_method = "web" if "VERIFYTWEET_RUN_FOR_WEB" in os.environ else "cli"
Config.RUN_METHOD = run_method
configurations = {"web": WebConfig, "cli": Config}
diff --git a/verifytweet/services/search.py b/verifytweet/services/search.py
index b541df7..15f3b25 100644
--- a/verifytweet/services/search.py
+++ b/verifytweet/services/search.py
@@ -152,18 +152,19 @@ def search(self, user_id: str, date: datetime.datetime,
)
if not user_id or not date or not tweet_snippet:
raise ValueError('User ID, Tweet or Date cannot be empty')
+ results = list()
twint_config = twint.Config()
twint_config.Username = user_id
twint_config.Search = tweet_snippet
twint_config.Since = date_checker.format_for_date(date)
twint_config.Limit = app_config.TWEET_MAX_STORE
twint_config.Store_object = True
+ twint_config.Store_object_tweets_list = results
try:
twint.run.Search(twint_config)
except Exception as e:
logger.exception(e)
return (None, ResultStatus.MODULE_FAILURE)
- results = twint.output.tweets_object
if not results:
return (results, ResultStatus.NO_RESULT)
logger.debug(f'Search results: {results}\n')
diff --git a/verifytweet/util/logging.py b/verifytweet/util/logging.py
index 63d51ab..ef0b7e1 100644
--- a/verifytweet/util/logging.py
+++ b/verifytweet/util/logging.py
@@ -21,7 +21,7 @@
from verifytweet.config.settings import app_config
-logger = logging.getLogger()
+logger = logging.getLogger('verify_logger')
logger.setLevel(app_config.LOG_LEVEL)
handler = logging.StreamHandler(sys.stdout)
diff --git a/wsgi.py b/wsgi.py
index 627cdf2..7fa6e39 100644
--- a/wsgi.py
+++ b/wsgi.py
@@ -24,6 +24,8 @@
import gunicorn.app.base
from gunicorn.six import iteritems
+os.environ["VERIFYTWEET_RUN_FOR_WEB"] = "true"
+
from verifytweet.config.settings import app_config
from verifytweet.app import router