-
-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #284 - Updated the Create endpoint to require a CONTRIBUTOR role and updates the unit tests to use a contributor user. * Adds member list to source. Commented out. Need to find a way to associate the user. Also adds member roles. * #284 - Added a check for the contributor having a source before continuing. Will now update unit tests. * #284 - Updated the unit tests to add a source for the contributor user * #284 - Renaming 'Source' to 'Organization' to match how the front-end refers to the concept. * #284 - Fixed style issues. --------- Co-authored-by: Darrell Malone Jr <[email protected]>
- Loading branch information
Showing
14 changed files
with
177 additions
and
57 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
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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from ..core import db, CrudMixin | ||
from backend.database.models._assoc_tables import organization_user | ||
|
||
|
||
class Organization(db.Model, CrudMixin): | ||
id = db.Column(db.String, primary_key=True) | ||
name = db.Column(db.Text) | ||
url = db.Column(db.Text) | ||
contact_email = db.Column(db.Text) | ||
reported_incidents = db.relationship( | ||
'Incident', backref='organization', lazy="select") | ||
members = db.relationship( | ||
'User', backref='contributor_orgs', | ||
secondary=organization_user, lazy="select") |
This file was deleted.
Oops, something went wrong.
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
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
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
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
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
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,11 +3,15 @@ | |
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, Organization, organization_user | ||
from backend.database.models._assoc_tables import MemberRole | ||
from datetime import datetime | ||
from pytest_postgresql.janitor import DatabaseJanitor | ||
from sqlalchemy import insert | ||
|
||
example_email = "[email protected]" | ||
admin_email = "[email protected]" | ||
contributor_email = "[email protected]" | ||
example_password = "my_password" | ||
|
||
|
||
|
@@ -49,6 +53,19 @@ def client(app): | |
return app.test_client() | ||
|
||
|
||
@pytest.fixture | ||
def example_organization(db_session): | ||
organization = Organization( | ||
id="example_organization", | ||
name="Example Organization", | ||
url="www.example.com", | ||
contact_email=contributor_email, | ||
) | ||
db_session.add(organization) | ||
db_session.commit() | ||
return organization | ||
|
||
|
||
@pytest.fixture | ||
def example_user(db_session): | ||
user = User( | ||
|
@@ -79,6 +96,28 @@ def admin_user(db_session): | |
return user | ||
|
||
|
||
@pytest.fixture | ||
def contributor_user(db_session, example_organization): | ||
user = User( | ||
email=contributor_email, | ||
password=user_manager.hash_password(example_password), | ||
role=UserRole.CONTRIBUTOR, | ||
first_name="contributor", | ||
last_name="last" | ||
) | ||
db_session.add(user) | ||
db_session.commit() | ||
insert_statement = insert(organization_user).values( | ||
organization_id=example_organization.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 | ||
|
||
|
||
@pytest.fixture | ||
def access_token(client, example_user): | ||
res = client.post( | ||
|
@@ -92,6 +131,19 @@ def access_token(client, example_user): | |
return res.json["access_token"] | ||
|
||
|
||
@pytest.fixture | ||
def contributor_access_token(client, contributor_user): | ||
res = client.post( | ||
"api/v1/auth/login", | ||
json={ | ||
"email": contributor_email, | ||
"password": example_password, | ||
}, | ||
) | ||
assert res.status_code == 200 | ||
return res.json["access_token"] | ||
|
||
|
||
@pytest.fixture | ||
def cli_runner(app): | ||
return app.test_cli_runner() | ||
|
Oops, something went wrong.