from tests.data import add_fixtures, clubs


def test_list_all(db_session, client):
    sfn = clubs.sfn()
    lva = clubs.lva()
    add_fixtures(db_session, sfn, lva)

    res = client.get("/clubs")
    assert res.status_code == 200
    assert res.json == {
        "clubs": [
            {"id": lva.id, "name": "LV Aachen"},
            {"id": sfn.id, "name": "Sportflug Niederberg"},
        ]
    }


def test_name_filter(db_session, client):
    sfn = clubs.sfn()
    lva = clubs.lva()
    add_fixtures(db_session, sfn, lva)

    res = client.get("/clubs?name=LV%20Aachen")
    assert res.status_code == 200
    assert res.json == {"clubs": [{"id": lva.id, "name": "LV Aachen"}]}


def test_name_filter_with_unknown_club(db_session, client):
    res = client.get("/clubs?name=Unknown")
    assert res.status_code == 200
    assert res.json == {"clubs": []}

from pytest_voluptuous import S
from voluptuous.validators import ExactSequence

from tests.data import add_fixtures, clubs


def test_list_all(db_session, client):
    add_fixtures(db_session, clubs.sfn(), clubs.lva())

    res = client.get("/clubs")
    assert res.status_code == 200
    assert res.json == S(
        {
            "clubs": ExactSequence(
                [
                    {"id": int, "name": "LV Aachen"},
                    {"id": int, "name": "Sportflug Niederberg"},
                ]
            )
        }
    )


def test_name_filter(db_session, client):
    add_fixtures(db_session, clubs.sfn(), clubs.lva())

    res = client.get("/clubs?name=LV%20Aachen")
    assert res.status_code == 200
    assert res.json == S({"clubs": ExactSequence([{"id": int, "name": "LV Aachen"}])})


def test_name_filter_with_unknown_club(db_session, client):
    res = client.get("/clubs?name=Unknown")
    assert res.status_code == 200
    assert res.json == S({"clubs": ExactSequence([])})

Use `pytest-voluptuous` to simplify JSON compare code
api/clubs/list/test: Use `pytest-voluptuous` to simplify JSON compare code

+ from pytest_voluptuous import S
+ from voluptuous.validators import ExactSequence
+ 
  from tests.data import add_fixtures, clubs
  
  
  def test_list_all(db_session, client):
-     sfn = clubs.sfn()
-     lva = clubs.lva()
-     add_fixtures(db_session, sfn, lva)
+     add_fixtures(db_session, clubs.sfn(), clubs.lva())
  
      res = client.get("/clubs")
      assert res.status_code == 200
-     assert res.json == {
+     assert res.json == S(
-         "clubs": [
-             {"id": lva.id, "name": "LV Aachen"},
-             {"id": sfn.id, "name": "Sportflug Niederberg"},
-         ]
+         {
+             "clubs": ExactSequence(
+                 [
+                     {"id": int, "name": "LV Aachen"},
+                     {"id": int, "name": "Sportflug Niederberg"},
+                 ]
+             )
+         }
-     }
+     )
  
  
  def test_name_filter(db_session, client):
-     sfn = clubs.sfn()
-     lva = clubs.lva()
-     add_fixtures(db_session, sfn, lva)
+     add_fixtures(db_session, clubs.sfn(), clubs.lva())
  
      res = client.get("/clubs?name=LV%20Aachen")
      assert res.status_code == 200
-     assert res.json == {"clubs": [{"id": lva.id, "name": "LV Aachen"}]}
+     assert res.json == S({"clubs": ExactSequence([{"id": int, "name": "LV Aachen"}])})
  
  
  def test_name_filter_with_unknown_club(db_session, client):
      res = client.get("/clubs?name=Unknown")
      assert res.status_code == 200
-     assert res.json == {"clubs": []}
+     assert res.json == S({"clubs": ExactSequence([])})
  
Use `pytest-voluptuous` to simplify JSON compare code
## Code Before:
from tests.data import add_fixtures, clubs


def test_list_all(db_session, client):
    sfn = clubs.sfn()
    lva = clubs.lva()
    add_fixtures(db_session, sfn, lva)

    res = client.get("/clubs")
    assert res.status_code == 200
    assert res.json == {
        "clubs": [
            {"id": lva.id, "name": "LV Aachen"},
            {"id": sfn.id, "name": "Sportflug Niederberg"},
        ]
    }


def test_name_filter(db_session, client):
    sfn = clubs.sfn()
    lva = clubs.lva()
    add_fixtures(db_session, sfn, lva)

    res = client.get("/clubs?name=LV%20Aachen")
    assert res.status_code == 200
    assert res.json == {"clubs": [{"id": lva.id, "name": "LV Aachen"}]}


def test_name_filter_with_unknown_club(db_session, client):
    res = client.get("/clubs?name=Unknown")
    assert res.status_code == 200
    assert res.json == {"clubs": []}

## Instruction:
Use `pytest-voluptuous` to simplify JSON compare code
## Code After:
from pytest_voluptuous import S
from voluptuous.validators import ExactSequence

from tests.data import add_fixtures, clubs


def test_list_all(db_session, client):
    add_fixtures(db_session, clubs.sfn(), clubs.lva())

    res = client.get("/clubs")
    assert res.status_code == 200
    assert res.json == S(
        {
            "clubs": ExactSequence(
                [
                    {"id": int, "name": "LV Aachen"},
                    {"id": int, "name": "Sportflug Niederberg"},
                ]
            )
        }
    )


def test_name_filter(db_session, client):
    add_fixtures(db_session, clubs.sfn(), clubs.lva())

    res = client.get("/clubs?name=LV%20Aachen")
    assert res.status_code == 200
    assert res.json == S({"clubs": ExactSequence([{"id": int, "name": "LV Aachen"}])})


def test_name_filter_with_unknown_club(db_session, client):
    res = client.get("/clubs?name=Unknown")
    assert res.status_code == 200
    assert res.json == S({"clubs": ExactSequence([])})
