Skip to content
Merged
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
5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FLASK_ENV=development
FLASK_APP=run.py
DB_NAME=stackoverflow
APP_KEY="Some API random key"
TEST_DB_NAME=testing_stackoverflow
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
.coverage
/__pycache__
__pycache__/
.pytest_cache/
.pytest_cache/
*.env
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ deploy:
provider: heroku
api_key:
secure: Eav/qEQN89dyvqBKam746FbeRAo8GQtfjicoxjev482DFHowK3BvieKiHlUzdMdZiAr38uZb2KYD39KdDV/xTMGKENL+/4ADWVywRl4EaNJd+5ufjx8zhQjElZJMpV1mnHCbVLmbE4v3XU65SbibpyjeDvcUMNKYDSjxuRAv0nsWdR/YFYt0s0hTALAGRb/q369+gWtCaX87UGxwUuMmg0uhl9Ke3ktdTStaytymNt4cToQ5V0LQopNs/lQgSb9ZQgLxhBmtjAqKVmyGQzXZc++Poyexeq1bdMA/AcuyyknmeTbYfIW9UNxUxBwCUCVQ/3qMDS4fyNAOYKlERt0agdxlOmQayEEkSgmrd6+iSTR1foena2pHcS2q6Pl9CncIygHezm/9uYPIhg1HmziNQR+peH4q278gSlDh9Z0TOT7NaBIzreTg8ZzrdmolhXEiLFLsX36OGz6HOjec4n8VOcvkDbEb0oQwU3GYTfAMpEk+XgsswSpii5pW75fmklJrr3dHvifekDpcHDhNMU9QCcU+R2LkkZpG3+8g9qsGyG7yoqveIbVO96M8gjvhORRDh7dt+/4GQ9UOkVSifa4q2rUxyXDCLXFlcvI5SwpUgcinvIjCpWRVQBEpeRMbg1Y/KugEtYMtp9AG02+ITLttTUkzmXGiqYKpgsTpgHZKpCM=
app:
app:
staging: andela-stackoverflow
release-v1.0.0: andela-stackoverflow-v1


env:
global:
- APP_KEY="Some API key"
- TEST_DB_NAME=testing_stackoverflow
16 changes: 13 additions & 3 deletions api/config.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
from os import getenv, path
from dotenv import load_dotenv


# load environment variables
env_path = path.abspath(".env")

load_dotenv(verbose=True, dotenv_path=env_path)


class Configuration:
"""Common configuration for all environments """
DB_NAME = "stackoverflow"
SECRET = "J0NJxenTRjjupTknRQsKFbka5JoIxgmAKQcMfl1vkB8"
DB_NAME = getenv("DB_NAME")
SECRET = getenv("APP_KEY")


class TestConfiguration(Configuration):
"""Configuration for the test environment"""
TESTING = True
DB_NAME = "testing_stackoverflow"
DB_NAME = getenv("TEST_DB_NAME")


class DevelopmentConfiguration(Configuration):
Expand Down
9 changes: 4 additions & 5 deletions api/core/JSONEncoder.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
from flask.json import JSONEncoder as BaseJSONEncoder
from api.core.models import Model
from api.core.models.collections import ModelCollection
from datetime import datetime


class JSONEncoder(BaseJSONEncoder):
def default(self, o):
if isinstance(o, Model) or isinstance(o, ModelCollection):
if isinstance(o, (Model, ModelCollection)):
return o.to_json()
if isinstance(o, datetime):
return o.strftime('%Y-%m-%d %H:%M:%S')
return JSONEncoder.default(self, o) # pragma: no cover
if isinstance(o, bytes):
return o.decode("UTF-8")
return BaseJSONEncoder.default(self, o)
4 changes: 2 additions & 2 deletions api/core/JWT.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ def _make_options(self):
def generate_token(self, subject):
return jwt.encode(
{'subject': subject, 'exp': self.expires},
**self._make_options(),
).decode("UTF-8")
**self._make_options()
)

def get_subject_from_headers(self):
token = self.get_token_from_header()
Expand Down
3 changes: 0 additions & 3 deletions api/core/Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ def __init__(self, attributes={}):
def update(self, attributes):
self.attributes.update(attributes)

def values(self):
return self.attributes.values()

def set_attributes(self, attributes):
object.__setattr__(self, "attributes", attributes)

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pylint==2.1.1
pytest==3.7.1
pytest-cov==2.5.1
python-coveralls==2.9.1
python-dotenv==0.9.1
PyYAML==3.13
requests==2.19.1
six==1.11.0
Expand Down