File size: 1,470 Bytes
f42ec01
35c0239
5760b44
 
35c0239
 
 
 
f42ec01
35c0239
 
 
 
f42ec01
5760b44
 
35c0239
 
5760b44
 
 
 
 
35c0239
 
 
5760b44
b1106e6
35c0239
 
5760b44
f42ec01
5760b44
 
 
 
35c0239
 
b1106e6
5760b44
35c0239
 
 
 
f42ec01
a5fed35
 
 
 
 
 
 
f42ec01
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
from fastapi.testclient import TestClient
import pytest

from app import app


@pytest.fixture()
def client():
    yield TestClient(app)


def test_fix_commas_fails_on_no_parameter(client):
    response = client.post('/baseline/fix-commas/')
    assert response.status_code == 422


def test_fix_commas_fails_on_wrong_parameters(client):
    response = client.post('/baseline/fix-commas/', json={'text': "Some text."})
    assert response.status_code == 400


@pytest.mark.parametrize(
    "test_input",
    ['',
     'Hello world.',
     'This test string should not have any commas inside it.']
)
def test_fix_commas_correct_string_unchanged(client, test_input: str):
    response = client.post('/baseline/fix-commas/', json={'s': test_input})

    assert response.status_code == 200
    assert response.json().get('s') == test_input


@pytest.mark.parametrize(
    "test_input, expected",
    [['I am, here.', 'I am here.'],
     ['books pens and pencils',
      'books, pens and pencils']]
)
def test_fix_commas_fixes_wrong_commas(client, test_input: str, expected: str):
    response = client.post('/baseline/fix-commas/', json={'s': test_input})

    assert response.status_code == 200
    assert response.json().get('s') == expected


def test_with_a_very_long_string(client):
    s = "Just a long string. " * 1000
    response = client.post('/baseline/fix-commas/', json={'s': s})

    assert response.status_code == 200
    assert response.json().get('s') == s