-
Notifications
You must be signed in to change notification settings - Fork 0
DEVOPS-10: Replace Trello with MongoDB #11
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,15 +1,9 @@ | ||
| # Flask server configuration. | ||
| FLASK_SKIP_DOTENV=true | ||
| FLASK_SKIP_DOTENV=True | ||
|
|
||
| # Change the following values for local development. | ||
| SECRET_KEY=test-secret-key | ||
|
|
||
| # Change these values for your Trello environment | ||
| API_KEY=test-api-key | ||
| TOKEN=test-token | ||
|
|
||
| # Change these values for your Trello board | ||
| BOARD_ID=test-board-id | ||
| TO_DO_LIST_ID=test-to-do-list-id | ||
| DOING_LIST_ID=test-doing-list-id | ||
| DONE_LIST_ID=test-done-list-id | ||
| # Change these values for your DB | ||
| DB_CONNECTION_STRING=mongodb://fakemongo.com | ||
| DB_NAME=name |
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,41 +1,24 @@ | ||
| import pytest | ||
| from dotenv import load_dotenv, find_dotenv | ||
| from todo_app import app | ||
| import requests | ||
| import os | ||
| import mongomock | ||
|
|
||
| from todo_app.data.db_items import add_card | ||
|
|
||
| @pytest.fixture | ||
| def client(): | ||
| file_path = find_dotenv('.env.test') | ||
|
|
||
| load_dotenv(file_path, override=True) | ||
| test_app = app.create_app() | ||
|
|
||
| with test_app.test_client() as client: | ||
| yield client | ||
| with mongomock.patch(servers=(('fakemongo.com', 27017),)): | ||
| test_app = app.create_app() | ||
| with test_app.test_client() as client: | ||
| yield client | ||
|
|
||
| def test_index_page(monkeypatch, client): | ||
| def test_index_page(client): | ||
| add_card('Test card') | ||
|
|
||
| monkeypatch.setattr(requests, 'get', get_lists_stub) | ||
| response = client.get('/') | ||
|
|
||
| assert response.status_code == 200 | ||
| assert 'Test card' in response.data.decode() | ||
|
|
||
| class StubResponse(): | ||
| def __init__(self, fake_response_data): | ||
| self.fake_response_data = fake_response_data | ||
|
|
||
| def json(self): | ||
| return self.fake_response_data | ||
|
|
||
| def get_lists_stub(url): | ||
| fake_response_data = None | ||
| query_string = f'?key={os.environ.get("API_KEY")}&token={os.environ.get("TOKEN")}&cards=open' | ||
| if url == f'https://api.trello.com/1/boards/{os.environ.get("BOARD_ID")}/lists{query_string}': | ||
| fake_response_data = [{ | ||
| 'id': '123abc', | ||
| 'name': 'To Do', | ||
| 'cards': [{'id': '456', 'name': 'Test card'}] | ||
| }] | ||
| return StubResponse(fake_response_data) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import os | ||
| from todo_app.models.Item import Item | ||
| import pymongo | ||
|
|
||
| def get_collection(): | ||
| client = pymongo.MongoClient(f'{os.getenv("DB_CONNECTION_STRING")}') | ||
| db = client[f'{os.getenv("DB_NAME")}'] | ||
| return db.card | ||
|
|
||
| def get_cards(): | ||
| collection = get_collection() | ||
| cards = collection.find() | ||
| return [Item.from_db_card(card) for card in cards] | ||
|
|
||
| def add_card(card_name): | ||
| collection = get_collection() | ||
| collection.insert_one({"name": card_name, "status": "To Do"}) | ||
|
|
||
| def change_card_status(card_id, status): | ||
| collection = get_collection() | ||
| collection.update_one({"_id": card_id}, {"$set": {"status": status}}) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor, but it's a good habit to convert the string |
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.