Ver código fonte

Fix setup and add tests

JoostSijm 4 anos atrás
pai
commit
7318966b78
6 arquivos alterados com 87 adições e 1 exclusões
  1. 7 1
      .gitignore
  2. 4 0
      setup.py
  3. 0 0
      tests/__init__.py
  4. 28 0
      tests/conftest.py
  5. 34 0
      tests/test_vboo_info_bot_functions.py
  6. 14 0
      tox.ini

+ 7 - 1
.gitignore

@@ -1,4 +1,10 @@
 __pycache__/
+tests/cassettes/
+build/
 .venv/
-.env
+.tox/
+*.egg-info/
+output.log
 *.log
+*.pyc
+.env

+ 4 - 0
setup.py

@@ -16,10 +16,14 @@ setuptools.setup(
     url="gogs@git.craftbroec.nl:joostsijm/vboo_info_bot.git",
     packages=setuptools.find_packages('src'),
     package_dir={'': 'src'},
+    entry_points={
+        'console_scripts': ['vboo-info-bot=vboo_info_bot.__main__:main'],
+    },
     install_requires=[
         "python-telegram-bot",
         "python-dotenv",
         "hyperlink",
+        "rival-regions-wrapper @ git+https://github.com/jjoo914/rival_regions_wrapper.git",
     ],
     classifiers=[
         "Programming Language :: Python :: 3",

+ 0 - 0
tests/__init__.py


+ 28 - 0
tests/conftest.py

@@ -0,0 +1,28 @@
+"""Test configuration"""
+
+import os
+
+from rival_regions_wrapper import LocalAuthentication, ApiWrapper
+from dotenv import load_dotenv
+import pytest
+
+
+load_dotenv()
+
+class MissingAuthenticationError(Exception):
+    """Error for missing authentication"""
+
+
+@pytest.fixture(scope="module")
+def api_wrapper():
+    """Set up wrapper before test"""
+    rr_username = os.environ.get('RIVAL_REGIONS_USERNAME', None)
+    rr_password = os.environ.get('RIVAL_REGIONS_PASSWORD', None)
+    rr_login_method = os.environ.get('RIVAL_REGIONS_LOGIN_METHOD', None)
+    if None in (rr_username, rr_password, rr_login_method):
+        raise MissingAuthenticationError(
+            'Load the following variables in your user environment: '
+            'RIVAL_REGIONS_USERNAME, RIVAL_REGIONS_PASSWORD, RIVAL_REGIONS_LOGIN_METHOD'
+        )
+    authentication = LocalAuthentication(rr_username, rr_password, rr_login_method)
+    return ApiWrapper(authentication)

+ 34 - 0
tests/test_vboo_info_bot_functions.py

@@ -0,0 +1,34 @@
+"""Wrapper test"""
+
+from rival_regions_wrapper.api_wrapper import Article
+import pytest
+
+from vboo_info_bot import functions
+
+
+@pytest.fixture
+def article_keys():
+    """Standard key fro article"""
+    return ['article_id', 'article_title', 'newspaper_id', 'newspaper_name', \
+        'author_name', 'author_id', 'region_name', 'region_id', 'content_text', 'content_html', \
+        'language']
+
+@pytest.mark.vcr()
+def test_article_info(api_wrapper, article_keys):
+    """Test article info"""
+    article_id = 2708696
+    response = Article(api_wrapper).info(article_id)
+
+    assert isinstance(response, dict), "The resonse should be a dict"
+    assert set(article_keys).issubset(response.keys()), "All keys should be in the response"
+    assert isinstance(response['article_id'], int), "Article id should be an integer"
+    assert isinstance(response['article_title'], str), "Article title should be a str"
+    assert isinstance(response['newspaper_id'], int), "Newspaper id should be an integer"
+    assert isinstance(response['newspaper_name'], str), "Newspaper name should be a string"
+    assert isinstance(response['author_name'], str), "Author name should be a string"
+    assert isinstance(response['author_id'], int), "Author id should be an integer"
+    assert isinstance(response['region_name'], str), "Region name should be a string"
+    assert isinstance(response['region_id'], int), "Region id should be an integer"
+    assert isinstance(response['content_text'], str), "Content text should be a string"
+    assert isinstance(response['content_html'], str), "Content html should be a string"
+    assert isinstance(response['language'], str), "Language should be a string"

+ 14 - 0
tox.ini

@@ -0,0 +1,14 @@
+# tox (https://tox.readthedocs.io/) is a tool for running tests
+# in multiple virtualenvs. This configuration file will run the
+# test suite on all supported python versions. To use it, "pip install tox"
+# and then run "tox" from this directory.
+
+[tox]
+envlist = py38
+
+[testenv]
+deps =
+    pytest
+    pytest-vcr
+commands =
+    pytest