Skip to content

Commit

Permalink
Merge pull request #19 from octue/v0.0.6
Browse files Browse the repository at this point in the history
v0.0.6
  • Loading branch information
thclark committed Jan 9, 2020
2 parents 99c1657 + dbbf62d commit ac0d2b4
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 60 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

setup(
name='twined',
version='0.0.5',
version='0.0.6',
py_modules=[],
install_requires=['jsonschema ~= 3.2.0'],
url='https://www.github.com/octue/twined',
Expand Down
Empty file added tests/__init__.py
Empty file.
12 changes: 12 additions & 0 deletions tests/base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import os
import unittest


class BaseTestCase(unittest.TestCase):
""" Base test case for twined:
- sets a path to the test data directory
"""

def setUp(self):
self.path = str(os.path.join(os.path.dirname(os.path.abspath(__file__)), 'data', ''))
super().setUp()
55 changes: 28 additions & 27 deletions tests/test_children.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import unittest
from twined import Twine, exceptions
from .base import BaseTestCase


class TestChildrenTwine(unittest.TestCase):
class TestChildrenTwine(BaseTestCase):
""" Tests related to the twine itself - ensuring that valid and invalid
`children` entries in a twine file work as expected
"""
Expand All @@ -11,49 +12,49 @@ def test_invalid_children_dict_not_array(self):
""" Ensures InvalidTwine exceptions are raised when instantiating twines where `children` entry is incorrectly
specified as a dict, not an array
"""
twine_file = 'data/twines/invalid_children_dict_not_array_twine.json'
twine_file = self.path + 'twines/invalid_children_dict_not_array_twine.json'
with self.assertRaises(exceptions.InvalidTwine):
Twine(file=twine_file)

def test_invalid_children_no_key(self):
""" Ensures InvalidTwine exceptions are raised when instantiating twines where a child
is specified without the required `key` field
"""
twine_file = 'data/twines/invalid_children_no_key_twine.json'
twine_file = self.path + 'twines/invalid_children_no_key_twine.json'
with self.assertRaises(exceptions.InvalidTwine):
Twine(file=twine_file)

def test_valid_children(self):
""" Ensures that a twine can be instantiated with correctly specified children
"""
twine_file = 'data/twines/valid_children_twine.json'
twine_file = self.path + 'twines/valid_children_twine.json'
twine = Twine(file=twine_file)
self.assertEqual(len(twine._raw['children']), 1)


class TestChildrenValidation(unittest.TestCase):
""" Tests related to whether validation of children occurs successfully (given a valid twine)
"""

def test_no_children(self):
""" Test that a twine with no children will validate on an empty children input
"""
raise exceptions.NotImplementedYet()

def test_missing_children(self):
""" Test that a twine with children will not validate on an empty children input
"""
raise exceptions.NotImplementedYet()

def test_extra_children(self):
""" Test that a twine with no children will not validate a non-empty children input
"""
raise exceptions.NotImplementedYet()

def test_matched_children(self):
""" Test that a twine with children required will validate when the children input matches
"""
raise exceptions.NotImplementedYet()
# class TestChildrenValidation(unittest.TestCase):
# """ Tests related to whether validation of children occurs successfully (given a valid twine)
# """
#
# def test_no_children(self):
# """ Test that a twine with no children will validate on an empty children input
# """
# raise exceptions.NotImplementedYet()
#
# def test_missing_children(self):
# """ Test that a twine with children will not validate on an empty children input
# """
# raise exceptions.NotImplementedYet()
#
# def test_extra_children(self):
# """ Test that a twine with no children will not validate a non-empty children input
# """
# raise exceptions.NotImplementedYet()
#
# def test_matched_children(self):
# """ Test that a twine with children required will validate when the children input matches
# """
# raise exceptions.NotImplementedYet()


if __name__ == '__main__':
Expand Down
49 changes: 25 additions & 24 deletions tests/test_credentials.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import unittest
from twined import Twine, exceptions
from .base import BaseTestCase


class TestCredentialsTwine(unittest.TestCase):
class TestCredentialsTwine(BaseTestCase):
""" Tests related to the twine itself - ensuring that valid and invalid
`credentials` entries in a twine file work as expected
"""
Expand All @@ -11,51 +12,51 @@ def test_fails_on_no_name(self):
""" Ensures InvalidTwine exceptions are raised when instantiating twines
with a missing `name` field in a credential
"""
twine_file = 'data/twines/invalid_credentials_no_name_twine.json'
twine_file = self.path + 'twines/invalid_credentials_no_name_twine.json'
with self.assertRaises(exceptions.InvalidTwine):
Twine(file=twine_file)

def test_fails_on_lowercase_name(self):
""" Ensures InvalidTwine exceptions are raised when instantiating twines
with lowercase letters in the `name` field
"""
twine_file = 'data/twines/invalid_credentials_lowercase_name_twine.json'
twine_file = self.path + 'twines/invalid_credentials_lowercase_name_twine.json'
with self.assertRaises(exceptions.InvalidTwine):
Twine(file=twine_file)

def test_fails_on_dict(self):
""" Ensures InvalidTwine exceptions are raised when instantiating twines
with invalid `credentials` entries (given as a dict, not an array)
"""
twine_file = 'data/twines/invalid_credentials_dict_not_array_twine.json'
twine_file = self.path + 'twines/invalid_credentials_dict_not_array_twine.json'
with self.assertRaises(exceptions.InvalidTwine):
Twine(file=twine_file)

def test_fails_on_name_whitespace(self):
twine_file = 'data/twines/invalid_credentials_space_in_name_twine.json'
twine_file = self.path + 'twines/invalid_credentials_space_in_name_twine.json'
with self.assertRaises(exceptions.InvalidTwine):
Twine(file=twine_file)


class TestCredentialsValidation(unittest.TestCase):
""" Tests related to whether validation of children occurs successfully (given a valid twine)
"""

def test_no_credentials(self):
""" Test that a twine with no credentials will validate straightforwardly
"""
raise exceptions.NotImplementedYet()

def test_missing_credentials(self):
""" Test that a twine with credentials will not validate where they are missing from the environment
"""
raise exceptions.NotImplementedYet()

def test_matched_credentials(self):
""" Test that a twine with credentials required will validate when the credentials are available in the
environment
"""
raise exceptions.NotImplementedYet()
# class TestCredentialsValidation(unittest.TestCase):
# """ Tests related to whether validation of children occurs successfully (given a valid twine)
# """
#
# def test_no_credentials(self):
# """ Test that a twine with no credentials will validate straightforwardly
# """
# raise exceptions.NotImplementedYet()
#
# def test_missing_credentials(self):
# """ Test that a twine with credentials will not validate where they are missing from the environment
# """
# raise exceptions.NotImplementedYet()
#
# def test_matched_credentials(self):
# """ Test that a twine with credentials required will validate when the credentials are available in the
# environment
# """
# raise exceptions.NotImplementedYet()


if __name__ == '__main__':
Expand Down
19 changes: 11 additions & 8 deletions tests/test_twine.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
import unittest
from twined import Twine, exceptions
from .base import BaseTestCase


class TestTwine(unittest.TestCase):
class TestTwine(BaseTestCase):
""" Testing operation of the Twine class
"""

def test_init_twine_with_filename(self):
""" Ensures that the twine class can be instantiated with a file
"""
twine_file = 'data/simple_app/twine.json'
twine_file = self.path + 'simple_app/twine.json'
Twine(file=twine_file)

def test_init_twine_with_json(self):
""" Ensures that a twine can be instantiated with a json string
"""
with open('data/simple_app/twine.json', 'r', encoding='utf-8') as f:
with open(self.path + 'simple_app/twine.json', 'r', encoding='utf-8') as f:
json_string = f.read()
Twine(json=json_string)

Expand All @@ -28,7 +31,7 @@ def test_init_twine_with_both_inputs(self):
"""
with self.assertRaises(exceptions.InvalidInput):
Twine(
file='data/simple_app/twine.json',
file=self.path + 'simple_app/twine.json',
json='{"input_values": "something"}'
)

Expand All @@ -51,7 +54,7 @@ def test_no_twine(self):
def test_empty_twine(self):
""" Ensures that an empty twine file can be loaded
"""
twine_file = 'data/empty_app/twine.json'
twine_file = self.path + 'empty_app/twine.json'
with self.assertLogs(level='DEBUG') as log:
Twine(file=twine_file)
self.assertEqual(len(log.output), 2)
Expand All @@ -62,19 +65,19 @@ def test_empty_twine(self):
def test_example_twine(self):
""" Ensures that the example (full) twine can be loaded and validated
"""
twine_file = 'data/example_app/twine.json'
twine_file = self.path + 'example_app/twine.json'
Twine(file=twine_file)

def test_simple_twine(self):
""" Ensures that the simple app schema can be loaded and used to parse some basic config and values data
"""
twine_file = 'data/simple_app/twine.json'
twine_file = self.path + 'simple_app/twine.json'
Twine(file=twine_file)

def test_broken_json_twine(self):
""" Ensures that an invalid json file raises an InvalidTwine exception
"""
twine_file = 'data/twines/invalid_json_twine.json'
twine_file = self.path + 'twines/invalid_json_twine.json'
with self.assertRaises(exceptions.InvalidTwine):
Twine(file=twine_file)

Expand Down

0 comments on commit ac0d2b4

Please sign in to comment.