forked from codeforboston/police-data-trust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
codeforboston#284 - Updated the unit tests to add a source for the co…
…ntributor user
- Loading branch information
Showing
1 changed file
with
26 additions
and
3 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 |
---|---|---|
|
@@ -3,8 +3,12 @@ | |
from backend.api import create_app | ||
from backend.auth import user_manager | ||
from backend.config import TestingConfig | ||
from backend.database import User, UserRole, db | ||
from backend.database import User, UserRole, db, Source, source_user | ||
from backend.database.models._assoc_tables import MemberRole | ||
from datetime import datetime | ||
from pytest_postgresql.janitor import DatabaseJanitor | ||
from sqlalchemy import insert | ||
from enum import Enum | ||
|
||
example_email = "[email protected]" | ||
admin_email = "[email protected]" | ||
|
@@ -50,6 +54,18 @@ def client(app): | |
return app.test_client() | ||
|
||
|
||
@pytest.fixture | ||
def example_source(db_session): | ||
source = Source( | ||
id="example_source", | ||
name="Example Source", | ||
url = "www.example.com", | ||
contact_email=contributor_email, | ||
) | ||
db_session.add(source) | ||
db_session.commit() | ||
return source | ||
|
||
@pytest.fixture | ||
def example_user(db_session): | ||
user = User( | ||
|
@@ -81,16 +97,23 @@ def admin_user(db_session): | |
|
||
|
||
@pytest.fixture | ||
def contributor_user(db_session): | ||
def contributor_user(db_session, example_source): | ||
user = User( | ||
email=contributor_email, | ||
password=user_manager.hash_password(example_password), | ||
role=UserRole.CONTRIBUTOR, | ||
first_name="contributor", | ||
last_name="last", | ||
last_name="last" | ||
) | ||
db_session.add(user) | ||
db_session.commit() | ||
insert_statement = insert(source_user).values( | ||
source_id=example_source.id, user_id=user.id, | ||
role=MemberRole.PUBLISHER, joined_at=datetime.now(), | ||
is_active=True, is_admin=False | ||
) | ||
db_session.execute(insert_statement) | ||
db_session.commit() | ||
|
||
return user | ||
|
||
|