File tree Expand file tree Collapse file tree 3 files changed +19
-9
lines changed
Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change 113113AUTOINSTALL_DEPS = True
114114
115115DEFAULT_CONFIG = {
116+ 'answer' : {
117+ 'ANSWER_END' : os .environ .get ('ANSWER_END' ),
118+ },
116119 'LabHub' : {
117120 'GH_TOKEN' : os .environ .get ('GH_TOKEN' ),
118121 'GL_TOKEN' : os .environ .get ('GL_TOKEN' ),
Original file line number Diff line number Diff line change 11import json
2- import os
32from urllib .parse import quote_plus , urljoin
43
54from errbot import BotPlugin , botcmd
5+ from utils .mixin import DefaultConfigMixin
66import requests
77
88
9- class Answer (BotPlugin ):
9+ class Answer (DefaultConfigMixin , BotPlugin ):
1010
11+ CONFIG_TEMPLATE = {
12+ 'ANSWER_END' : None ,
13+ }
1114 # Ignore LineLengthBear, PyCodestyleBear
1215 SURVEY_LINK = 'https://docs.google.com/forms/d/e/1FAIpQLSeD8lqMWAwJx0Mewlpc5Sbeo3MH5Yi9fSfXA6jnk07-aIURSA/viewform?usp=pp_url&entry.1236347280={question}&entry.1734934116={response}&entry.75323266={message_link}'
1316 MESSAGE_LINK = 'https://gitter.im/{uri}?at={idd}'
@@ -26,7 +29,7 @@ def construct_link(text):
2629 @botcmd
2730 def answer (self , msg , arg ):
2831 try :
29- answers = requests .get (urljoin (os . environ ['ANSWER_END' ], 'answer' ),
32+ answers = requests .get (urljoin (self . config ['ANSWER_END' ], 'answer' ),
3033 params = {'question' : arg }).json ()
3134 except json .JSONDecodeError :
3235 self .log .exception ('something went wrong while fetching answer for'
Original file line number Diff line number Diff line change 1- import os
21import vcr
32import requests_mock
43
98class TestAnswer (IsolatedTestCase ):
109
1110 def setUp (self ):
12- super ().setUp ()
1311 # Ignore InvalidLinkBear
1412 self .answer_end_point = 'http://0.0.0.0:8000'
15- os .environ ['ANSWER_END' ] = self .answer_end_point
16-
17- def tearDown (self ):
18- del os .environ ['ANSWER_END' ]
13+ extra_config = {
14+ 'DEFAULT_CONFIG' : {
15+ 'answer' : {
16+ 'ANSWER_END' : self .answer_end_point ,
17+ }
18+ }
19+ }
20+ super ().setUp (extra_config = extra_config )
1921
2022 @vcr .use_cassette ('tests/cassettes/answer.yaml' )
2123 def test_answer (self ):
@@ -24,6 +26,8 @@ def test_answer(self):
2426 self .assertIn ('Please checkout the following links' , self .pop_message ())
2527 self .push_message ('!answer shell autocompletion' )
2628 self .assertIn ('Please checkout the following links' , self .pop_message ())
29+ self .assertCommand ('!plugin config answer' ,
30+ str ({'ANSWER_END' : self .answer_end_point }))
2731
2832 def test_invalid_json (self ):
2933 with requests_mock .Mocker () as m :
You can’t perform that action at this time.
0 commit comments