Browse Source

Make stuff in the config not capitalized

Getty Ritter 4 years ago
parent
commit
217e0fbea9
8 changed files with 20 additions and 20 deletions
  1. 1 1
      lament-configuration.py
  2. 3 3
      lc/config.py
  3. 4 4
      lc/model.py
  4. 1 1
      lc/request.py
  5. 2 2
      lc/web.py
  6. 1 1
      scripts/populate.py
  7. 5 5
      tests/model.py
  8. 3 3
      tests/routes.py

+ 1 - 1
lament-configuration.py

@@ -4,5 +4,5 @@ from lc.app import app
 import lc.config
 import lc.model
 
-lc.config.DB.init(os.getenv("DB_LOC", "test.db"))
+lc.config.db.init(os.getenv("DB_LOC", "test.db"))
 lc.model.create_tables()

+ 3 - 3
lc/config.py

@@ -5,9 +5,9 @@ import flask
 import itsdangerous
 import playhouse.sqlite_ext
 
-DB = playhouse.sqlite_ext.SqliteExtDatabase(None)
-PER_PAGE = 50
-SERIALIZER = itsdangerous.URLSafeSerializer("TEMP KEY")
+db = playhouse.sqlite_ext.SqliteExtDatabase(None)
+per_page = 50
+serializer = itsdangerous.URLSafeSerializer("TEMP KEY")
 app = flask.Flask(__name__)
 app.secret_key = "ARGLBARGL"
 

+ 4 - 4
lc/model.py

@@ -12,7 +12,7 @@ import lc.request as r
 
 class Model(peewee.Model):
     class Meta:
-        database = c.DB
+        database = c.db
 
     def to_dict(self) -> dict:
         return playhouse.shortcuts.model_to_dict(self)
@@ -35,7 +35,7 @@ class Pagination:
 
     @classmethod
     def from_total(cls, current, total) -> "Pagination":
-        return cls(current=current, last=((total - 1) // c.PER_PAGE) + 1,)
+        return cls(current=current, last=((total - 1) // c.per_page) + 1,)
 
 
 # TODO: figure out authorization for users (oauth? passwd?)
@@ -85,7 +85,7 @@ class User(Model):
             Link.select()
             .where(Link.user == self)
             .order_by(-Link.created)
-            .paginate(page, c.PER_PAGE)
+            .paginate(page, c.per_page)
         )
         pagination = Pagination.from_total(page, Link.select().count())
         return links, pagination
@@ -155,7 +155,7 @@ class Tag(Model):
             .join(Link)
             .where((HasTag.tag == self))
             .order_by(-Link.created)
-            .paginate(page, c.PER_PAGE)
+            .paginate(page, c.per_page)
         ]
         pagination = Pagination.from_total(
             page, HasTag.select().where((HasTag.tag == self)).count(),

+ 1 - 1
lc/request.py

@@ -34,7 +34,7 @@ class User(Request):
         return cls(name=form["username"], password=form["password"],)
 
     def to_token(self) -> str:
-        return c.SERIALIZER.dumps({"name": self.name, "password": self.password,})
+        return c.serializer.dumps({"name": self.name, "password": self.password,})
 
 
 @dataclass_json

+ 2 - 2
lc/web.py

@@ -122,11 +122,11 @@ def endpoint(route: str):
         # use reflection over the methods defined by the endpoint
         # class to decide if it needs to accept POST requests or not.
         methods = ["GET"]
-        if "api_post" in dir(cls):
+        if "api_post" in dir(endpoint_class):
             methods.append("POST")
 
         # this is just for making error messages nicer
-        func.__name__ = cls.__name__
+        func.__name__ = endpoint_class.__name__
 
         # finally, use the Flask routing machinery to register our callback
         return c.app.route(route, methods=methods)(func)

+ 1 - 1
scripts/populate.py

@@ -9,7 +9,7 @@ import lc.request as r
 
 
 def main():
-    lc.config.DB.init("test.db")
+    lc.config.db.init("test.db")
     m.create_tables()
 
     u = m.User.get_or_none(name="gdritter")

+ 5 - 5
tests/model.py

@@ -7,13 +7,13 @@ import lc.request as r
 import lc.model as m
 
 
-class TestDB:
+class Testdb:
     def setup_method(self, _):
-        c.DB.init(":memory:")
-        c.DB.create_tables(m.MODELS)
+        c.db.init(":memory:")
+        c.db.create_tables(m.MODELS)
 
     def teardown_method(self, _):
-        c.DB.close()
+        c.db.close()
 
     def mk_user(self, name="gdritter", password="foo") -> m.User:
         return m.User.from_request(r.User(name=name, password=password,))
@@ -67,7 +67,7 @@ class TestDB:
         u = self.mk_user()
         t = m.Tag.get_or_create_tag(u, "food/bread/rye")
 
-        # this should have created three DB rows: for 'food', for
+        # this should have created three db rows: for 'food', for
         # 'food/bread', and for 'food/bread/rye':
         assert len(m.Tag.select()) == 3
 

+ 3 - 3
tests/routes.py

@@ -5,12 +5,12 @@ import lc.app as a
 
 class TestRoutes:
     def setup_method(self, _):
-        c.DB.init(":memory:")
-        c.DB.create_tables(m.MODELS)
+        c.db.init(":memory:")
+        c.db.create_tables(m.MODELS)
         self.app = a.app.test_client()
 
     def teardown_method(self, _):
-        c.DB.close()
+        c.db.close()
 
     def get(self, path):
         return self.app.get(path)