Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(RUF012) Fixed mutable class Defaults- Task 2 #10286

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
16 changes: 9 additions & 7 deletions openlibrary/tests/core/test_db.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import ClassVar

import web

from openlibrary.core.booknotes import Booknotes
Expand Down Expand Up @@ -156,7 +158,7 @@ def test_no_allow_delete_on_conflict(self):


class TestUsernameUpdate:
READING_LOG_SETUP_ROWS = [
READING_LOG_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [
{
"username": "@kilgore_trout",
"work_id": 1,
Expand All @@ -176,15 +178,15 @@ class TestUsernameUpdate:
"bookshelf_id": 2,
},
]
BOOKNOTES_SETUP_ROWS = [
BOOKNOTES_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [
{"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "notes": "Hello"},
{"username": "@billy_pilgrim", "work_id": 1, "edition_id": 1, "notes": "World"},
]
RATINGS_SETUP_ROWS = [
RATINGS_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [
{"username": "@kilgore_trout", "work_id": 1, "edition_id": 1, "rating": 4},
{"username": "@billy_pilgrim", "work_id": 5, "edition_id": 1, "rating": 2},
]
OBSERVATIONS_SETUP_ROWS = [
OBSERVATIONS_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [
{
"username": "@kilgore_trout",
"work_id": 1,
Expand All @@ -201,7 +203,7 @@ class TestUsernameUpdate:
},
]

EDITS_QUEUE_SETUP_ROWS = [
EDITS_QUEUE_SETUP_ROWS: ClassVar[list[dict[str, str | int | None]]] = [
{
"title": "One Fish, Two Fish, Red Fish, Blue Fish",
"submitter": "@kilgore_trout",
Expand Down Expand Up @@ -308,7 +310,7 @@ def test_update_username(self):


class TestCheckIns:
BOOKSHELVES_EVENTS_SETUP_ROWS = [
BOOKSHELVES_EVENTS_SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [
{
"id": 1,
"username": "@kilgore_trout",
Expand Down Expand Up @@ -481,7 +483,7 @@ def test_get_latest_event_date(self):


class TestYearlyReadingGoals:
SETUP_ROWS = [
SETUP_ROWS: ClassVar[list[dict[str, str | int]]] = [
{
'username': '@billy_pilgrim',
'year': 2022,
Expand Down
14 changes: 8 additions & 6 deletions openlibrary/utils/schema.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import ClassVar

"""utility to generate db schema for any database engine.
(should go to web.py)
"""
Expand Down Expand Up @@ -94,7 +96,7 @@ def quote(self, value):


class MySQLAdapter(AbstractAdapter):
native_types = {
native_types: ClassVar[dict[str, str]] = {
'serial': 'int auto_increment not null',
'integer': 'int',
'float': 'float',
Expand All @@ -107,7 +109,7 @@ class MySQLAdapter(AbstractAdapter):
'binary': 'blob',
'boolean': 'boolean',
}
constants = {
constants: ClassVar[dict[str, str]] = {
'CURRENT_TIMESTAMP': 'CURRENT_TIMESTAMP',
'CURRENT_DATE': 'CURRENT_DATE',
'CURRENT_TIME': 'CURRENT_TIME',
Expand All @@ -121,7 +123,7 @@ def references_to_sql(self, column_name, value):


class PostgresAdapter(AbstractAdapter):
native_types = {
native_types: ClassVar[dict[str, str]] = {
'serial': 'serial',
'integer': 'int',
'float': 'float',
Expand All @@ -134,7 +136,7 @@ class PostgresAdapter(AbstractAdapter):
'binary': 'bytea',
'boolean': 'boolean',
}
constants = {
constants: ClassVar[dict[str, str]] = {
'CURRENT_TIMESTAMP': 'current_timestamp',
'CURRENT_DATE': 'current_date',
'CURRENT_TIME': 'current_time',
Expand All @@ -148,7 +150,7 @@ def references_to_sql(self, column_name, value):


class SQLiteAdapter(AbstractAdapter):
native_types = {
native_types: ClassVar[dict[str, str]] = {
'serial': 'integer autoincrement',
'integer': 'integer',
'float': 'float',
Expand All @@ -161,7 +163,7 @@ class SQLiteAdapter(AbstractAdapter):
'binary': 'blob',
'boolean': 'boolean',
}
constants = {
constants: ClassVar[dict[str, str]] = {
'CURRENT_TIMESTAMP': "CURRENT_TIMESTAMP",
'CURRENT_DATE': "CURRENT_DATE",
'CURRENT_TIME': "CURRENT_TIME",
Expand Down
Loading