1
0
mirror of https://github.com/balkian/bitter.git synced 2024-12-22 08:28:12 +00:00

Drone tests, fixed get_credentials

This commit is contained in:
J. Fernando Sánchez 2016-09-15 13:56:17 +02:00
parent 17f589c710
commit 6ebb82ba54
12 changed files with 93 additions and 21 deletions

View File

@ -3,6 +3,7 @@ From python:2.7.9-onbuild
Maintainer J. Fernando Sánchez @balkian Maintainer J. Fernando Sánchez @balkian
# RUN pip --cert cacert.pem install -r -v requirements.txt # RUN pip --cert cacert.pem install -r -v requirements.txt
ADD . /usr/src/app/
RUN pip install --editable .; RUN pip install -e "/usr/src/app/[server]"
ENTRYPOINT ["bitter"] ENTRYPOINT ["bitter"]

View File

@ -1,3 +1,6 @@
include requirements.txt include requirements.txt
include test-requirements.txt include test-requirements.txt
include README.md include README.md
graft bitter/templates
graft bitter/static
graft test

View File

@ -41,6 +41,14 @@ To add more users to the credentials file, you may run the builtin server, with
python -m bitter server <consumer_key> <consumer_secret> python -m bitter server <consumer_key> <consumer_secret>
``` ```
If you get an error about missing dependencies, install the extra dependencies for the server. e.g.:
```
pip install bitter[web]
```
Make sure the callback url of your app is set to http://127.0.0.1:5000/callback_url/
# Notice # Notice
Please, use according to Twitter's Terms of Service Please, use according to Twitter's Terms of Service

7
bitter/__init__.py Normal file
View File

@ -0,0 +1,7 @@
"""
Bitter module. A library and cli for Twitter using python-twitter.
http://github.com/balkian/bitter
"""
__version__ = '0.4.1'
__all__ = ['cli', 'config', 'crawlers', 'models', 'utils' ]

View File

@ -12,8 +12,15 @@ from sqlalchemy import exists
from bitter import utils, models, crawlers from bitter import utils, models, crawlers
from bitter.models import make_session, User, ExtractorEntry, Following from bitter.models import make_session, User, ExtractorEntry, Following
import sys
if sys.version_info <= (3, 0):
from contextlib2 import ExitStack
else:
from contextlib import ExitStack from contextlib import ExitStack
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@click.group() @click.group()

View File

@ -46,7 +46,10 @@ def iter_credentials(credfile=None):
def get_credentials(credfile=None, inverse=False, **kwargs): def get_credentials(credfile=None, inverse=False, **kwargs):
creds = [] creds = []
for i in iter_credentials(credfile): for i in iter_credentials(credfile):
if all(map(lambda x: i[x[0]] == x[1], kwargs.items())): matches = all(map(lambda x: i[x[0]] == x[1], kwargs.items()))
if matches and not inverse:
creds.append(i)
elif inverse and not matches:
creds.append(i) creds.append(i)
return creds return creds

1
requirements-py2.txt Normal file
View File

@ -0,0 +1 @@
contextlib2

View File

@ -6,16 +6,25 @@ from pip.req import parse_requirements
# pip 6 introduces the *required* session argument # pip 6 introduces the *required* session argument
try: try:
install_reqs = parse_requirements("requirements.txt", session=pip.download.PipSession()) install_reqs = parse_requirements("requirements.txt", session=pip.download.PipSession())
py2_reqs = parse_requirements("requirements-py2.txt", session=pip.download.PipSession())
test_reqs = parse_requirements("test-requirements.txt", session=pip.download.PipSession()) test_reqs = parse_requirements("test-requirements.txt", session=pip.download.PipSession())
except AttributeError: except AttributeError:
install_reqs = parse_requirements("requirements.txt") install_reqs = parse_requirements("requirements.txt")
py2_reqs = parse_requirements("requirements-py2.txt")
test_reqs = parse_requirements("test-requirements.txt") test_reqs = parse_requirements("test-requirements.txt")
import sys
import itertools
if sys.version_info <= (3, 0):
install_reqs = itertools.chain(install_reqs, py2_reqs)
# reqs is a list of requirement # reqs is a list of requirement
# e.g. ['django==1.5.1', 'mezzanine==1.4.6'] # e.g. ['django==1.5.1', 'mezzanine==1.4.6']
install_reqs = [str(ir.req) for ir in install_reqs] install_reqs = [str(ir.req) for ir in install_reqs]
test_reqs = [str(ir.req) for ir in test_reqs] test_reqs = [str(ir.req) for ir in test_reqs]
with open('bitter/__init__.py') as f:
exec(f.read())
setup( setup(
name="bitter", name="bitter",
@ -27,9 +36,13 @@ setup(
author='J. Fernando Sanchez', author='J. Fernando Sanchez',
author_email='balkian@gmail.com', author_email='balkian@gmail.com',
url="http://balkian.com", url="http://balkian.com",
version="0.4", version=__version__,
install_requires=install_reqs, install_requires=install_reqs,
tests_require=test_reqs, tests_require=test_reqs,
extras_require = {
'server': ['flask', 'flask-oauthlib']
},
test_suite="tests",
include_package_data=True, include_package_data=True,
entry_points=""" entry_points="""
[console_scripts] [console_scripts]

View File

@ -0,0 +1 @@
pytest

View File

@ -1,9 +0,0 @@
from unittest import TestCase
from bitter.crawlers import TwitterWorker, TwitterQueue
class TestWorker(TestCase):
def test_worker(self):
w = TwitterWorker()

View File

@ -1,6 +0,0 @@
from unittest import TestCase
class TestModels(TestCase):
def test_worker(self):
assert True

View File

@ -1,7 +1,50 @@
from unittest import TestCase from unittest import TestCase
import os
from bitter import utils
from bitter import config as c
class TestUtils(TestCase): class TestUtils(TestCase):
def test_get_user(self): def setUp(self):
assert True self.credfile = '/tmp/credentials.txt'
c.CREDENTIALS = self.credfile
if os.path.exists(self.credfile):
os.remove(self.credfile)
utils.create_credentials(self.credfile)
def test_create_credentials(self):
assert os.path.exists(self.credfile)
os.remove(self.credfile)
utils.create_credentials() # From config
assert os.path.exists(self.credfile)
def test_add_credentials(self):
utils.add_credentials(self.credfile, user="test")
assert utils.get_credentials(self.credfile)
assert utils.get_credentials(user="test")
assert list(utils.get_credentials(user="test"))[0]["user"] == "test"
def test_get_credentials(self):
utils.add_credentials(self.credfile, user="test")
assert utils.get_credentials(user="test")
assert not utils.get_credentials(user="test", inverse=True)
def test_add_two_credentials(self):
utils.add_credentials(self.credfile, user="test")
utils.add_credentials(self.credfile, user="test2")
assert utils.get_credentials(user="test")
assert utils.get_credentials(user="test2")
def test_delete_credentials(self):
utils.add_credentials(self.credfile, user="test")
assert utils.get_credentials(user="test")
utils.delete_credentials(user="test")
print(utils.get_credentials())
assert not utils.get_credentials(user="test")