Skip to content

Commit

Permalink
Minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ya7on committed Jul 8, 2019
1 parent f55287b commit a686595
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ before_script:
- mongo rocketchat --eval 'db.createCollection("users", { });db.users.insert([{_id:"rocket.cat",language:"ru"},{_id:"rocket.dog"}])'

script:
- pylint app.py src/
- find -name "*.py" -not -path "./venv/*" | xargs pylint
- env PYTHONPATH=$(pwd) py.test tests/
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
default: docker_build

docker_build:
@docker build -t hubot-mongo-bridge-server .
@docker build -t hubot-mongo-bridge .
78 changes: 67 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -13,32 +16,85 @@ You can set up project by using environment variables
</tr>
<tr>
<td>HOST</td>
<td>Host name for the server</td>
<td>Host name on which the server will be running.</td>
<td>localhost</td>
</tr>
<tr>
<td>PORT</td>
<td>Port number for the server</td>
<td>Port on which server will be launched.</td>
<td>8000</td>
</tr>
<tr>
<td>MONGODB_HOST</td>
<td>MongoDB host where app will connect</td>
<td>Address of the host that hosts the Rocket.Chat database.</td>
<td>localhost</td>
</tr>
<tr>
<td>MONGODB_PORT</td>
<td>MongoDB port where app will connect</td>
<td>The port where the Rocket.Chat database is located.</td>
<td>27017</td>
</tr>
</table>

## 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:
<table>
<tr>
<th>Parameter</th>
<th>Description</th>
<th>Options</th>
</tr>
<tr>
<td>user_id</td>
<td>The string with the user ID who you need to know the localization setting</td>
<td>Required</td>
</tr>
</table>

## 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)
8 changes: 6 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -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())
9 changes: 9 additions & 0 deletions tests/test_locale.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
""" 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()
assert "ru" in data["locale"]


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()
assert "" in data["locale"]


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()
Expand Down

0 comments on commit a686595

Please sign in to comment.