-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This defines message schema using json-schema for a subset of messages sent by Anitya. Signed-off-by: Jeremy Cline <jcline@redhat.com>
- Loading branch information
1 parent
74ea662
commit 832e387
Showing
9 changed files
with
786 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,5 @@ | ||
JSON schema definitions for messages published by Anitya. | ||
|
||
See http://json-schema.org/ for documentation on the schema format. See | ||
https://fedora-messaging.readthedocs.io/en/latest/messages.html for | ||
documentation on fedora-messaging. |
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,15 @@ | ||
# Copyright (C) 2018 Red Hat, Inc. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
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,139 @@ | ||
# Copyright (C) 2018 Red Hat, Inc. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
"""The schema for messages sent by Anitya.""" | ||
|
||
from fedora_messaging import message | ||
|
||
|
||
class DistroCreatedV1(message.Message): | ||
""" | ||
Message sent by Anitya to the "anitya.distro.add" topic when a new | ||
distribution is added. | ||
""" | ||
|
||
body_schema = { | ||
'id': 'https://fedoraproject.org/jsonschema/anitya_distro_createdv1.json', | ||
'$schema': 'http://json-schema.org/draft-04/schema#', | ||
'description': 'Message sent when a new distro is created in Anitya', | ||
'type': 'object', | ||
'required': ['msg'], | ||
'properties': { | ||
'msg': { | ||
'type': 'object', | ||
'description': 'The actual message', | ||
'properties': { | ||
'project': {'type': 'null'}, | ||
'message': { | ||
'type': 'object', | ||
'properties': { | ||
'agent': {'type': 'string'}, | ||
'distro': {'type': 'string'}, | ||
}, | ||
'required': ['agent', 'distro'], | ||
}, | ||
'distro': { | ||
'type': 'object', | ||
'properties': { | ||
'name': {'type': 'string'}, | ||
}, | ||
'required': ['name'], | ||
}, | ||
}, | ||
'required': ['project', 'message', 'distro'], | ||
}, | ||
}, | ||
} | ||
|
||
def __str__(self): | ||
"""Return a complete human-readable representation of the message""" | ||
return 'A new distribution, {}, was added to Anitya.'.format( | ||
self.body['msg']['distro']['name']) | ||
|
||
def summary(self): | ||
"""Return a short summary of the message.""" | ||
return str(self) | ||
|
||
|
||
class ProjectCreatedV1(message.Message): | ||
""" | ||
The message sent when a new project is created in Anitya. The message topic | ||
is currently '<prefix>.{stg,prod}.anitya.project.add' | ||
""" | ||
|
||
body_schema = { | ||
'id': 'https://fedoraproject.org/jsonschema/anitya_project_createdv1.json', | ||
'$schema': 'http://json-schema.org/draft-04/schema#', | ||
'description': 'Message sent when a new project is created in Anitya', | ||
'type': 'object', | ||
'required': ['msg'], | ||
'properties': { | ||
'msg': { | ||
'type': 'object', | ||
'description': 'The actual message', | ||
'required': ['project', 'message', 'distro'], | ||
'properties': { | ||
'distro': {'type': 'null'}, | ||
'message': { | ||
'type': 'object', | ||
'properties': { | ||
'agent': {'type': 'string'}, | ||
'project': {'type': 'string'}, | ||
}, | ||
'required': ['agent', 'project'], | ||
}, | ||
'project': { | ||
'type': 'object', | ||
'properties': { | ||
'backend': {'type': 'string'}, | ||
'created_on': {'type': 'number'}, | ||
'homepage': {'type': 'string'}, | ||
'id': {'type': 'integer'}, | ||
'name': {'type': 'string'}, | ||
'regex': {'anyOf': [{'type': 'string'}, {'type': 'null'}]}, | ||
'updated_on': {'type': 'number'}, | ||
'version': {'anyOf': [{'type': 'string'}, {'type': 'null'}]}, | ||
'version_url': {'anyOf': [{'type': 'string'}, {'type': 'null'}]}, | ||
'versions': {'type': 'array'}, | ||
}, | ||
'required': [ | ||
'backend', | ||
'created_on', | ||
'homepage', | ||
'id', | ||
'name', | ||
'regex', | ||
'updated_on', | ||
'version', | ||
'version_url', | ||
'versions', | ||
], | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
|
||
def __str__(self): | ||
""" | ||
Return a complete human-readable representation of the message, which | ||
in this case is equivalent to the summary. | ||
""" | ||
return 'A new project, {}, was added to Anitya.'.format( | ||
self.body['msg']['project']['name']) | ||
|
||
def summary(self): | ||
"""Return a summary of the message.""" | ||
return str(self) |
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,15 @@ | ||
# Copyright (C) 2018 Red Hat, Inc. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
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,151 @@ | ||
# Copyright (C) 2018 Red Hat, Inc. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
"""Unit tests for the message schema.""" | ||
import unittest | ||
|
||
from jsonschema import ValidationError | ||
from .. import schema | ||
|
||
|
||
class DistroCreatedV1Tests(unittest.TestCase): | ||
"""A set of unit tests to ensure the schema works as expected.""" | ||
|
||
def test_message(self): | ||
""" | ||
Assert the message schema validates a message with the minimal number | ||
of required fields. | ||
""" | ||
body = { | ||
'msg': { | ||
'project': None, | ||
'message': { | ||
'agent': 'Bond', | ||
'distro': 'Fedora', | ||
}, | ||
'distro': {'name': 'Fedora'}, | ||
} | ||
} | ||
message = schema.DistroCreatedV1(body=body) | ||
|
||
message.validate() | ||
|
||
def test_missing_field(self): | ||
"""Assert missing the 'distro' key causes a validation error.""" | ||
body = { | ||
'msg': { | ||
'project': None, | ||
'message': { | ||
'agent': 'Bond', | ||
'distro': 'Fedora', | ||
}, | ||
} | ||
} | ||
message = schema.DistroCreatedV1(body=body) | ||
|
||
self.assertRaises(ValidationError, message.validate) | ||
|
||
def test_str(self): | ||
"""Assert __str__ produces a human-readable message.""" | ||
body = { | ||
'msg': { | ||
'project': None, | ||
'message': { | ||
'agent': 'Bond', | ||
'distro': 'Fedora', | ||
}, | ||
'distro': {'name': 'Fedora'}, | ||
} | ||
} | ||
message = schema.DistroCreatedV1(body=body) | ||
expected_str = 'A new distribution, Fedora, was added to Anitya.' | ||
|
||
message.validate() | ||
self.assertEqual(expected_str, str(message)) | ||
|
||
def test_summary(self): | ||
"""Assert the summary function is implemented.""" | ||
body = { | ||
'msg': { | ||
'project': None, | ||
'message': { | ||
'agent': 'Bond', | ||
'distro': 'Fedora', | ||
}, | ||
'distro': {'name': 'Fedora'}, | ||
} | ||
} | ||
message = schema.DistroCreatedV1(body=body) | ||
expected_str = 'A new distribution, Fedora, was added to Anitya.' | ||
|
||
message.validate() | ||
self.assertEqual(expected_str, message.summary()) | ||
|
||
|
||
class ProjectCreatedV1Tests(unittest.TestCase): | ||
"""A set of unit tests to ensure the schema works as expected.""" | ||
|
||
def setUp(self): | ||
self.body = { | ||
'msg': { | ||
'project': { | ||
'backend': 'PyPI', | ||
'created_on': 0, | ||
'homepage': 'http://example.com', | ||
'id': 1, | ||
'name': 'arrow', | ||
'regex': None, | ||
'updated_on': 0, | ||
'version': None, | ||
'version_url': 'https://gitlab.example.com/arrow', | ||
'versions': [], | ||
}, | ||
'message': { | ||
'agent': 'Bond', | ||
'project': 'arrow', | ||
}, | ||
'distro': None, | ||
}, | ||
} | ||
|
||
def test_message(self): | ||
""" | ||
Assert the message schema validates a message with the minimal number | ||
of required fields. | ||
""" | ||
message = schema.ProjectCreatedV1(body=self.body) | ||
message.validate() | ||
|
||
def test_missing_field(self): | ||
"""Assert missing the 'distro' key causes a validation error.""" | ||
del self.body['msg']['project'] | ||
message = schema.ProjectCreatedV1(body=self.body) | ||
self.assertRaises(ValidationError, message.validate) | ||
|
||
def test_str(self): | ||
"""Assert __str__ produces a human-readable message.""" | ||
message = schema.ProjectCreatedV1(body=self.body) | ||
expected_str = 'A new project, arrow, was added to Anitya.' | ||
|
||
message.validate() | ||
self.assertEqual(expected_str, str(message)) | ||
|
||
def test_summary(self): | ||
"""Assert the summary function is implemented.""" | ||
message = schema.ProjectCreatedV1(body=self.body) | ||
expected_str = 'A new project, arrow, was added to Anitya.' | ||
|
||
message.validate() | ||
self.assertEqual(expected_str, message.summary()) |
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,2 @@ | ||
[bdist_wheel] | ||
universal = 1 |
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,62 @@ | ||
#!/usr/bin/env python | ||
# | ||
# Copyright (C) 2018 Red Hat, Inc. | ||
# | ||
# This program is free software; you can redistribute it and/or modify | ||
# it under the terms of the GNU General Public License as published by | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU General Public License along | ||
# with this program; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
import os | ||
|
||
from setuptools import setup, find_packages | ||
|
||
|
||
here = os.path.abspath(os.path.dirname(__file__)) | ||
with open(os.path.join(here, 'README')) as fd: | ||
README = fd.read() | ||
|
||
|
||
setup( | ||
name='anitya_schema', | ||
version='1.0.0', | ||
description='JSON schema definitions for messages published by Anitya', | ||
long_description=README, | ||
url='https://github.com/release-monitoring/anitya/', | ||
# Possible options are at https://pypi.python.org/pypi?%3Aaction=list_classifiers | ||
classifiers=[ | ||
'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)', | ||
'Operating System :: POSIX :: Linux', | ||
'Programming Language :: Python :: 2', | ||
'Programming Language :: Python :: 2.7', | ||
'Programming Language :: Python :: 3', | ||
'Programming Language :: Python :: 3.4', | ||
'Programming Language :: Python :: 3.5', | ||
'Programming Language :: Python :: 3.6', | ||
], | ||
license='GPLv2+', | ||
maintainer='Fedora Infrastructure Team', | ||
maintainer_email='infrastructure@lists.fedoraproject.org', | ||
platforms=['Fedora', 'GNU/Linux'], | ||
keywords='fedora', | ||
packages=find_packages( | ||
exclude=('anitya_schema.tests', 'anitya_schema.tests.*')), | ||
include_package_data=True, | ||
zip_safe=False, | ||
install_requires=['fedora_messaging'], | ||
test_suite='anitya_schema.tests', | ||
entry_points={ | ||
'fedora.messages': [ | ||
'anitya_distro_createdv1=anitya_schema.schema:DistroCreatedV1', | ||
'anitya_project_createdv1=anitya_schema.schema:ProjectCreatedV1', | ||
] | ||
} | ||
) |
Oops, something went wrong.