<commit_before>from nougat import Nougat
from nougat.routing import Routing, get, post, put, patch ,delete
from nougat.test_client import TestClient
from aiohttp import FormData


class TestBasicApplication:

    def test_get(self, app):

        class Basic(Routing):

            @get('/')
            async def index(self):
                return 'hello world'

        app.route(Basic)

        res = TestClient(app).get('/')
        assert res.text == 'hello world'

    def test_post(self, app):

        class Basic(Routing):
            @post('/')
            async def index(self):
                return 'post method'

        app.route(Basic)

        res = TestClient(app).post('/')
        assert res.text == 'post method'

    def test_put(self, app):

        class Basic(Routing):
            @put('/')
            async def index(self):
                return 'put method'

        app.route(Basic)

        res = TestClient(app).put('/')
        assert res.text == 'put method'

    def test_patch(self, app):

        class Basic(Routing):
            @patch('/')
            async def index(self):
                return 'patch method'

        app.route(Basic)

        res = TestClient(app).patch('/')
        assert res.text == 'patch method'

    def test_delete(self, app):

        class Basic(Routing):
            @delete('/')
            async def index(self):
                return 'delete method'

        app.route(Basic)

        res = TestClient(app).delete('/')
        assert res.text == 'delete method'


class TestRouter:

    def test_static(self, app):

        class MainRouting(Routing):

            @get('/static')
            async def static_route(self):
                return 'static route'

        app.route(MainRouting)

        res = TestClient(app).get('/static')
        assert res.text == 'static route'

        res = TestClient(app).get('/')
        assert res.text == 'Not Found'

    def test_simple_type(self, app):

        class MainRouting(Routing):

            @get('/article/:id')
            async def article_simple(self):
                return 'id: {}'.format(self.request.url_dict.get('id'))

        app.route(MainRouting)

        res = TestClient(app).get('/article/')
        assert res.text == 'Not Found'

        res = TestClient(app).get('/article/123')
        assert res.text == 'id: 123'

        res = TestClient(app).get('/article/word')
        assert res.text == 'id: word'

        res = TestClient(app).get('/article/path/123')
        assert res.text == 'Not Found'

    def test_unnamed_regex(self, app):

        class MainRouting(Routing):
            @get('/article/[0-9]+')
            async def article_simple(self):
                return 'hit'

        app.route(MainRouting)

        res = TestClient(app).get('/article/')
        assert res.text == 'Not Found'

        res = TestClient(app).get('/article/123')
        assert res.text == 'hit'

        res = TestClient(app).get('/article/word')
        assert res.text == 'Not Found'

        res = TestClient(app).get('/article/path/123')
        assert res.text == 'Not Found'

    def test_named_regex(self, app):

        class MainRouting(Routing):
            @get('/article/:id<[0-9]+>')
            async def article_simple(self):
                return self.request.url_dict.get('id', 'None')

        app.route(MainRouting)

        res = TestClient(app).get('/article/')
        assert res.text == 'Not Found'

        res = TestClient(app).get('/article/123')
        assert res.text == '123'

        res = TestClient(app).get('/article/word')
        assert res.text == 'Not Found'

        res = TestClient(app).get('/article/path/123')
        assert res.text == 'Not Found'

    def test_form_data_with_multipart(self, app):

        class MainRouting(Routing):

            @post('/')
            async def multipart(self):
                name = self.request.form.get('file')
                return name.name

        app.route(MainRouting)

        data = FormData()
        data.add_field('name', 'foo')
        data.add_field('file', 'file content',
                       filename='avatar.webp',
                       content_type='image/webp')

        res = TestClient(app).post('/', data=data)
        assert res.text == 'avatar.webp'


class TestMiddleware:
<commit_msg>style: rename the filename of test case<commit_after>from nougat import Nougat
from nougat.routing import Routing, get, post, put, patch ,delete
from nougat.test_client import TestClient
from aiohttp import FormData


class TestBasicApplication:

    def test_get(self, app):

        class Basic(Routing):

            @get('/')
            async def index(self):
                return 'hello world'

        app.route(Basic)

        res = TestClient(app).get('/')
        assert res.text == 'hello world'

    def test_post(self, app):

        class Basic(Routing):
            @post('/')
            async def index(self):
                return 'post method'

        app.route(Basic)

        res = TestClient(app).post('/')
        assert res.text == 'post method'

    def test_put(self, app):

        class Basic(Routing):
            @put('/')
            async def index(self):
                return 'put method'

        app.route(Basic)

        res = TestClient(app).put('/')
        assert res.text == 'put method'

    def test_patch(self, app):

        class Basic(Routing):
            @patch('/')
            async def index(self):
                return 'patch method'

        app.route(Basic)

        res = TestClient(app).patch('/')
        assert res.text == 'patch method'

    def test_delete(self, app):

        class Basic(Routing):
            @delete('/')
            async def index(self):
                return 'delete method'

        app.route(Basic)

        res = TestClient(app).delete('/')
        assert res.text == 'delete method'


class TestRouter:

    def test_static(self, app):

        class MainRouting(Routing):

            @get('/static')
            async def static_route(self):
                return 'static route'

        app.route(MainRouting)

        res = TestClient(app).get('/static')
        assert res.text == 'static route'

        res = TestClient(app).get('/')
        assert res.text == 'Not Found'

    def test_simple_type(self, app):

        class MainRouting(Routing):

            @get('/article/:id')
            async def article_simple(self):
                return 'id: {}'.format(self.request.url_dict.get('id'))

        app.route(MainRouting)

        res = TestClient(app).get('/article/')
        assert res.text == 'Not Found'

        res = TestClient(app).get('/article/123')
        assert res.text == 'id: 123'

        res = TestClient(app).get('/article/word')
        assert res.text == 'id: word'

        res = TestClient(app).get('/article/path/123')
        assert res.text == 'Not Found'

    def test_unnamed_regex(self, app):

        class MainRouting(Routing):
            @get('/article/[0-9]+')
            async def article_simple(self):
                return 'hit'

        app.route(MainRouting)

        res = TestClient(app).get('/article/')
        assert res.text == 'Not Found'

        res = TestClient(app).get('/article/123')
        assert res.text == 'hit'

        res = TestClient(app).get('/article/word')
        assert res.text == 'Not Found'

        res = TestClient(app).get('/article/path/123')
        assert res.text == 'Not Found'

    def test_named_regex(self, app):

        class MainRouting(Routing):
            @get('/article/:id<[0-9]+>')
            async def article_simple(self):
                return self.request.url_dict.get('id', 'None')

        app.route(MainRouting)

        res = TestClient(app).get('/article/')
        assert res.text == 'Not Found'

        res = TestClient(app).get('/article/123')
        assert res.text == '123'

        res = TestClient(app).get('/article/word')
        assert res.text == 'Not Found'

        res = TestClient(app).get('/article/path/123')
        assert res.text == 'Not Found'

    def test_form_data_with_multipart(self, app):

        class MainRouting(Routing):

            @post('/')
            async def multipart(self):
                name = self.request.form.get('file')
                return name.name

        app.route(MainRouting)

        data = FormData()
        data.add_field('name', 'foo')
        data.add_field('file', 'file content',
                       filename='file.file',
                       content_type='image/img')

        res = TestClient(app).post('/', data=data)
        assert res.text == 'file.file'


class TestMiddleware:

{'fraction_non_alphanumeric': 0.1365669074647403, 'fraction_numerical': 0.006421281963077629, 'mean_word_length': 1.8794981842192142, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1631439', 'n_tokens_mistral': 2580, 'n_tokens_neox': 2448, 'n_words': 574}