From 763ab1f7db17adba8f8f8bc97e2b34975badaa96 Mon Sep 17 00:00:00 2001 From: Martijn Vermaat <martijn@vermaat.name> Date: Mon, 22 Sep 2014 22:25:41 +0200 Subject: [PATCH] Announcement in info webservice method Closes #11 --- mutalyzer/models.py | 2 ++ mutalyzer/services/rpc.py | 9 +++++++++ tests/test_services_json.py | 19 +++++++++++++++++++ tests/test_website.py | 21 ++++++++++++++++++++- 4 files changed, 50 insertions(+), 1 deletion(-) diff --git a/mutalyzer/models.py b/mutalyzer/models.py index 6cb3277f..f7356dda 100644 --- a/mutalyzer/models.py +++ b/mutalyzer/models.py @@ -290,6 +290,8 @@ class InfoOutput(ComplexModel): nomenclatureVersionParts = Array(String) serverName = String contactEmail = String + announcement = String + announcementUrl = String #InfoOutput diff --git a/mutalyzer/services/rpc.py b/mutalyzer/services/rpc.py index 0c1b042d..5a2eb753 100644 --- a/mutalyzer/services/rpc.py +++ b/mutalyzer/services/rpc.py @@ -29,6 +29,7 @@ from mutalyzer.db.models import (Assembly, Chromosome, BatchJob, from mutalyzer.output import Output from mutalyzer.grammar import Grammar from mutalyzer.sync import CacheSync +from mutalyzer import announce from mutalyzer import stats from mutalyzer import variantchecker from mutalyzer.mapping import Converter @@ -1160,6 +1161,9 @@ class MutalyzerService(ServiceBase): version as a list of strings. - serverName: The name of the server that is being queried. - contactEmail: The email address to contact for more information. + - announcement: Announcement body text. + - announcementUrl: URL to go with the announcement for further + information. @rtype: object """ output = Output(__file__) @@ -1177,6 +1181,11 @@ class MutalyzerService(ServiceBase): result.serverName = socket.gethostname() result.contactEmail = mutalyzer.__contact__ + announcement = announce.get_announcement() + if announcement: + result.announcement = announcement['body'] + result.announcementUrl = announcement['url'] + output.addMessage(__file__, -1, 'INFO', 'Finished processing info') return result #info diff --git a/tests/test_services_json.py b/tests/test_services_json.py index 461e8171..ce029ba7 100644 --- a/tests/test_services_json.py +++ b/tests/test_services_json.py @@ -6,6 +6,7 @@ Tests for the JSON interface to Mutalyzer. import simplejson as json from spyne.server.null import NullServer import mutalyzer +from mutalyzer import announce from mutalyzer.services.json import application from fixtures import database, hg19, hg19_transcript_mappings @@ -78,3 +79,21 @@ class TestServicesJson(MutalyzerTest): r = self._call('info') assert type(r['versionParts']) == list assert r['version'] == mutalyzer.__version__ + + def test_info_announcement(self): + """ + Running the info method should show us the current announcement + """ + announce.set_announcement('Test announcement') + r = self._call('info') + assert type(r['announcement']) == str + assert r['announcement'] == 'Test announcement' + + announce.set_announcement('New announcement') + r = self._call('info') + assert type(r['announcement']) == str + assert r['announcement'] == 'New announcement' + + announce.unset_announcement() + r = self._call('info') + assert not r.get('announcement') diff --git a/tests/test_website.py b/tests/test_website.py index 6b1e75d0..44d9e996 100644 --- a/tests/test_website.py +++ b/tests/test_website.py @@ -21,7 +21,7 @@ from Bio import Entrez import lxml.html import mutalyzer -from mutalyzer import Scheduler +from mutalyzer import announce, Scheduler from mutalyzer.website import create_app from fixtures import cache, database, hg19, hg19_transcript_mappings @@ -85,6 +85,25 @@ class TestWebsite(MutalyzerTest): r = self.app.get(href) assert r.status_code == 200 + def test_announcement(self): + """ + We should always see the current announcement. + """ + announce.set_announcement('Test announcement') + r = self.app.get('/syntax-checker') + assert r.status == '200 OK' + assert 'Test announcement' in r.data + + announce.set_announcement('New announcement') + r = self.app.get('/syntax-checker') + assert r.status == '200 OK' + assert 'New announcement' in r.data + + announce.unset_announcement() + r = self.app.get('/syntax-checker') + assert r.status == '200 OK' + assert 'nnouncement' not in r.data + def test_description_extractor(self): """ Submit the variant description extractor. -- GitLab