Skip to content
This repository was archived by the owner on Apr 29, 2025. It is now read-only.

Commit fb3bfdd

Browse files
Merge pull request #55 from DigitalProductInnovationAndDevelopment/test/llm
add test for api and llm
2 parents 1c69ac9 + 253ecbe commit fb3bfdd

21 files changed

Lines changed: 685 additions & 147 deletions

.github/workflows/license-compliance.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ jobs:
2525
run: |
2626
python -m venv venv
2727
. venv/bin/activate
28+
pip install pipenv
29+
pipenv requirements > requirements.txt
2830
pip install -r requirements.txt
2931
3032
- name: Check licenses

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ This project is licensed under the MIT License. See the [LICENSE](LICENSE) file
151151
This Project was created in the context of TUMs practical course [Digital Product Innovation and Development](https://www.fortiss.org/karriere/digital-product-innovation-and-development) by fortiss in the summer semester 2024.
152152
The task was suggested by Siemens, who also supervised the project.
153153

154+
## FAQ
155+
156+
Please refer to [FAQ](documentation/FAQ.md)
157+
154158
## Contact
155159

156160
To contact fortiss or Siemens, please refer to their official websites.

documentation/00 - introduction.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ For more detailed information about the API routes, refer to the [API Routes](ap
6767

6868
- **[Prerequisites](01%20-%20prerequisites):** Environment setup and dependencies.
6969
- **[Installation](02%20-%20installation):** Step-by-step installation guide.
70-
- **[Usage](04%20-%20usage):** Instructions on how to use the system.
70+
- **[Usage](03%20-%20usage):** Instructions on how to use the system.
71+
72+
- **[Testing](04-testing):** Provides an explanation of the testing strategy and rules.
7173

7274
---
7375

documentation/04-testing.md

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# Testing
2+
3+
We have a basic testing setup in place that covers database insertion and API retrieval.
4+
5+
The tests are located inside the `src/tests` directory and can be executed using the following command:
6+
7+
```bash
8+
pipenv run pytest
9+
#or
10+
pytest
11+
```
12+
13+
We also have a GitHub test workflow set up in `test.yml` that runs on every pull request and merge on the main branch to ensure that the tests are passing.
14+
15+
## Adding new Tests
16+
17+
New tests can also be added to the folder `src/tests`.
18+
19+
The files must be prefixed with `test_` for pytest to recognize them.
20+
21+
A testing function should also be created with the prefix `test_`.
22+
23+
eg:
24+
25+
```python
26+
def test_create_get_task_integration():
27+
assert 1+1=2
28+
```
29+
30+
We use dependency overriding of Repositories with different databases to ensure that they do not interfere with your actual database. The dependencies can be overridden as shown below.
31+
32+
```python
33+
34+
from app import app
35+
36+
37+
SQLALCHEMY_DATABASE_URL = "sqlite://"
38+
39+
engine = create_engine(
40+
SQLALCHEMY_DATABASE_URL,
41+
connect_args={"check_same_thread": False},
42+
poolclass=StaticPool,
43+
)
44+
TestingSessionLocal = sessionmaker(autocommit=False, autoflush=False, bind=engine)
45+
46+
47+
db_models.BaseModel.metadata.create_all(bind=engine)
48+
49+
50+
def override_get_db():
51+
try:
52+
db = TestingSessionLocal()
53+
yield db
54+
finally:
55+
db.close()
56+
57+
58+
def override_get_task_repository(session: Session = Depends(override_get_db)):
59+
return TaskRepository(session)
60+
61+
app.dependency_overrides[get_task_repository] = override_get_task_repository
62+
63+
```
64+
65+
For a comprehensive guide on testing with FastAPI, please refer to the [FASTAPI Testing](https://fastapi.tiangolo.com/tutorial/testing/) documentation.
66+
67+
Note:
68+
It is always challenging to perform integration testing, especially when dealing with LLMS and queues. However, the API endpoints have been thoroughly tested to ensure accurate responses.

documentation/FAQ.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,29 @@
11
# Frequently Asked Questions
22

3-
A compiled list of FAQs that may come in handy.
3+
A compiled list of frequently asked questions that may come in handy.
44

5-
## Import ot found?
5+
## Import not found?
66

7-
If you are getting an "import not found" error, it is likely because the base folder is always `src`. Always run the program from the `src` folder or use the commands inside the Makefile.
7+
If you are encountering an "import not found" error, it is likely because the base folder is always `src`. Make sure to run the program from the `src` folder or use the commands inside the Makefile.
88

9-
If you have something in `src/lib` and want to use it, import it as follows:
9+
If you have something in `src/lib` and want to use it, import it as shown below:
1010

1111
```python
1212
import lib # or
1313
from lib import ...
1414
```
1515

16+
# Why use POST call to retrieve recommendations and aggregated recommendations?
17+
18+
For these calls, we require a JSON type body with at least `{}`. This allows us to handle nested filters such as `task_id` and `severity` inside the filters. Using query parameters and GET calls would be less suitable for this purpose. However, one can modify the pathname, like changing `get-`, to make it more convenient.
19+
1620
# Why are env.docker and .env different?
1721

18-
If you are only running the program using Docker, then you only need to worry about `.env.docker`.
22+
If you are running the program exclusively using Docker, then you only need to concern yourself with `.env.docker`.
1923

20-
As the addresses tend to be different in a Docker environment compared to a local environment, you need different values to resolve the addresses.
24+
Since the addresses can differ between a Docker environment and a local environment, you need different values to resolve the addresses.
2125

22-
For example, if you have your program outside Docker (locally) and want to access a database, you may use:
26+
For example, if your program is outside Docker (locally) and you want to access a database, you may use:
2327

2428
```
2529
POSTGRES_SERVER=localhost
@@ -50,3 +54,7 @@ We have a predefined structure that input must adhere to called `Content`. You c
5054

5155
Inside the db model called `Findings`, there is a method `from_data` which can be modified to adapt the changes.
5256
`VulnerablityReport` also has `create_from_flama_json` that must be adjusted accordingly to make sure the Generation side also works.
57+
58+
# Does it make sense to Mock LLM?
59+
60+
While we don't strive for accuracy, it would still make sense to mock LLM methods to ensure that methods for finding and interacting properly with LLM class methods work correctly. Nevertheless, it is still difficult to extract meaningful test outputs based on only prompts as input.

requirements.txt

Lines changed: 0 additions & 25 deletions
This file was deleted.

run

Lines changed: 0 additions & 4 deletions
This file was deleted.

run.sh

Lines changed: 0 additions & 4 deletions
This file was deleted.

src/data/VulnerabilityReport.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def set_llm_service(self, llm_service: "LLMServiceStrategy"):
3030
finding.llm_service = llm_service
3131
return self
3232

33-
def add_finding(self, finding):
33+
def add_finding(self, finding: Finding):
3434
self.findings.append(finding)
3535

3636
def get_findings(self):

src/data/repository/finding.py

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)