Skip to content

Commit

Permalink
Merge pull request #2 from kilobyteno/code-style
Browse files Browse the repository at this point in the history
  • Loading branch information
dsbilling authored Sep 15, 2023
2 parents 3278c15 + 07289f8 commit c1c0cd5
Show file tree
Hide file tree
Showing 13 changed files with 144 additions and 41 deletions.
6 changes: 0 additions & 6 deletions .env

This file was deleted.

5 changes: 5 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
ENV=staging

TEST_API_TOKEN=
TEST_PROJECT_ID=
TEST_CHANNEL_ID=
15 changes: 15 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[flake8]
max-line-length = 160
ignore = D104, D400, D210, D101, D100, D107, D106, I100, I202, I101
import-order-style = pycharm
statistics = True
exclude =
.git,
__pycache__,
.github,
.pytest_cache,
venv,
build,
dist,
oppe.egg-info,
.eggs,
45 changes: 45 additions & 0 deletions .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: "Code Style"

on:
pull_request:
types:
- synchronize
- opened
- edited

jobs:
validation:
name: "Validation"
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [ "3.8", "3.9", "3.10" ]
steps:
- name: Checkout the repository
uses: actions/checkout@v4
- name: Set up Python ${{ inputs.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
cache: 'pip' # caching pip dependencies
- name: Install All Dependencies
run: |
python -m pip install --upgrade pip
pip install -r all.txt
- name: Run flake8
run: |
flake8 --config=.flake8
- name: Check for vulnerabilities
uses: pypa/gh-action-pip-audit@v1.0.6
with:
inputs: requirements.txt requirements-dev.txt
- name: Rename file
run: mv .env.example .env
- name: Change environment variables in .env
run: |
sed -i "s/TEST_API_TOKEN=/TEST_API_TOKEN=${{ secrets.TEST_API_TOKEN }}/g" .env
sed -i "s/TEST_PROJECT_ID=/TEST_PROJECT_ID=${{ secrets.TEST_PROJECT_ID }}/g" .env
sed -i "s/TEST_CHANNEL_ID=/TEST_CHANNEL_ID=${{ secrets.TEST_CHANNEL_ID }}/g" .env
- name: Run Tests
run: |
pytest --disable-pytest-warnings
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v4
with:
Expand Down
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
repos:
- repo: https://github.com/PyCQA/flake8
rev: 6.0.0
hooks:
- id: flake8
additional_dependencies: [flake8-print, flake8-quotes, flake8-use-fstring, pep8-naming, flake8-import-order, flake8-docstrings]
args: [--config=.flake8]
exclude: ^(.git|__pycache__|.github|.pytest_cache|venv|build|dist|oppe.egg-info|.eggs)/.*\.py$
- repo: https://github.com/pycqa/isort
rev: 5.12.0
hooks:
- id: isort
name: isort (python)
2 changes: 2 additions & 0 deletions all.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-r requirements-dev.txt
-r requirements.txt
1 change: 1 addition & 0 deletions oppe/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Init file for oppe"""
10 changes: 8 additions & 2 deletions oppe/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ class Config:
EVENT_URL (str):
The URL for accessing Oppe app events
"""

# Reading the env variables
dotenv_path = os.path.join(os.path.dirname(__file__), '..', '.env')
if os.path.exists(dotenv_path):
load_dotenv(dotenv_path)

BASE_URL = f"https://{os.getenv('ENV')}oppe.app"
EVENT_URL = f"{BASE_URL}/api/event/"
ENV = os.getenv('ENV')
if ENV == 'staging':
BASE_URL = 'https://staging.oppe.app'
else:
BASE_URL = 'https://oppe.app'

EVENT_URL = f'{BASE_URL}/api/event/'
34 changes: 18 additions & 16 deletions oppe/oppe.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import json

import requests

from oppe.config import Config
import json


class Oppe:
Expand All @@ -12,16 +14,17 @@ class Oppe:
The authentication token.
project (str):
The project identifier.
"""
"""

def __init__(self, token, project):
"""
Initializes an instance of the Oppe class.
Initialize an instance of the Oppe class.
:param token: The authentication token.
:type token: str
:param project: The project identifier.
:type project: str
"""
:param token: The authentication token.
:type token: str
:param project: The project identifier.
:type project: str
"""
self.token = token
self.project = project

Expand All @@ -40,15 +43,14 @@ def trigger_event(self, channel, title, description):
:rtype: bool
"""
data = {
"channel_id": channel,
"title": title,
"description": description,
'channel_id': channel,
'title': title,
'description': description,
}
headers = {
"Accept": "application/json",
"Content-Type": "application/json",
"Authorization": f"Bearer {self.token}"
'Accept': 'application/json',
'Content-Type': 'application/json',
'Authorization': f'Bearer {self.token}'
}
response = requests.post(Config.EVENT_URL, data=json.dumps(data), headers=headers)
requests.post(Config.EVENT_URL, data=json.dumps(data), headers=headers)
return True

9 changes: 9 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
flake8~=6.1.0
flake8-docstrings~=1.7.0
flake8-import-order~=0.18.2
flake8-print~=5.0.0
flake8-quotes~=3.3.2
flake8-use-fstring~=1.4.0
isort~=5.12.0
pre-commit~=3.4.0
Faker~=19.4.0
32 changes: 18 additions & 14 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,33 @@
requirements = f.read().splitlines()

setuptools.setup(
name="oppe",
version='0.0.1',
description="A Python API Wrapper for Oppe",
name='oppe',
version='0.0.2',
description='A Python API Wrapper for Oppe',
long_description=readme,
long_description_content_type="text/markdown",
long_description_content_type='text/markdown',
project_urls={
'Homepage': 'https://oppe.app',
'Documentation': 'https://oppe.app',
'Github': 'https://github.com/kilobyteno/oppe.py'
'Documentation': 'https://docs.oppe.app',
'Github': 'https://github.com/kilobyteno/oppe-for-python',
},
url="https://github.com/kilobyteno/oppe.py",
author="Kilobyte AS",
author_email="daniel@kilobyte.no",
license="MIT",
python_requires='>=3.6',
packages=["oppe"],
url='https://github.com/kilobyteno/oppe-for-python',
author='Kilobyte AS',
license='MIT',
python_requires='>=3.8',
packages=['oppe'],
include_package_data=True,
install_requires=requirements,
setuptools_git_versioning={
'enabled': True,
},
setup_requires=['setuptools-git-versioning<2'],
classifiers=[
'Programming Language :: Python',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Programming Language :: Python :: 3.10',
'Programming Language :: Python :: 3.11',
]
)
11 changes: 8 additions & 3 deletions tests/test_pyoppe.py → tests/test_oppe.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
import os

from dotenv import load_dotenv
from faker import Faker

from oppe.oppe import Oppe

fake = Faker()

# Reading the env variables
dotenv_path = os.path.join(os.path.dirname(__file__), '..', '.env')
if os.path.exists(dotenv_path):
load_dotenv(dotenv_path)


def init_oppe():
return Oppe(token=os.getenv('TEST_API_TOKEN'), project=os.getenv('TEST_PROJECT'))
""" Initialize Oppe """
return Oppe(token=os.getenv('TEST_API_TOKEN'), project=os.getenv('TEST_PROJECT_ID'))


def test_publish_event():
""" Test publish event """
oppe = init_oppe()
response = oppe.trigger_event(channel=os.getenv('TEST_CHANNEL_ID'), title=os.getenv('TEST_TITLE'), description=os.getenv('TEST_DESCRIPTION'))
assert response == True
response = oppe.trigger_event(channel=os.getenv('TEST_CHANNEL_ID'), title=fake.domain_word(), description=fake.sentence())
assert response is True

0 comments on commit c1c0cd5

Please sign in to comment.