Beispiel #1
0
    def get_quote(self, **kwargs):

        quote = None

        if kwargs.get('previous'):
            quote = quote_service.previous()

        if not quote:
            quote = quote_service.search(kwargs.get('text', ""))

        if not quote:
            quote = quote_service.next()

        if quote:
            quote_service.hit(quote=quote)
        else:
            quote = Quote(text='No quote in database', author=Author(name='System message'))

        return quote
Beispiel #2
0
    def post(self, request):

        form = SlackPOSTForm(data=request.POST)

        quote = None

        if form.is_valid():
            quote = quote_service.search(form.cleaned_data['text'])

        if not quote:
            quote = quote_service.next()

        if quote:
            quote_service.hit(quote=quote)
        else:
            quote = Quote(text='No quote in database',
                          author=Author(name='System message'))

        prefix = 'https://' if request.is_secure() else 'http://'
        path = prefix + request.get_host() + '/'

        return JsonResponse(in_channel_response(quote=quote, path=path))
    def test_context_english(self):
        quote = quote_service.search('context_english')

        self.assertEqual(quote, self.good_quote)
    def test_context(self):
        quote = quote_service.search('context_native')

        self.assertEqual(quote, self.good_quote)
    def test_parameter_only(self):

        quote = quote_service.search('--some-parameter')

        self.assertEqual(quote, None)
    def test(self):

        quote = quote_service.search('something_not_existing')

        self.assertEqual(quote, None)