From ed3b8eb77820be045a4c0527082a61fb495b5bac Mon Sep 17 00:00:00 2001 From: BehindLoader Date: Mon, 8 Jul 2019 16:49:44 +0300 Subject: [PATCH] Minor changes --- Makefile | 2 +- README.md | 78 +++++++++++++++++++++++++++++++++++++------- tests/conftest.py | 8 +++-- tests/test_locale.py | 9 +++++ 4 files changed, 83 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index 06e54fa..c11a79b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ default: docker_build docker_build: - @docker build -t hubot-mongo-bridge-server . + @docker build -t hubot-mongo-bridge . diff --git a/README.md b/README.md index f709cd3..fd0feee 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,8 @@ -# hubot-mongo-bridge -Bridge between hubot scripts and Rocket.Chat mongodb +# Hubot Bridge + +_«"Hubot bridge" is a rope stretched between the hubot scripts and the Rocket.Chat database.»_ ― Friedrich Nietzsche + +A service that provides interaction with the Rocket.Chat database using the REST API. ## Settings @@ -13,32 +16,85 @@ You can set up project by using environment variables HOST - Host name for the server + Host name on which the server will be running. localhost PORT - Port number for the server + Port on which server will be launched. 8000 MONGODB_HOST - MongoDB host where app will connect + Address of the host that hosts the Rocket.Chat database. localhost MONGODB_PORT - MongoDB port where app will connect + The port where the Rocket.Chat database is located. 27017 -## Install +## Deploy + +### In Docker + +The easiest way to deploy the project. Great for production deployment. + +To deploy a project using Docker, you need to follow the instructions: + +1. **Build image**. Run the following command in project root directory. This will create an docker image with the name "mongo-bridge" on your computer. +``` +$ make +``` + +2. **Run**. Make sure the Rocket.Chat database is running and enter this command to your terminal: +``` +docker run -p 8000:8000 hubot-bridge +``` + +In order to set up project you need to pass environment variables to your docker container. You can do it by using `-e` or `--env` flag on docker container starting. For example: +``` +docker run -e MONGODB_PORT=27018 hubot-bridge +``` +This line pass variable `MONGODB_PORT` with the value `27018` into container. + +## Development + +### Run project for development -- `make` +1. **Install packages**. You need to have the following packages on your computer: + - python (version 3.6 or higher) + - python-pip + - python-virtualenv (optional) +2. **Install python dependencies**. + - Create python virtual environment and activate it. (optional) + - Install python dependencies from `requirements.txt` +3. **Run**. `app.py` -- `docker run -p 8000:8000 --env MONGODB_HOST='your_mongo_host' hubot-mongo-bridge-server` +## API + +### `/locale` GET + +*Getting localization settings for a specific user* + +Query params: + + + + + + + + + + + +
ParameterDescriptionOptions
user_idThe string with the user ID who you need to know the localization settingRequired
-## Usage +## Authors -`http://localhost:8000/locale?user_id=foo` +The project was made by: +- [S. Suprun](https://github.com/BehindLoader) +- [A. Maksimovich](https://github.com/ABSLord) diff --git a/tests/conftest.py b/tests/conftest.py index b155d88..3737ec1 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,8 +1,12 @@ +""" Module for test fixtures """ + import pytest from src.utils import make_app @pytest.fixture -def client(loop, aiohttp_client): - return loop.run_until_complete(aiohttp_client(make_app())) +async def client(aiohttp_client): + """ aiohttp client """ + + return await aiohttp_client(make_app()) diff --git a/tests/test_locale.py b/tests/test_locale.py index e2812a7..1d5ef85 100644 --- a/tests/test_locale.py +++ b/tests/test_locale.py @@ -1,5 +1,8 @@ +""" Tests for locale module """ async def test_for_existing_user(client): + """ Test Case for getting locale of existing user """ + resp = await client.get("/locale?user_id=rocket.cat") assert resp.status == 200 data = await resp.json() @@ -7,6 +10,8 @@ async def test_for_existing_user(client): async def test_for_nonexistent_locale(client): + """ Test Case for getting locale of existing user without locale """ + resp = await client.get("/locale?user_id=rocket.dog") assert resp.status == 200 data = await resp.json() @@ -14,11 +19,15 @@ async def test_for_nonexistent_locale(client): async def test_for_nonexistent_user(client): + """ Test Case for getting locale of nonexisting user """ + resp = await client.get("/locale?user_id=qwerty") assert resp.status == 404 async def test_for_bad_request(client): + """ Test Case for getting locale with bad queries """ + resp = await client.get("/locale") assert resp.status == 400 text = await resp.text()