Skip to content

Commit

Permalink
Add initial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barseghyanartur committed Nov 17, 2019
1 parent 2570883 commit 23128e6
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 17 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ coverage.xml
*.cover
.hypothesis/
.pytest_cache/
*.py,cover

# Translations
*.mo
Expand Down Expand Up @@ -112,3 +113,6 @@ changelog.md
codebin/
builddocs/
builddocs.zip
!tesing/.gitkeep
testing/
matyan-testing/
46 changes: 46 additions & 0 deletions src/matyan/tests/output/generate-changelog-releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
### Unreleased

**Other**


### 0.2

**Feature**

*MSFT-1238 Token Authentication*

- Update authentication docs [Artur Barseghyan]
- Implement token authentication [Artur Barseghyan]

*MSFT-1237 Improve Document Sharing*

- Improve document sharing. Add option to share via GDrive [Artur Barseghyan]

**Other**


### 0.1

**Feature**

*MSFT-1234 Car Type Suggester*

- Add insurance amount indication based on car weight [Artur Barseghyan]
- Initial car type suggester implementation [Artur Barseghyan]

**Bugfix**

*MSFT-1236 Prevent Duplicate Postal Codes*

- Make postal code field unique for the country [Artur Barseghyan]
- Normalise postal codes for US addresses [Artur Barseghyan]
- Normalise postal codes for German addresses [Artur Barseghyan]

**Deprecation**

*MSFT-1235 Deprecate Old Api*

- Update docs [Artur Barseghyan]
- Deprecate API v 2.0 [Artur Barseghyan]

**Other**
32 changes: 32 additions & 0 deletions src/matyan/tests/output/generate-changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
**Feature**

*MSFT-1238 Token Authentication*

- Update authentication docs [Artur Barseghyan]
- Implement token authentication [Artur Barseghyan]

*MSFT-1237 Improve Document Sharing*

- Improve document sharing. Add option to share via GDrive [Artur Barseghyan]

*MSFT-1234 Car Type Suggester*

- Add insurance amount indication based on car weight [Artur Barseghyan]
- Initial car type suggester implementation [Artur Barseghyan]

**Bugfix**

*MSFT-1236 Prevent Duplicate Postal Codes*

- Make postal code field unique for the country [Artur Barseghyan]
- Normalise postal codes for US addresses [Artur Barseghyan]
- Normalise postal codes for German addresses [Artur Barseghyan]

**Deprecation**

*MSFT-1235 Deprecate Old Api*

- Update docs [Artur Barseghyan]
- Deprecate API v 2.0 [Artur Barseghyan]

**Other**
52 changes: 48 additions & 4 deletions src/matyan/tests/test_commands.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import os
import logging
import unittest

import subprocess
import git

from .base import log_info, internet_available_only
from ..helpers import project_dir
from .base import log_info, internet_available_only, is_internet_available

__title__ = 'matyan.tests.test_commands'
__author__ = 'Artur Barseghyan'
Expand All @@ -17,15 +20,56 @@
class TestCommands(unittest.TestCase):
"""Matyan commands tests."""

def setUp(self):
@classmethod
def setUpClass(cls):
"""Set up."""
super(TestCommands, cls).setUpClass()
if is_internet_available():
# Test directory for cloning the repo
test_dir = project_dir("tests/matyan-testing")
if not os.path.exists(test_dir):
git.Repo.clone_from(
"git@bitbucket.org:barseghyanartur/matyan-testing.git",
test_dir
)

# Go to cloned repository
os.chdir(test_dir)

# Expected output of the `generate-changelog` command.
changelog_output = project_dir(
'tests/output/generate-changelog.md'
)
with open(changelog_output, 'r') as file:
cls.changelog_output = file.read().strip()

# Expected output of the `generate-changelog --show-releases`
# command.
changelog_releases_output = project_dir(
'tests/output/generate-changelog-releases.md'
)
with open(changelog_releases_output, 'r') as file:
cls.changelog_releases_output = file.read().strip()

@internet_available_only
@log_info
def test_01_generate_changelog_command(self):
"""Test generate changelog command."""
res = subprocess.check_output('generate-changelog').strip()
self.assertEqual(res, b'')
res = subprocess.check_output([
'generate-changelog'
]).strip().decode()
self.assertEqual(res, self.changelog_output)
return res

@internet_available_only
@log_info
def test_02_generate_changelog_command_show_releases(self):
"""Test generate changelog command."""
res = subprocess.check_output([
'generate-changelog',
'--show-releases'
]).strip().decode()
self.assertEqual(res, self.changelog_releases_output)
return res


Expand Down
12 changes: 1 addition & 11 deletions src/matyan/tests/test_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
import os
import unittest

import six
from six.moves.urllib.parse import urlsplit
from ..utils import (
create_default_config_file,
create_config_file,
generate_changelog_cli,
generate_empty_tree,
get_branch_type,
Expand Down Expand Up @@ -41,14 +39,6 @@ def tearDown(self):
"""Tear down."""
# TODO

@property
def good_url(self):
return self.good_patterns[0]['url']

@property
def bad_url(self):
return list(self.bad_patterns.keys())[0]

@internet_available_only
@log_info
def test_01_generate_changelog_command(self):
Expand Down
8 changes: 6 additions & 2 deletions src/matyan/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
__copyright__ = '2019 Artur Barseghyan'
__license__ = 'GPL-2.0-only OR LGPL-2.0-or-later'
__all__ = (
'create_default_config_file',
'create_config_file',
'generate_changelog_cli',
'generate_empty_tree',
'get_branch_type',
Expand Down Expand Up @@ -533,7 +533,7 @@ def json_changelog_cli() -> Type[None]:
# pprint(tree)


def generate_changelog_cli() -> Type[None]:
def generate_changelog() -> str:
"""Generate changelog (markdown format)."""
parser = argparse.ArgumentParser(description='Generate changelog')
parser.add_argument(
Expand Down Expand Up @@ -642,6 +642,10 @@ def generate_changelog_cli() -> Type[None]:
return '\n'.join(changelog)


def generate_changelog_cli() -> Type[None]:
print(generate_changelog())


def create_config_file() -> bool:
"""Create config file.
Expand Down

0 comments on commit 23128e6

Please sign in to comment.