add authenticated User LangPreference tracking

+ Use User.LangPreference when there is no set AURSID
  if request.user.is_authenticated is true.
+ Updated post /language to update LangPreference when
  request.user.is_authenticated.
+ Restore language during test where we change it.
+ Added the user attribute to aurweb.testing.requests.Request.

Signed-off-by: Kevin Morris <kevr@0cost.org>
This commit is contained in:
Kevin Morris 2021-01-08 20:10:45 -08:00
parent a33d076d8b
commit 9fdbe3f775
5 changed files with 59 additions and 14 deletions

View file

@ -1,8 +1,27 @@
import aurweb.config
class User:
""" A fake User model. """
# Fake columns.
LangPreference = aurweb.config.get("options", "default_lang")
# A fake authenticated flag.
authenticated = False
def is_authenticated(self):
return self.authenticated
class Client:
""" A fake FastAPI Request.client object. """
# A fake host.
host = "127.0.0.1"
class Request:
""" A fake Request object which mimics a FastAPI Request for tests. """
client = Client()
cookies = dict()
headers = dict()
user = User()