Beispiel #1
0
    def test_when_ngram_less_than_one(self):
        """ fails """
        self.params['ngram'] = -1

        with pytest.raises(ValidationError) as err:
            validate_post_params(self.params)

        self.assertEqual(
            err.value.status_code, 400
        )
        self.assertEqual(str(err.value.detail[0]),
                         'ngram must be a positive number and greater than 0')
Beispiel #2
0
    def test_when_unknow_params_are_passed(self):
        """ raises and error """

        self.params['some_param'] = 'None'

        with pytest.raises(ParseError) as err:
            validate_post_params(self.params)

        self.assertEqual(
            err.value.status_code, 400
        )
        self.assertEqual(str(err.value.detail),
                         "some_param shouldn't be in the params")
Beispiel #3
0
    def test_body_is_null_or_empty(self):
        """ raises and error """

        self.params['body'] = ''

        with pytest.raises(ValidationError) as err:
            validate_post_params(self.params)

        self.assertEqual(
            err.value.status_code, 400
        )
        self.assertEqual(str(err.value.detail[0]),
                         'text must exist to calculate ngrams')
Beispiel #4
0
    def create_stats(self, request):
        """ create stats """

        post_params = request.data
        validate_post_params(post_params)
        ngram = post_params.get('ngram', 1)
        body = post_params.get('body')
        case_sensitive = post_params.get('case_sensitive', True)
        length = post_params.get('length', 100)

        stats = calculate_ngrams(ngram=int(ngram),
                                 body=body,
                                 case_sensitive=case_sensitive,
                                 length=int(length))

        return Response(stats, status=status.HTTP_201_CREATED)
Beispiel #5
0
 def test_everything_pass(self):
     """ when valid params are passed returns nil """
     val = validate_post_params(self.params)
     self.assertEqual(val, None)