Skip to content

Commit

Permalink
tests: created tests for config content check
Browse files Browse the repository at this point in the history
  • Loading branch information
fotini-pan authored and slint committed Aug 1, 2019
1 parent 56ccb1e commit faa6ef5
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 110 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ dist: xenial
python: 3.7

cache:
directories:
- $HOME/virtualenv/python3.6.*
- $HOME/.cache/pip
- pip

matrix:
fast_finish: true
allow_failures:
- env: REQUIREMENTS=dev
- env: REQUIREMENTS=devel

env:
- REQUIREMENTS=lowest
Expand Down
10 changes: 7 additions & 3 deletions autobot/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Autobot is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Cli commands."""
"""CLI commands."""

import sys

Expand Down Expand Up @@ -44,7 +44,9 @@ def report():
@click.option("--format", default="json", help="The result format.")
def show(owner, repo, maintainer, format):
"""Autobot report show cli."""
conf = Config(owner, repos=[r for r in repo], maintainers=[m for m in maintainer])
conf = Config(
owner=owner, repos=[r for r in repo], maintainers=[m for m in maintainer]
)
bot = BotAPI(conf)
res = bot.report
with open("results.yml", "w") as outfile:
Expand All @@ -71,7 +73,9 @@ def show(owner, repo, maintainer, format):
)
def send(owner, repo, maintainer, via):
"""Autobot report send cli."""
conf = Config(owner, repos=[r for r in repo], maintainers=[m for m in maintainer])
conf = Config(
owner=owner, repos=[r for r in repo], maintainers=[m for m in maintainer]
)
bot = BotAPI(conf)
for m in conf._load_maintainers().keys():
if via == "gitter":
Expand Down
17 changes: 9 additions & 8 deletions autobot/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,20 @@
import yaml
from dotenv import load_dotenv

load_dotenv()


class Config:
"""Loads config from environment and files."""

def __init__(self, owner: str, **kwargs):
def __init__(self, **kwargs):
"""Config initialization."""
self.owner = owner
self.repos = kwargs.get("repos", None)
self.maintainers = kwargs.get("maintainers", None)
self.GITHUB_TOKEN = os.getenv("GH_TOKEN")
self.INFO_PATH = os.getenv(owner.upper() + "_INFO")
load_dotenv()
self.owner = kwargs.get("owner", os.getenv("OWNER"))
self.repos = kwargs.get("repos", [])
self.maintainers = kwargs.get("maintainers", [])
self.GITHUB_TOKEN = kwargs.get("github_token", os.getenv("GH_TOKEN"))
self.INFO_PATH = kwargs.get(
"info_path", os.getenv(self.owner.upper() + "_INFO")
)
self.GITTER_TOKEN = "CHANGE_ME"
self.MAIL_SETTINGS = {...}

Expand Down
1 change: 1 addition & 0 deletions autobot/opensource
Submodule opensource added at 9bb1cf
64 changes: 0 additions & 64 deletions requirements-devel.txt
Original file line number Diff line number Diff line change
@@ -1,64 +0,0 @@
amqp==2.5.0
asn1crypto==0.24.0
astroid==2.2.5
atomicwrites==1.3.0
attrs==19.1.0
autopep8==1.4.4
bcrypt==3.1.7
billiard==3.6.0.0
cached-property==1.5.1
celery==4.3.0
certifi==2019.6.16
cffi==1.12.3
chardet==3.0.4
Click==7.0
cryptography==2.7
docker==3.7.3
docker-compose==1.24.1
docker-pycreds==0.4.0
dockerpty==0.4.1
docopt==0.6.2
Flask==1.0.3
github3.py==1.3.0
idna==2.7
importlib-metadata==0.18
isort==4.3.21
itsdangerous==1.1.0
Jinja2==2.10.1
jsonschema==2.6.0
jwcrypto==0.6.0
kombu==4.6.3
lazy-load==0.8.2
lazy-object-proxy==1.4.1
MarkupSafe==1.1.1
mccabe==0.6.1
more-itertools==7.2.0
packaging==19.0
paramiko==2.6.0
pep8==1.7.1
pluggy==0.12.0
py==1.8.0
pycodestyle==2.5.0
pycparser==2.19
pylint==2.3.1
PyNaCl==1.3.0
pyparsing==2.4.1.1
pytest==5.0.1
python-dateutil==2.8.0
python-dotenv==0.10.3
pytz==2019.1
PyYAML==3.13
redis==3.2.1
requests==2.20.1
six==1.12.0
texttable==0.9.1
typed-ast==1.4.0
uritemplate==3.0.0
urllib3==1.24.3
vine==1.3.0
wcwidth==0.1.7
websocket-client==0.56.0
Werkzeug==0.15.4
wrapt==1.11.2
xmltodict==0.12.0
zipp==0.5.2
13 changes: 13 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ ignore =
.travis.yml
opensource

[black]
exclude = "/(
\.eggs|
\.pytest_cache|
\.vscode|
\autobot.egg-info|
\env|
\tests/__pycache__|
\.editorconfig|
\.travis.yml|
\opensource
)/"

[build_sphinx]
source-dir = docs/
build-dir = docs/_build
Expand Down
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"click>=7.0",
"PyYAML>=3.13",
"python-dotenv>=0.10.3",
"lazy-load>=0.8.2",
]

setup(
Expand Down
97 changes: 97 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# -*- coding: utf-8 -*-
#
# This file is part of Autobot.
# Copyright (C) 2015-2019 CERN.
#
# Autobot is free software; you can redistribute it and/or modify it
# under the terms of the MIT License; see LICENSE file for more details.

"""Test configuration file."""

import pytest
import yaml


@pytest.fixture(scope="session")
def info(tmpdir_factory):
"""Mock info for configuration testing."""
mock = {
"orgs": {
"org1": {
"repositories": {
"org1foo1": {
"description": "Description for org1foo1",
"maintainers": ["org1foo", "mix1"],
},
"org1foo2": {
"description": "Description for org1foo2",
"maintainers": ["org1foo", "mix2", "mix3"],
},
"org1foo3": {
"description": "Description for org1foo3",
"maintainers": ["org1foo", "mix1", "mix3"],
},
"org1bar1": {
"description": "Description for org1bar1",
"maintainers": ["org1bar", "mix1"],
},
"org1bar2": {
"description": "Description for org1bar2",
"maintainers": ["org1bar", "mix2"],
},
"org1baz1": {
"description": "Description for org1baz1",
"maintainers": ["org1baz", "mix2", "mix3"],
},
}
},
"org2": {
"repositories": {
"org2foo1": {
"description": "Description for org2foo1",
"maintainers": ["org2foo", "mix3"],
},
"org2bar1": {
"description": "Description for org2bar1",
"maintainers": ["org2bar", "mix1"],
},
"org2bar2": {
"description": "Description for org2bar2",
"maintainers": ["org2bar", "mix1", "mix2"],
},
"org2baz1": {
"description": "Description for org2baz1",
"maintainers": ["org2baz", "mix2", "mix3"],
},
"org2baz2": {
"description": "Description for org2baz2",
"maintainers": ["org2baz", "mix1"],
},
}
},
}
}
d = tmpdir_factory.mktemp("tests").join("repositories.yml")
with open(d, "w") as outfile:
yaml.dump(mock, outfile, default_flow_style=False)
return str(d)


@pytest.fixture
def config(info, **kwargs):
"""Configuration testing fixture."""
from autobot.config import Config

owner = kwargs.get("owner", "org1")
repos = kwargs.get("repos", [])
maintainers = kwargs.get("maintainers", [])
github_token = kwargs.get("github_token", "some token")
info_path = kwargs.get("info_path", info)

return Config(
owner=owner,
repos=repos,
maintainers=maintainers,
github_token=github_token,
info_path=info_path,
)
66 changes: 35 additions & 31 deletions tests/test_autobot.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,38 @@

"""Tests for `autobot` package."""

import pytest
from click.testing import CliRunner

from autobot import cli


@pytest.fixture
def response():
"""Sample pytest fixture.
See more at: http://doc.pytest.org/en/latest/fixture.html
"""
# import requests
# return requests.get('https://github.com/audreyr/cookiecutter-pypackage')


def test_content(response):
"""Sample pytest test function with the pytest fixture as an argument."""
# from bs4 import BeautifulSoup
# assert 'GitHub' in BeautifulSoup(response.content).title.string


def test_command_line_interface():
"""Test the CLI."""
runner = CliRunner()
result = runner.invoke(cli.main)
assert result.exit_code == 0
assert "autobot.cli.main" in result.output
help_result = runner.invoke(cli.main, ["--help"])
assert help_result.exit_code == 0
assert "--help Show this message and exit." in help_result.output
import os
import sys


def test_config_content(config):
"""Test configuration content."""
assert isinstance(config.owner, str)
assert isinstance(config.GITHUB_TOKEN, str)
assert isinstance(config.INFO_PATH, str)
assert os.path.isfile(os.path.join(os.path.dirname(__file__), config.INFO_PATH))
assert isinstance(config.repos, list)
for repo in config.repos:
assert isinstance(repo, str)
assert isinstance(config.maintainers, list)
for maintainer in config.maintainers:
assert isinstance(maintainer, str)
maintainers = config._load_maintainers()
assert isinstance(maintainers, dict)
for i in maintainers.items():
assert isinstance(i[0], str)
assert isinstance(i[1], list)
for val in i[1]:
assert isinstance(val, str)
repos = config._load_repositories()
assert isinstance(repos, dict)
for i in repos.items():
assert isinstance(i[0], str)
assert isinstance(i[1], list)
for val in i[1]:
assert isinstance(val, str)


def test_cli(config):
"""Test cli commands."""
pass

0 comments on commit faa6ef5

Please sign in to comment.