Backend lint check (#451)
- apply lint + format fixes to backend - add ci for lint + format fixes for backend - use fixed version of pydantic
This commit is contained in:
		
							parent
							
								
									30bda8c75d
								
							
						
					
					
						commit
						56a6d7a5d8
					
				
							
								
								
									
										28
									
								
								.github/workflows/lint.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							
							
						
						
									
										28
									
								
								.github/workflows/lint.yaml
									
									
									
									
										vendored
									
									
										Normal file
									
								
							| @ -0,0 +1,28 @@ | |||||||
|  | name: Lint Check | ||||||
|  | on: [push, pull_request] | ||||||
|  | jobs: | ||||||
|  |   unit-tests: | ||||||
|  |     runs-on: ubuntu-latest | ||||||
|  |     steps: | ||||||
|  |       - name: checkout | ||||||
|  |         uses: actions/checkout@v2 | ||||||
|  |          | ||||||
|  |       - name: Set up Python | ||||||
|  |         uses: actions/setup-python@v1 | ||||||
|  |         with: | ||||||
|  |           python-version: "3.10" | ||||||
|  | 
 | ||||||
|  |       - name: Install dependencies | ||||||
|  |         run: | | ||||||
|  |           cd backend/ | ||||||
|  |           python -m pip install --upgrade pip | ||||||
|  |           pip install -r requirements.txt | ||||||
|  |           pip install -U black pylint | ||||||
|  | 
 | ||||||
|  |       - name: Style Check | ||||||
|  |         run: | | ||||||
|  |           black --check backend/btrixcloud/ | ||||||
|  | 
 | ||||||
|  |       - name: Lint Check | ||||||
|  |         run: | | ||||||
|  |           pylint backend/btrixcloud/ | ||||||
| @ -12,8 +12,12 @@ from .db import BaseMongoModel | |||||||
| 
 | 
 | ||||||
| from .users import User | from .users import User | ||||||
| 
 | 
 | ||||||
| from .invites import AddToArchiveRequest, InvitePending, InviteToArchiveRequest, UserRole | from .invites import ( | ||||||
| 
 |     AddToArchiveRequest, | ||||||
|  |     InvitePending, | ||||||
|  |     InviteToArchiveRequest, | ||||||
|  |     UserRole, | ||||||
|  | ) | ||||||
| 
 | 
 | ||||||
| # crawl scale for constraint | # crawl scale for constraint | ||||||
| MAX_CRAWL_SCALE = 3 | MAX_CRAWL_SCALE = 3 | ||||||
| @ -223,6 +227,8 @@ class ArchiveOps: | |||||||
| # ============================================================================ | # ============================================================================ | ||||||
| def init_archives_api(app, mdb, user_manager, invites, user_dep: User): | def init_archives_api(app, mdb, user_manager, invites, user_dep: User): | ||||||
|     """Init archives api router for /archives""" |     """Init archives api router for /archives""" | ||||||
|  |     # pylint: disable=too-many-locals | ||||||
|  | 
 | ||||||
|     ops = ArchiveOps(mdb, invites) |     ops = ArchiveOps(mdb, invites) | ||||||
| 
 | 
 | ||||||
|     async def archive_dep(aid: str, user: User = Depends(user_dep)): |     async def archive_dep(aid: str, user: User = Depends(user_dep)): | ||||||
| @ -336,7 +342,6 @@ def init_archives_api(app, mdb, user_manager, invites, user_dep: User): | |||||||
|     @router.post("/add-user", tags=["invites"]) |     @router.post("/add-user", tags=["invites"]) | ||||||
|     async def add_new_user_to_archive( |     async def add_new_user_to_archive( | ||||||
|         invite: AddToArchiveRequest, |         invite: AddToArchiveRequest, | ||||||
|         request: Request, |  | ||||||
|         archive: Archive = Depends(archive_owner_dep), |         archive: Archive = Depends(archive_owner_dep), | ||||||
|         user: User = Depends(user_dep), |         user: User = Depends(user_dep), | ||||||
|     ): |     ): | ||||||
|  | |||||||
| @ -183,6 +183,7 @@ class UserManager(BaseUserManager[UserCreate, UserDB]): | |||||||
|     async def create_non_super_user( |     async def create_non_super_user( | ||||||
|         self, email: str, password: str, name: str = "New user" |         self, email: str, password: str, name: str = "New user" | ||||||
|     ): |     ): | ||||||
|  |         """create a regular user with given credentials""" | ||||||
|         if not email: |         if not email: | ||||||
|             print("No user defined", flush=True) |             print("No user defined", flush=True) | ||||||
|             return |             return | ||||||
| @ -206,7 +207,6 @@ class UserManager(BaseUserManager[UserCreate, UserDB]): | |||||||
|         except (DuplicateKeyError, UserAlreadyExists): |         except (DuplicateKeyError, UserAlreadyExists): | ||||||
|             print(f"User {email} already exists", flush=True) |             print(f"User {email} already exists", flush=True) | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|     async def on_after_register_custom( |     async def on_after_register_custom( | ||||||
|         self, user: UserDB, user_create: UserCreate, request: Optional[Request] |         self, user: UserDB, user_create: UserCreate, request: Optional[Request] | ||||||
|     ): |     ): | ||||||
|  | |||||||
| @ -3,6 +3,7 @@ fastapi==0.71.0 | |||||||
| fastapi-users[mongodb]==9.2.2 | fastapi-users[mongodb]==9.2.2 | ||||||
| loguru | loguru | ||||||
| aiofiles | aiofiles | ||||||
|  | pydantic==1.8.2 | ||||||
| kubernetes-asyncio==22.6.5 | kubernetes-asyncio==22.6.5 | ||||||
| aiobotocore | aiobotocore | ||||||
| redis>=4.2.0rc1 | redis>=4.2.0rc1 | ||||||
|  | |||||||
| @ -11,6 +11,7 @@ ADMIN_PW = "PASSW0RD!" | |||||||
| VIEWER_USERNAME = "viewer@example.com" | VIEWER_USERNAME = "viewer@example.com" | ||||||
| VIEWER_PW = "viewerPASSW0RD!" | VIEWER_PW = "viewerPASSW0RD!" | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| @pytest.fixture(scope="session") | @pytest.fixture(scope="session") | ||||||
| def admin_auth_headers(): | def admin_auth_headers(): | ||||||
|     r = requests.post( |     r = requests.post( | ||||||
| @ -25,12 +26,14 @@ def admin_auth_headers(): | |||||||
|     access_token = data.get("access_token") |     access_token = data.get("access_token") | ||||||
|     return {"Authorization": f"Bearer {access_token}"} |     return {"Authorization": f"Bearer {access_token}"} | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| @pytest.fixture(scope="session") | @pytest.fixture(scope="session") | ||||||
| def admin_aid(admin_auth_headers): | def admin_aid(admin_auth_headers): | ||||||
|     r = requests.get(f"{API_PREFIX}/archives", headers=admin_auth_headers) |     r = requests.get(f"{API_PREFIX}/archives", headers=admin_auth_headers) | ||||||
|     data = r.json() |     data = r.json() | ||||||
|     return data["archives"][0]["id"] |     return data["archives"][0]["id"] | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| @pytest.fixture(scope="session") | @pytest.fixture(scope="session") | ||||||
| def admin_crawl_id(admin_auth_headers, admin_aid): | def admin_crawl_id(admin_auth_headers, admin_aid): | ||||||
|     # Start crawl. |     # Start crawl. | ||||||
| @ -57,6 +60,7 @@ def admin_crawl_id(admin_auth_headers, admin_aid): | |||||||
|             return crawl_id |             return crawl_id | ||||||
|         time.sleep(5) |         time.sleep(5) | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| @pytest.fixture(scope="session") | @pytest.fixture(scope="session") | ||||||
| def viewer_auth_headers(admin_auth_headers, admin_aid): | def viewer_auth_headers(admin_auth_headers, admin_aid): | ||||||
|     requests.post( |     requests.post( | ||||||
|  | |||||||
| @ -7,7 +7,11 @@ def test_login_invalid(): | |||||||
|     password = "invalid" |     password = "invalid" | ||||||
|     r = requests.post( |     r = requests.post( | ||||||
|         f"{API_PREFIX}/auth/jwt/login", |         f"{API_PREFIX}/auth/jwt/login", | ||||||
|         data={"username": ADMIN_USERNAME, "password": password, "grant_type": "password"}, |         data={ | ||||||
|  |             "username": ADMIN_USERNAME, | ||||||
|  |             "password": password, | ||||||
|  |             "grant_type": "password", | ||||||
|  |         }, | ||||||
|     ) |     ) | ||||||
|     data = r.json() |     data = r.json() | ||||||
| 
 | 
 | ||||||
| @ -18,7 +22,11 @@ def test_login_invalid(): | |||||||
| def test_login(): | def test_login(): | ||||||
|     r = requests.post( |     r = requests.post( | ||||||
|         f"{API_PREFIX}/auth/jwt/login", |         f"{API_PREFIX}/auth/jwt/login", | ||||||
|         data={"username": ADMIN_USERNAME, "password": ADMIN_PW, "grant_type": "password"}, |         data={ | ||||||
|  |             "username": ADMIN_USERNAME, | ||||||
|  |             "password": ADMIN_PW, | ||||||
|  |             "grant_type": "password", | ||||||
|  |         }, | ||||||
|     ) |     ) | ||||||
|     data = r.json() |     data = r.json() | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -5,8 +5,7 @@ from .conftest import API_PREFIX | |||||||
| 
 | 
 | ||||||
| def test_admin_get_archive_crawls(admin_auth_headers, admin_aid, admin_crawl_id): | def test_admin_get_archive_crawls(admin_auth_headers, admin_aid, admin_crawl_id): | ||||||
|     r = requests.get( |     r = requests.get( | ||||||
|         f"{API_PREFIX}/archives/{admin_aid}/crawls", |         f"{API_PREFIX}/archives/{admin_aid}/crawls", headers=admin_auth_headers | ||||||
|         headers=admin_auth_headers |  | ||||||
|     ) |     ) | ||||||
|     data = r.json() |     data = r.json() | ||||||
|     assert len(data["crawls"]) > 0 |     assert len(data["crawls"]) > 0 | ||||||
| @ -16,8 +15,7 @@ def test_admin_get_archive_crawls(admin_auth_headers, admin_aid, admin_crawl_id) | |||||||
| 
 | 
 | ||||||
| def test_viewer_get_archive_crawls(viewer_auth_headers, admin_aid, admin_crawl_id): | def test_viewer_get_archive_crawls(viewer_auth_headers, admin_aid, admin_crawl_id): | ||||||
|     r = requests.get( |     r = requests.get( | ||||||
|         f"{API_PREFIX}/archives/{admin_aid}/crawls", |         f"{API_PREFIX}/archives/{admin_aid}/crawls", headers=viewer_auth_headers | ||||||
|         headers=viewer_auth_headers |  | ||||||
|     ) |     ) | ||||||
|     data = r.json() |     data = r.json() | ||||||
|     crawls = data["crawls"] |     crawls = data["crawls"] | ||||||
| @ -31,7 +29,7 @@ def test_viewer_get_archive_crawls(viewer_auth_headers, admin_aid, admin_crawl_i | |||||||
| def test_viewer_get_crawl(viewer_auth_headers, admin_aid, admin_crawl_id): | def test_viewer_get_crawl(viewer_auth_headers, admin_aid, admin_crawl_id): | ||||||
|     r = requests.get( |     r = requests.get( | ||||||
|         f"{API_PREFIX}/archives/{admin_aid}/crawls/{admin_crawl_id}", |         f"{API_PREFIX}/archives/{admin_aid}/crawls/{admin_crawl_id}", | ||||||
|         headers=viewer_auth_headers |         headers=viewer_auth_headers, | ||||||
|     ) |     ) | ||||||
|     data = r.json() |     data = r.json() | ||||||
|     assert data["id"] == admin_crawl_id |     assert data["id"] == admin_crawl_id | ||||||
| @ -41,7 +39,7 @@ def test_viewer_get_crawl(viewer_auth_headers, admin_aid, admin_crawl_id): | |||||||
| def test_viewer_get_crawl_replay(viewer_auth_headers, admin_aid, admin_crawl_id): | def test_viewer_get_crawl_replay(viewer_auth_headers, admin_aid, admin_crawl_id): | ||||||
|     r = requests.get( |     r = requests.get( | ||||||
|         f"{API_PREFIX}/archives/{admin_aid}/crawls/{admin_crawl_id}/replay.json", |         f"{API_PREFIX}/archives/{admin_aid}/crawls/{admin_crawl_id}/replay.json", | ||||||
|         headers=viewer_auth_headers |         headers=viewer_auth_headers, | ||||||
|     ) |     ) | ||||||
|     data = r.json() |     data = r.json() | ||||||
|     assert data["id"] == admin_crawl_id |     assert data["id"] == admin_crawl_id | ||||||
|  | |||||||
| @ -80,6 +80,7 @@ def test_wait_for_complete(admin_auth_headers, admin_aid, admin_crawl_id): | |||||||
|     wacz_size = data["resources"][0]["size"] |     wacz_size = data["resources"][0]["size"] | ||||||
|     wacz_hash = data["resources"][0]["hash"] |     wacz_hash = data["resources"][0]["hash"] | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_crawl_info(admin_auth_headers, admin_aid, admin_crawl_id): | def test_crawl_info(admin_auth_headers, admin_aid, admin_crawl_id): | ||||||
|     r = requests.get( |     r = requests.get( | ||||||
|         f"{API_PREFIX}/archives/{admin_aid}/crawls/{admin_crawl_id}", |         f"{API_PREFIX}/archives/{admin_aid}/crawls/{admin_crawl_id}", | ||||||
| @ -88,6 +89,7 @@ def test_crawl_info(admin_auth_headers, admin_aid, admin_crawl_id): | |||||||
|     data = r.json() |     data = r.json() | ||||||
|     assert data["fileSize"] == wacz_size |     assert data["fileSize"] == wacz_size | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_download_wacz(): | def test_download_wacz(): | ||||||
|     r = requests.get(host_prefix + wacz_path) |     r = requests.get(host_prefix + wacz_path) | ||||||
|     assert r.status_code == 200 |     assert r.status_code == 200 | ||||||
|  | |||||||
| @ -10,6 +10,7 @@ def test_create_super_user(admin_auth_headers): | |||||||
|     assert token != "None" |     assert token != "None" | ||||||
|     assert len(token) > 4 |     assert len(token) > 4 | ||||||
| 
 | 
 | ||||||
|  | 
 | ||||||
| def test_create_non_super_user(viewer_auth_headers): | def test_create_non_super_user(viewer_auth_headers): | ||||||
|     assert viewer_auth_headers |     assert viewer_auth_headers | ||||||
|     auth = viewer_auth_headers["Authorization"] |     auth = viewer_auth_headers["Authorization"] | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user