-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start testing the pytlas assistant manager (pam)
- Loading branch information
Showing
4 changed files
with
136 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class SkillData: | ||
"""Represents a single skill data. | ||
""" | ||
|
||
def __init__(self, package, name=None, description='No description provided', | ||
version='?.?.?', author='', homepage='', media=''): | ||
self.package = package | ||
self.name = name or package | ||
self.media = media | ||
self.description = description | ||
self.version = version | ||
self.author = author | ||
self.homepage = homepage | ||
|
||
def __str__(self): | ||
return """{name} - v{version} | ||
description: {description} | ||
homepage: {homepage} | ||
author: {author} | ||
package: {package} | ||
""".format(**self.__dict__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
from sure import expect | ||
from unittest.mock import patch | ||
from pytlas.skill import register, register_metadata | ||
from pytlas.pam import get_installed_skills | ||
from pytlas.skill_data import SkillData | ||
|
||
class TestPam: | ||
|
||
def test_it_should_retrieve_installed_skills_from_handlers(self): | ||
register('get_weather', lambda r: r.agent.done(), 'atlassistant__weather') | ||
|
||
with patch('pytlas.pam.get_package_name_from_module', return_value='atlassistant__weather'): | ||
r = get_installed_skills('fr') | ||
|
||
expect(r).to.have.length_of(1) | ||
|
||
data = r[0] | ||
|
||
expect(data).to.be.a(SkillData) | ||
expect(data.name).to.equal('atlassistant/weather') | ||
expect(data.version).to.equal('?.?.?') | ||
|
||
def test_it_should_list_installed_skill_metadata_when_available(self): | ||
|
||
def get_meta(_): return { | ||
'name': 'weather', | ||
'version': '1.0.0', | ||
} | ||
|
||
register('get_weather', lambda r: r.agent.done(), 'atlassistant__weather') | ||
register_metadata(get_meta, 'atlassistant__weather') | ||
|
||
with patch('pytlas.pam.get_package_name_from_module', return_value='atlassistant__weather'): | ||
r = get_installed_skills('fr') | ||
|
||
expect(r).to.have.length_of(1) | ||
|
||
data = r[0] | ||
|
||
expect(data).to.be.a(SkillData) | ||
expect(data.name).to.equal('weather') | ||
expect(data.package).to.equal('atlassistant/weather') | ||
expect(data.version).to.equal('1.0.0') | ||
|
||
def test_it_should_localize_installed_skill_metadata_when_available(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
from sure import expect | ||
from pytlas.skill_data import SkillData | ||
|
||
TEST_PACKAGE = 'atlassistant__weather' | ||
TEST_NAME = 'weather' | ||
TEST_DESCRIPTION = 'Give weather forecasts' | ||
TEST_VERSION = '1.1.0' | ||
TEST_AUTHOR = 'Julien LEICHER' | ||
TEST_HOMEPAGE = 'https://julien.leicher.me' | ||
|
||
class TestSkillData: | ||
|
||
def test_it_should_contain_package_as_the_name_if_not_defined(self): | ||
data = SkillData(package=TEST_PACKAGE) | ||
|
||
expect(data.name).to.equal(data.package) | ||
|
||
def test_it_should_print_correctly(self): | ||
data = SkillData( | ||
package=TEST_PACKAGE, | ||
name=TEST_NAME, | ||
description=TEST_DESCRIPTION, | ||
version=TEST_VERSION, | ||
homepage=TEST_HOMEPAGE, | ||
author=TEST_AUTHOR) | ||
|
||
expect(str(data)).to.equal("""%s - v%s | ||
description: %s | ||
homepage: %s | ||
author: %s | ||
package: %s | ||
""" % (TEST_NAME, TEST_VERSION, TEST_DESCRIPTION, TEST_HOMEPAGE, TEST_AUTHOR, TEST_PACKAGE)) |