Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unittests base #28

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
venv
**/config.py
globalcfg.py
.coverage
13 changes: 13 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Start Rabbit MQ Server in Docker.
#
# Expose ports:
# 5671 --> 5671, 5672 --> 5672 (used by AMQP 0-9-1 and 1.0 clients without and with TLS)
# 8080 --> 15672 (Management Plugin)
#
# Learn more: https://hub.docker.com/_/rabbitmq/


docker run --hostname my-rabbit -d --name codex-bot-rabbitmq -p 5672:5672 -p 5671:5671 -p 8080:15672 rabbitmq:3

docker run --name codex-bot-mongo -d -p 27017:27017 mongo
2 changes: 2 additions & 0 deletions codexbot/services/telegram/telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,7 @@ def set_webhook(self):
result = requests.get(query)
except Exception as e:
logging.debug(e)
return False
else:
logging.debug(result.content)
return result.content
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ setuptools==35.0.2
- six [required: Any, installed: 1.10.0]
- six [required: >=1.6.0, installed: 1.10.0]
wheel==0.29.0
nose
coverage
report
6 changes: 6 additions & 0 deletions runtests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#
# Run tests and display results with code coverage
#


nosetests -v report --with-coverage --cover-package=codexbot/ tests/*.py
17 changes: 17 additions & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import json


class BaseTest(object):
"""This object represents a Base test and its sets of functions."""

def __init__(self, *args, **kwargs):
super(BaseTest, self).__init__(*args, **kwargs)

@staticmethod
def is_json(string):
try:
json.loads(string)
except ValueError:
return False

return True
23 changes: 23 additions & 0 deletions tests/db.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import unittest

from codexbot.lib.db import Db
from tests.base import BaseTest


class DatabaseTest(BaseTest, unittest.TestCase):

def __init__(self, *args, **kwargs):
super(BaseTest, self).__init__(*args, **kwargs)
self.db_name = 'test_db'
self.collection_name = 'test_collection'

def setUp(self):
self.db = Db(self.db_name)
self.db.insert(self.collection_name, {'id': 'test_id'})

def testDatabaseInit(self):
result = list(self.db.find(self.collection_name, {'id': 'test_id'}))
self.assertNotEquals(len(result), 0)

def tearDown(self):
self.db.remove(self.collection_name)
30 changes: 30 additions & 0 deletions tests/telegram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import json
import unittest

from codexbot.services.telegram import Telegram
from tests.base import BaseTest


class TelegramTestBase(BaseTest, unittest.TestCase):

def setUp(self):
self._telegram = Telegram()

def testConfiguration(self):
# Test presence
from codexbot.services.telegram.config import CALLBACK_ROUTE, BOT_NAME, API_TOKEN, API_URL
self.assertNotEqual(CALLBACK_ROUTE, "")
self.assertNotEqual(BOT_NAME, "")
self.assertNotEqual(API_TOKEN, "")
self.assertNotEqual(API_URL, "")

# Test route format
self.assertEqual(CALLBACK_ROUTE[0], "/")
self.assertNotEqual(CALLBACK_ROUTE[-1], "/")

def testSetWebhook(self):
result = self._telegram.set_webhook()
self.assertNotEqual(result, False)
self.is_json(result)
json_result = json.loads(result)
self.assertEqual(json_result.get("ok", None), True)