Spaces:
Runtime error
Runtime error
Commit ·
d454ab0
1
Parent(s): afc114b
Worked with scope what is it and what does it do in test/database.py
Browse files- tests/database.py +2 -2
- tests/test_users.py +5 -1
tests/database.py
CHANGED
|
@@ -12,7 +12,7 @@ SQLALCHEMY_DATABASE_URL = f"postgresql://{setting.database_username}:{setting.da
|
|
| 12 |
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
| 13 |
TestingSessionMaker = sessionmaker(autoflush=False, autocommit=False, bind=engine)
|
| 14 |
|
| 15 |
-
@pytest.fixture
|
| 16 |
def session():
|
| 17 |
Base.metadata.drop_all(bind=engine)
|
| 18 |
Base.metadata.create_all(bind=engine)
|
|
@@ -22,7 +22,7 @@ def session():
|
|
| 22 |
finally:
|
| 23 |
db.close()
|
| 24 |
|
| 25 |
-
@pytest.fixture
|
| 26 |
def client(session):
|
| 27 |
def override_get_db():
|
| 28 |
try:
|
|
|
|
| 12 |
engine = create_engine(SQLALCHEMY_DATABASE_URL)
|
| 13 |
TestingSessionMaker = sessionmaker(autoflush=False, autocommit=False, bind=engine)
|
| 14 |
|
| 15 |
+
@pytest.fixture(scope="module")
|
| 16 |
def session():
|
| 17 |
Base.metadata.drop_all(bind=engine)
|
| 18 |
Base.metadata.create_all(bind=engine)
|
|
|
|
| 22 |
finally:
|
| 23 |
db.close()
|
| 24 |
|
| 25 |
+
@pytest.fixture(scope="module")
|
| 26 |
def client(session):
|
| 27 |
def override_get_db():
|
| 28 |
try:
|
tests/test_users.py
CHANGED
|
@@ -10,4 +10,8 @@ def test_create_user(client):
|
|
| 10 |
response = client.post("/users/", json={"email": "abdullah@gmail.com", "password": "abdullah1234"})
|
| 11 |
new_user = user.UserResponse(**response.json())
|
| 12 |
assert response.status_code == 201
|
| 13 |
-
assert new_user.email == "abdullah@gmail.com"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
response = client.post("/users/", json={"email": "abdullah@gmail.com", "password": "abdullah1234"})
|
| 11 |
new_user = user.UserResponse(**response.json())
|
| 12 |
assert response.status_code == 201
|
| 13 |
+
assert new_user.email == "abdullah@gmail.com"
|
| 14 |
+
|
| 15 |
+
def test_login_user(client):
|
| 16 |
+
response = client.post("/login", data={"username": "abdullah@gmail.com", "password": "abdullah1234"})
|
| 17 |
+
assert response.status_code==200
|