Пример #1
0
 def post(self, request, format=None):
     data = parse_qa(request.POST.get('qanda'))
     question = get_question(
         question_txt=data['question'], keywords=data['keywords'])
     answer = get_answer(
         question=question, answer_txt=data['answer'], url=data['url'])
     return JSONResponse(answer.id)
Пример #2
0
 def test_only_question(self):
     qa = 'How do I do the thing?'
     expected = {
         'question': 'How do I do the thing?',
         'keywords': '',
         'url': '',
         'answer': ''
     }
     self.assertEqual(parse_qa(qa), expected)
Пример #3
0
 def test_extract_question_and_url(self):
     qa = 'How do I do the thing? http://learntodoathing.com/'
     expected = {
         'question': 'How do I do the thing?',
         'keywords': '',
         'url': 'http://learntodoathing.com/',
         'answer': ''
     }
     self.assertEqual(parse_qa(qa), expected)
Пример #4
0
 def test_fields_stripped_of_whitespace(self):
     qa = '  How do I do the thing ? Believe you can!   http://doathing.com/ '
     expected = {
         'question': 'How do I do the thing?',
         'keywords': '',
         'url': 'http://doathing.com/',
         'answer': 'Believe you can!'
     }
     self.assertEqual(parse_qa(qa), expected)
Пример #5
0
 def test_keywords_are_added_to_the_question(self):
     qa = 'How do I change the theme? (themes, style, styles) Use our handy tool! https://example.com/'
     expected = {
         'question': 'How do I change the theme?',
         'keywords': 'themes, style, styles',
         'url': 'https://example.com/',
         'answer': 'Use our handy tool!'
     }
     self.assertEqual(parse_qa(qa), expected)
Пример #6
0
 def test_questions_and_answers_can_talk_about_http(self):
     qa = 'How do I redirect from https to https? Just redirect from http to https.  http://beggingthequestion.com/'
     expected = {
         'question': 'How do I redirect from https to https?',
         'keywords': '',
         'url': 'http://beggingthequestion.com/',
         'answer': 'Just redirect from http to https.'
     }
     self.assertEqual(parse_qa(qa), expected)
Пример #7
0
 def test_extract_question_answer_url(self):
     qa = 'How do I do the thing? Believe you can! http://doathing.com/'
     expected = {
         'question': 'How do I do the thing?',
         'keywords': '',
         'url': 'http://doathing.com/',
         'answer': 'Believe you can!'
     }
     self.assertEqual(parse_qa(qa), expected)
Пример #8
0
 def test_extract_question_and_answer(self):
     qa = 'How do I do the thing? You must believe you can do the thing.'
     expected = {
         'question': 'How do I do the thing?',
         'keywords': '',
         'url': '',
         'answer': 'You must believe you can do the thing.'
     }
     self.assertEqual(parse_qa(qa), expected)