• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CodeHex16 / Database-API / 15071891157

16 May 2025 03:23PM UTC coverage: 97.682% (-0.2%) from 97.876%
15071891157

push

github

web-flow
Merge pull request #36 from CodeHex16/fix-yihao-sprint15

Update MongoDB connection logic and comment out error handling

13 of 15 new or added lines in 7 files covered. (86.67%)

2 existing lines in 1 file now uncovered.

2107 of 2157 relevant lines covered (97.68%)

0.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

88.24
/app/database.py
1
import os
1✔
2
import regex
1✔
3

4

5
MONGODB_URL = os.getenv("MONGODB_URL")
1✔
6
MONGO_USERNAME = os.getenv("MONGO_USERNAME")
1✔
7
MONGO_PASSWORD = os.getenv("MONGO_PASSWORD")
1✔
8

9
# Se l'MONGODB_URL se contiene username e password, allora usa MONGODB_URL
10
if MONGODB_URL and regex.match(r"^mongodb://.*:.*@.*:.*", MONGODB_URL):
1✔
NEW
11
    MONGODB_URL = MONGODB_URL
×
12
# Se l'MONGODB_URL non contiene username e password, allora usa MONGO_USERNAME e MONGO_PASSWORD
13
elif MONGO_USERNAME and MONGO_PASSWORD and regex.match(r"^.*:.*", MONGODB_URL):
1✔
NEW
14
    MONGODB_URL = f"mongodb://{MONGO_USERNAME}:{MONGO_PASSWORD}@{MONGODB_URL}"
×
15
else:
16
    # Se non sono presenti username e password, usa l'URL di default
17
    MONGODB_URL = "mongodb://root:example@localhost:27017"
1✔
18

19

20

21
# Variabile globale per memorizzare la connessione al database
22
_db = None
1✔
23

24
def init_db(db_instance):
1✔
25
    """Inizializza la connessione al database"""
26
    global _db
27
    _db = db_instance
1✔
28

29
async def get_db():
1✔
30
    """Restituisce l'istanza del database"""
31
    global _db
32
    if _db is None:
1✔
33
        # Se il database non รจ stato inizializzato, solleva un'eccezione
34
        raise RuntimeError(
1✔
35
            "Database non inizializzato. Chiamare init_db() prima dell'utilizzo."
36
        )
37
    return _db
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc