Skip to content

Commit

Permalink
Merge branch 'main' into update-ml-id-column-sites
Browse files Browse the repository at this point in the history
  • Loading branch information
peterdudfield authored Sep 20, 2024
2 parents 8eed688 + 0fa40db commit 823e9cf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .bumpversion.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 1.0.36
current_version = 1.0.37
commit = True
tag = True
message = Bump version: {current_version} → {new_version} [ci skip]
Expand Down
2 changes: 1 addition & 1 deletion pvsite_datamodel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
UserSQL,
)

__version__ = "1.0.36"
__version__ = "1.0.37"
15 changes: 11 additions & 4 deletions pvsite_datamodel/read/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,17 @@ def get_user_by_email(session: Session, email: str, make_new_user_if_none: bool
if user is None and make_new_user_if_none is True:
logger.info(f"User with email {email} not found, so making one")

# making a new site group
site_group = SiteGroupSQL(site_group_name=f"site_group_for_{email}")
session.add(site_group)
session.commit()
# checking for site_group
site_group = (
session.query(SiteGroupSQL)
.filter(SiteGroupSQL.site_group_name == f"site_group_for_{email}")
.first()
)
# making a new site group if one doesn't exist
if site_group is None:
site_group = SiteGroupSQL(site_group_name=f"site_group_for_{email}")
session.add(site_group)
session.commit()

# make a new user
user = UserSQL(email=email, site_group_uuid=site_group.site_group_uuid)
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

[tool.poetry]
name = "pvsite-datamodel"
version = "1.0.36"
version = "1.0.37"
description = "SDK for interacting with the PVSite database"
authors = ["Open Climate Fix"]
readme = "README.md"
Expand Down
12 changes: 9 additions & 3 deletions tests/read/test_get_user_by_email.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
from pvsite_datamodel import UserSQL
from pvsite_datamodel import SiteGroupSQL, UserSQL
from pvsite_datamodel.read import get_user_by_email
from pvsite_datamodel.write.user_and_site import create_site_group, create_user


class TestGetUserByEmail:
"""Test for get_user_by_email function"""

def test_get_user_by_email_no_users_site_group_exists(self, db_session):
_ = create_site_group(db_session=db_session, site_group_name="[email protected]")
_ = get_user_by_email(session=db_session, email="[email protected]")
assert len(db_session.query(UserSQL).all()) == 1
assert len(db_session.query(SiteGroupSQL).all()) == 1

def test_get_user_by_email_no_users(self, db_session):
user = get_user_by_email(session=db_session, email="[email protected]")
assert user.email == "[email protected]"
assert len(db_session.query(UserSQL).all()) == 1

def test_get_user_by_email_with_users(self, db_session):
site_group = create_site_group(db_session=db_session)
user = create_user(
_ = create_user(
session=db_session, site_group_name=site_group.site_group_name, email="[email protected]"
)
user = create_user(
_ = create_user(
session=db_session, site_group_name=site_group.site_group_name, email="[email protected]"
)

Expand Down

0 comments on commit 823e9cf

Please sign in to comment.