-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1f63b09
commit 5593a03
Showing
1 changed file
with
0 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,9 @@ | ||
"""tests for get_data.py""" | ||
from get_data import ( | ||
add_site_to_site_group, | ||
create_new_site, | ||
create_user, | ||
delete_site, | ||
delete_site_group, | ||
delete_user, | ||
get_all_users, | ||
get_all_site_groups, | ||
) | ||
from sqlalchemy import func | ||
from pvsite_datamodel.sqlmodels import UserSQL, SiteGroupSQL, SiteSQL | ||
from pvsite_datamodel.read import get_all_sites | ||
from pvsite_datamodel.write.user_and_site import make_site_group, make_site, make_user | ||
|
||
|
||
# get all users | ||
|
@@ -34,155 +25,3 @@ def test_get_all_site_groups(db_session): | |
site_groups = get_all_site_groups(session=db_session) | ||
# assert | ||
assert len(site_groups) == 0 | ||
|
||
|
||
# add site to site group | ||
def test_add_site_to_site_group(db_session): | ||
site_group = make_site_group(db_session=db_session) | ||
site_1 = make_site(db_session=db_session, ml_id=1) | ||
site_2 = make_site(db_session=db_session, ml_id=2) | ||
site_3 = make_site(db_session=db_session, ml_id=3) | ||
site_group.sites.append(site_1) | ||
site_group.sites.append(site_2) | ||
|
||
add_site_to_site_group( | ||
session=db_session, | ||
site_uuid=str(site_3.site_uuid), | ||
site_group_name=site_group.site_group_name, | ||
) | ||
|
||
assert len(site_group.sites) == 3 | ||
|
||
|
||
# create new site | ||
def test_create_new_site(db_session): | ||
site, message = create_new_site( | ||
session=db_session, | ||
client_site_id=6932, | ||
client_site_name="test_site_name", | ||
latitude=1.0, | ||
longitude=1.0, | ||
capacity_kw=1.0, | ||
) | ||
|
||
assert site.client_site_name == "test_site_name" | ||
assert site.ml_id == 1 | ||
assert site.client_site_id == 6932 | ||
assert ( | ||
message | ||
== f"Site with client site id {site.client_site_id} and site uuid {site.site_uuid} created successfully" | ||
) | ||
|
||
|
||
# test for create_new_site to check ml_id increments | ||
def test_create_new_site_twice(db_session): | ||
"""Test create new site function for ml_id""" | ||
|
||
site_1, _ = create_new_site( | ||
session=db_session, | ||
client_site_id=6932, | ||
client_site_name="test_site_name", | ||
latitude=1.0, | ||
longitude=1.0, | ||
capacity_kw=1.0, | ||
) | ||
|
||
site_2, _ = create_new_site( | ||
session=db_session, | ||
client_site_id=6932, | ||
client_site_name="test_site_name", | ||
latitude=1.0, | ||
longitude=1.0, | ||
capacity_kw=1.0, | ||
) | ||
|
||
assert site_1.ml_id == 1 | ||
assert site_2.ml_id == 2 | ||
|
||
|
||
def test_create_user(db_session): | ||
"Test to create a new user." | ||
|
||
site_group_1 = make_site_group(db_session=db_session) | ||
|
||
user_1 = create_user( | ||
session=db_session, | ||
email="[email protected]", | ||
site_group_name=site_group_1.site_group_name, | ||
) | ||
|
||
assert user_1.email == "[email protected]" | ||
assert user_1.site_group.site_group_name == "test_site_group" | ||
assert user_1.site_group_uuid == site_group_1.site_group_uuid | ||
|
||
# test to delete a site | ||
def test_delete_site(db_session): | ||
"""Test to delete a site.""" | ||
|
||
site_1 = make_site(db_session=db_session, ml_id=1) | ||
|
||
# todo add site to site group | ||
|
||
site_group = make_site_group(db_session=db_session, site_group_name="test_site_group") | ||
site_group.sites.append(site_1) | ||
|
||
site_uuid = site_1.site_uuid | ||
|
||
message = delete_site(session=db_session, site_uuid=site_uuid) | ||
|
||
site = db_session.query(SiteSQL).filter(SiteSQL.site_uuid == site_uuid).first() | ||
|
||
assert site is None | ||
assert message == f"Site with site uuid {site_uuid} deleted successfully" | ||
|
||
# test to delete a user | ||
def test_delete_user(db_session): | ||
"""Test to delete a user.""" | ||
|
||
site_group_1 = make_site_group(db_session=db_session) | ||
|
||
user_1 = make_user( | ||
db_session=db_session, | ||
email="[email protected]", | ||
site_group=site_group_1, | ||
) | ||
|
||
message = delete_user(session=db_session, email=user_1.email) | ||
|
||
user = db_session.query(UserSQL).filter(UserSQL.email == user_1.email).first() | ||
|
||
assert message == f"User with email {user_1.email} and site_group_uuid {user_1.site_group_uuid} deleted successfully" | ||
assert user is None | ||
|
||
|
||
|
||
|
||
# # test to delete a site group | ||
def test_delete_site_group(db_session): | ||
|
||
site_group = make_site_group(db_session=db_session, site_group_name="test_site_group") | ||
|
||
message = delete_site_group(session=db_session, site_group_name=site_group.site_group_name) | ||
|
||
assert message == f"Site group with name {site_group.site_group_name} and site group uuid {site_group.site_group_uuid} deleted successfully." | ||
|
||
# test delete site group with users | ||
|
||
def test_delete_site_group_with_users(db_session): | ||
"""Test to delete a site group with users.""" | ||
|
||
site_group_1 = make_site_group(db_session=db_session) | ||
|
||
_ = make_user( | ||
db_session=db_session, | ||
email="[email protected]", | ||
site_group=site_group_1, | ||
) | ||
|
||
message = delete_site_group(session=db_session, site_group_name=site_group_1.site_group_name) | ||
|
||
assert message == f"Site group with name {site_group_1.site_group_name} and site group uuid {site_group_1.site_group_uuid} has users and cannot be deleted." | ||
|
||
|
||
|
||
|