Coverage for app/models.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.8.0, created at 2025-04-20 21:23 +0000

1from werkzeug.security import generate_password_hash, check_password_hash 

2from flask_login import UserMixin 

3from app import db 

4 

5""" 

6File where we will store all database models which get turned into database tables 

7 

8""" 

9 

10 

11# File where we will store all database models which get turned into database tables 

12 

13 

14class User(UserMixin,db.Model): 

15 # base user table 

16 # column id: Integer, and primary key of this table 

17 id = db.Column(db.Integer, primary_key=True) 

18 # column username, a string max length 64, index and each must be unique 

19 username = db.Column(db.String(64), index=True, unique=True) 

20 # column password hash, string unknown length 

21 password_hash = db.Column(db.String()) 

22 

23 # methods that operate on the User class 

24 # set password which takes a string and creates its hash and stores it in the database for that user 

25 def set_password(self, password): 

26 self.password_hash = generate_password_hash(password) 

27 

28 # check password to check if a hash matches with an inputes password 

29 def check_password(self, password): 

30 return check_password_hash(self.password_hash, password) 

31 

32class Document(db.Model): 

33 # table for documents 

34 # id: Integer, and is the primary key of the table 

35 id = db.Column(db.Integer, primary_key=True) 

36 # column document_name, string length unkown, and every document should have a name 

37 document_name = db.Column(db.String(), nullable=False) 

38 # column document_type, string length unkown, and every document has an extension 

39 document_type = db.Column(db.String(), nullable=False) 

40 # column file_contents, string length unkown, and every document shoould have binary data attached to it 

41 file_contents = db.Column(db.LargeBinary, nullable=False)