Skip to content

Commit

Permalink
fixes circleci, pipfile and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
KamalGalrani committed Jul 17, 2019
1 parent 44b6231 commit 2bd229f
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 55 deletions.
35 changes: 8 additions & 27 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,47 +43,28 @@ jobs:
- image: circleci/python:3.7
steps:
- checkout
- run:
name: "Install dependencies"
command: |
sudo pip install pipenv
pipenv install
- run:
name: "Build package"
command: |
mkdir -p ./dist/
echo $(git describe --abbrev=0 --tags) > ./dist/VERSION
python setup.py sdist
python setup.py bdist_wheel
pipenv run python setup.py sdist
pipenv run python setup.py bdist_wheel
- persist_to_workspace:
root: .
paths:
- dist

publish-github-release:
docker:
- image: cibuilds/github:0.10
steps:
- attach_workspace:
at: ./dist
- run:
name: "Publish Release on GitHub"
command: |
VERSION=$(<./dist/dist/VERSION)
rm ./dist/dist/VERSION
ghr -t ${GITHUB_TOKEN} -u ${CIRCLE_PROJECT_USERNAME} -r ${CIRCLE_PROJECT_REPONAME} -c ${CIRCLE_SHA1} -delete ${VERSION} ./dist/dist/
workflows:
version: 2
main:
jobs:
- tests-3.7
- tests-3.6
- tests-2.7
- build:
filters:
tags:
only: /^\d+\.\d+\.\d+$/
- publish-github-release:
requires:
- build
filters:
branches:
ignore: /.*/
tags:
only: /^\d+\.\d+\.\d+$/
- build
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -105,3 +105,4 @@ venv.bak/
# mypy
.mypy_cache/

test-reports
2 changes: 2 additions & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ name = "tvarit_api"
[packages]
pyyaml = "~=5.1"
requests = "~=2.22"
pyotp = "~=2.2"

[dev-packages]
codecov = "~=2.0"
coverage = "~=4.5"
mock = "~=3.0"
requests-mock = "~=1.6"
unittest-xml-reporting = "~=2.5"
funcsigs = "~=1.0"
24 changes: 16 additions & 8 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 1 addition & 16 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
from setuptools import setup, find_packages
from subprocess import check_output


def get_version():
try:
tag = check_output(
["git", "describe", "--tags", "--abbrev=0", "--match=[0-9]*"]
)
return tag.decode("utf-8").strip("\n")
except Exception:
raise RuntimeError(
"The version number cannot be extracted from git tag in this source "
"distribution; please either download the source from PyPI, or check out "
"from GitHub and make sure that the git CLI is available."
)

from tvarit_api.version import get_version

with open("README.md") as file:
long_description = file.read()
Expand Down
4 changes: 3 additions & 1 deletion test/api/test_team.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import sys
import unittest

import requests_mock

sys.path.append('.')

from tvarit_api import Tvarit


Expand Down
11 changes: 10 additions & 1 deletion test/test_tvarit.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
else:
from mock import patch, Mock

import sys
import requests

sys.path.append('.')

from tvarit_api import Tvarit
from tvarit_api.api import TokenAuth
from tvarit_api.api import TokenAuth, TOTPAuth


class MockResponse:
Expand Down Expand Up @@ -75,6 +78,12 @@ def test_tvarit_api_basic_auth(self):
)
self.assertTrue(isinstance(cli.api.auth, requests.auth.HTTPBasicAuth))

def test_tvarit_totp_auth(self):
cli = Tvarit(
(1, "secret"), host="localhost", url_path_prefix="", protocol="https"
)
self.assertTrue(isinstance(cli.api.auth, TOTPAuth))

def test_tvarit_api_token_auth(self):
cli = Tvarit(
"alongtoken012345etc",
Expand Down
4 changes: 2 additions & 2 deletions tvarit_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def __call__(self, request):
return request


class TotpAuth(requests.auth.AuthBase):
class TOTPAuth(requests.auth.AuthBase):
def __init__(self, org_id, token):
self.org_id = str(org_id)
self.totp = pyotp.TOTP(token).now
Expand Down Expand Up @@ -98,7 +98,7 @@ def construct_api_url():
self.auth = TokenAuth(self.auth)
else:
if type(self.auth[0]) == int:
self.auth = TotpAuth(*self.auth)
self.auth = TOTPAuth(*self.auth)
else:
self.auth = requests.auth.HTTPBasicAuth(*self.auth)

Expand Down
39 changes: 39 additions & 0 deletions tvarit_api/version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
__all__ = [
"get_version"
]

import os
from subprocess import check_output


def get_version():

version = None

if os.path.isfile('PKG-INFO'):
with open('PKG-INFO') as f:
lines = f.readlines()
for line in lines:
if line.startswith("Version: "):
version = line.strip()[9:]
else:
try:
tag = check_output(
["git", "describe", "--tags", "--abbrev=0", "--match=[0-9]*"]
)
return tag.decode("utf-8").strip("\n")
except Exception:
pass

if not version:
raise RuntimeError(
"The version number cannot be extracted from git tag in this source "
"distribution; please either download the source from PyPI, or check out "
"from GitHub and make sure that the git CLI is available."
)

return version


if __name__ == "__main__":
print(get_version())

0 comments on commit 2bd229f

Please sign in to comment.