2018-12-14 11:36:22 -08:00
|
|
|
import json
|
2019-03-14 13:29:02 -07:00
|
|
|
from datetime import datetime
|
|
|
|
from datetime import timedelta
|
2018-09-18 15:17:34 -07:00
|
|
|
|
2019-01-22 21:35:22 -08:00
|
|
|
from flask_testing import TestCase
|
2019-03-14 13:29:02 -07:00
|
|
|
from mock import patch
|
|
|
|
|
2018-11-13 05:58:02 -08:00
|
|
|
from grant.app import create_app
|
CCRs (#86)
* CCRs API / Models boilerplate
* start on frontend
* backendy things
* Create CCR redux module, integrate API endpoints, create types
* Fix/Cleanup API
* Wire up CreateRequestDraftList
* bounty->target
* Add 'Create Request Flow' MVP
* cleanup
* Tweak filenames
* Simplify migrations
* fix migrations
* CCR Staking MVP
* tslint
* Get Pending Requests into Profile
* Remove staking requirement
* more staking related removals
* MVP Admin integration
* Make RFP when CCR is accepted
* Add pagination to CCRs in Admin
Improve styles for Proposals
* Hookup notifications
Adjust copy
* Simplify ccr->rfp relationship
Add admin approval email
Fixup copy
* Show Message on RFP Detail
Make Header CTAs change based on draft status
Adjust proposal card style
* Bugfix: Show header for non signed in users
* Add 'create a request' to intro
* Profile Created CCRs
RFP CCR attribution
* ignore
* CCR Price in USD (#85)
* init profile tipjar backend
* init profile tipjar frontend
* fix lint
* implement tip jar block
* fix wrapping, hide tip block on self
* init backend proposal tipjar
* init frontend proposal tipjar
* add hide title, fix bug
* uncomment rate limit
* rename vars, use null check
* allow address and view key to be unset
* add api tests
* fix tsc errors
* fix lint
* fix CopyInput styling
* fix migrations
* hide tipping in proposal if address not set
* add tip address to create flow
* redesign campaign block
* fix typo
* init backend changes
* init admin changes
* init frontend changes
* fix backend tests
* update campaign block
* be - init rfp usd changes
* admin - init rfp usd changes
* fe - fully adapt api util functions to usd
* fe - init rfp usd changes
* adapt profile created to usd
* misc usd changes
* add tip jar to dedicated card
* fix tipjar bug
* use zf light logo
* switch to zf grants logo
* hide profile tip jar if address not set
* add comment, run prettier
* conditionally add info icon and tooltip to funding line
* admin - disallow decimals in RFPs
* fe - cover usd string edge case
* add Usd as rfp bounty type
* fix migration order
* fix email bug
* adapt CCRs to USD
* implement CCR preview
* fix tsc
* Copy Updates and UX Tweaks (#87)
* Add default structure to proposal content
* Landing page copy
* Hide contributors tab for v2 proposals
* Minor UX tweaks for Liking/Following/Tipping
* Copy for Tipping Tooltip, proposal explainer for review, and milestone day estimate notice.
* Fix header styles bug and remove commented out styles.
* Revert "like" / "unfollow" hyphenication
* Comment out unused tests related to staking
Increase PROPOSAL_TARGET_MAX in .env.example
* Comment out ccr approval email send until ready
* Adjust styles, copy.
* fix proposal prune test (#88)
* fix USD display in preview, fix non-unique key (#90)
* Pre-stepper explainer for CCRs.
* Tweak styles
* Default content for CCRs
* fix tsc
* CCR approval and rejection emails
* add back admin_approval_ccr email templates
* Link ccr author name to profile in RFPs
* copy tweaks
* copy tweak
* hookup mangle user command
* Fix/add endif in jinja
* fix tests
* review
* fix review
2019-12-05 17:01:02 -08:00
|
|
|
from grant.ccr.models import CCR
|
2019-03-14 13:29:02 -07:00
|
|
|
from grant.extensions import limiter
|
|
|
|
from grant.milestone.models import Milestone
|
|
|
|
from grant.proposal.models import Proposal
|
|
|
|
from grant.settings import PROPOSAL_STAKING_AMOUNT
|
2019-01-29 14:21:06 -08:00
|
|
|
from grant.task.jobs import ProposalReminder
|
2019-01-22 21:35:22 -08:00
|
|
|
from grant.user.models import User, SocialMedia, db, Avatar
|
2019-01-30 09:59:15 -08:00
|
|
|
from grant.utils.enums import ProposalStatus
|
CCRs (#86)
* CCRs API / Models boilerplate
* start on frontend
* backendy things
* Create CCR redux module, integrate API endpoints, create types
* Fix/Cleanup API
* Wire up CreateRequestDraftList
* bounty->target
* Add 'Create Request Flow' MVP
* cleanup
* Tweak filenames
* Simplify migrations
* fix migrations
* CCR Staking MVP
* tslint
* Get Pending Requests into Profile
* Remove staking requirement
* more staking related removals
* MVP Admin integration
* Make RFP when CCR is accepted
* Add pagination to CCRs in Admin
Improve styles for Proposals
* Hookup notifications
Adjust copy
* Simplify ccr->rfp relationship
Add admin approval email
Fixup copy
* Show Message on RFP Detail
Make Header CTAs change based on draft status
Adjust proposal card style
* Bugfix: Show header for non signed in users
* Add 'create a request' to intro
* Profile Created CCRs
RFP CCR attribution
* ignore
* CCR Price in USD (#85)
* init profile tipjar backend
* init profile tipjar frontend
* fix lint
* implement tip jar block
* fix wrapping, hide tip block on self
* init backend proposal tipjar
* init frontend proposal tipjar
* add hide title, fix bug
* uncomment rate limit
* rename vars, use null check
* allow address and view key to be unset
* add api tests
* fix tsc errors
* fix lint
* fix CopyInput styling
* fix migrations
* hide tipping in proposal if address not set
* add tip address to create flow
* redesign campaign block
* fix typo
* init backend changes
* init admin changes
* init frontend changes
* fix backend tests
* update campaign block
* be - init rfp usd changes
* admin - init rfp usd changes
* fe - fully adapt api util functions to usd
* fe - init rfp usd changes
* adapt profile created to usd
* misc usd changes
* add tip jar to dedicated card
* fix tipjar bug
* use zf light logo
* switch to zf grants logo
* hide profile tip jar if address not set
* add comment, run prettier
* conditionally add info icon and tooltip to funding line
* admin - disallow decimals in RFPs
* fe - cover usd string edge case
* add Usd as rfp bounty type
* fix migration order
* fix email bug
* adapt CCRs to USD
* implement CCR preview
* fix tsc
* Copy Updates and UX Tweaks (#87)
* Add default structure to proposal content
* Landing page copy
* Hide contributors tab for v2 proposals
* Minor UX tweaks for Liking/Following/Tipping
* Copy for Tipping Tooltip, proposal explainer for review, and milestone day estimate notice.
* Fix header styles bug and remove commented out styles.
* Revert "like" / "unfollow" hyphenication
* Comment out unused tests related to staking
Increase PROPOSAL_TARGET_MAX in .env.example
* Comment out ccr approval email send until ready
* Adjust styles, copy.
* fix proposal prune test (#88)
* fix USD display in preview, fix non-unique key (#90)
* Pre-stepper explainer for CCRs.
* Tweak styles
* Default content for CCRs
* fix tsc
* CCR approval and rejection emails
* add back admin_approval_ccr email templates
* Link ccr author name to profile in RFPs
* copy tweaks
* copy tweak
* hookup mangle user command
* Fix/add endif in jinja
* fix tests
* review
* fix review
2019-12-05 17:01:02 -08:00
|
|
|
from .test_data import test_user, test_other_user, test_proposal, mock_blockchain_api_requests, test_ccr
|
2018-09-18 15:17:34 -07:00
|
|
|
|
|
|
|
|
|
|
|
class BaseTestConfig(TestCase):
|
|
|
|
|
|
|
|
def create_app(self):
|
2018-11-28 13:56:19 -08:00
|
|
|
app = create_app(['grant.settings', 'tests.settings'])
|
2018-09-18 15:17:34 -07:00
|
|
|
app.config.from_object('tests.settings')
|
2019-03-12 20:35:38 -07:00
|
|
|
limiter.enabled = False
|
2018-09-18 15:17:34 -07:00
|
|
|
return app
|
|
|
|
|
|
|
|
def setUp(self):
|
2018-11-13 05:58:02 -08:00
|
|
|
db.drop_all()
|
2018-09-18 15:17:34 -07:00
|
|
|
self.app = self.create_app().test_client()
|
|
|
|
db.create_all()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
db.session.remove()
|
|
|
|
db.drop_all()
|
2018-12-14 11:36:22 -08:00
|
|
|
|
2018-11-27 11:07:09 -08:00
|
|
|
def assertStatus(self, response, status_code, message=None):
|
|
|
|
"""
|
|
|
|
Overrides TestCase's default to print out response JSON.
|
|
|
|
"""
|
2018-11-13 05:58:02 -08:00
|
|
|
|
2018-11-27 11:07:09 -08:00
|
|
|
message = message or 'HTTP Status %s expected but got %s. Response json: %s' \
|
2019-03-14 13:29:02 -07:00
|
|
|
% (status_code, response.status_code, response.json or response.data)
|
2018-11-27 11:07:09 -08:00
|
|
|
self.assertEqual(response.status_code, status_code, message)
|
|
|
|
|
|
|
|
assert_status = assertStatus
|
2018-11-13 05:58:02 -08:00
|
|
|
|
2018-12-14 11:36:22 -08:00
|
|
|
|
2018-11-13 05:58:02 -08:00
|
|
|
class BaseUserConfig(BaseTestConfig):
|
|
|
|
def setUp(self):
|
|
|
|
super(BaseUserConfig, self).setUp()
|
2018-12-17 10:33:33 -08:00
|
|
|
self._user = User.create(
|
2018-11-13 05:58:02 -08:00
|
|
|
email_address=test_user["emailAddress"],
|
2018-12-14 11:36:22 -08:00
|
|
|
password=test_user["password"],
|
2018-11-13 05:58:02 -08:00
|
|
|
display_name=test_user["displayName"],
|
|
|
|
title=test_user["title"],
|
|
|
|
)
|
2019-01-27 18:51:05 -08:00
|
|
|
self._user.email_verification.has_verified = True
|
|
|
|
db.session.add(self._user)
|
2019-01-02 10:23:02 -08:00
|
|
|
sm = SocialMedia(
|
|
|
|
service=test_user['socialMedias'][0]['service'],
|
|
|
|
username=test_user['socialMedias'][0]['username'],
|
|
|
|
user_id=self._user.id)
|
2018-11-13 05:58:02 -08:00
|
|
|
db.session.add(sm)
|
2018-12-17 10:33:33 -08:00
|
|
|
avatar = Avatar(image_url=test_user["avatar"]["link"], user_id=self._user.id)
|
2018-11-13 05:58:02 -08:00
|
|
|
db.session.add(avatar)
|
2018-12-14 11:36:22 -08:00
|
|
|
self.user_password = test_user["password"]
|
|
|
|
|
2019-01-04 11:03:37 -08:00
|
|
|
self._other_user = User.create(
|
2018-11-29 13:54:26 -08:00
|
|
|
email_address=test_other_user["emailAddress"],
|
2018-12-14 11:36:22 -08:00
|
|
|
password=test_other_user["password"],
|
2018-11-29 13:54:26 -08:00
|
|
|
display_name=test_other_user["displayName"],
|
|
|
|
title=test_other_user["title"]
|
|
|
|
)
|
2019-01-04 11:03:37 -08:00
|
|
|
self.other_user_password = test_other_user["password"]
|
2018-11-13 05:58:02 -08:00
|
|
|
db.session.commit()
|
2018-12-17 10:33:33 -08:00
|
|
|
self._user_id = self._user.id
|
2019-01-04 11:03:37 -08:00
|
|
|
self._other_user_id = self._other_user.id
|
2018-11-13 05:58:02 -08:00
|
|
|
|
2018-12-17 10:33:33 -08:00
|
|
|
# always return fresh (avoid detached instance issues)
|
|
|
|
@property
|
|
|
|
def user(self):
|
|
|
|
return User.query.filter_by(id=self._user_id).first()
|
|
|
|
|
2019-01-04 11:03:37 -08:00
|
|
|
@property
|
|
|
|
def other_user(self):
|
|
|
|
return User.query.filter_by(id=self._other_user_id).first()
|
|
|
|
|
2019-01-27 19:09:31 -08:00
|
|
|
def mark_user_not_verified(self, user=None):
|
|
|
|
if not user:
|
|
|
|
user = self.user
|
|
|
|
user.email_verification.has_verified = False
|
|
|
|
db.session.add(user)
|
|
|
|
db.session.commit()
|
|
|
|
|
2018-12-17 10:33:33 -08:00
|
|
|
def login_default_user(self, cust_pass=None):
|
|
|
|
return self.app.post(
|
2018-12-14 11:36:22 -08:00
|
|
|
"/api/v1/users/auth",
|
|
|
|
data=json.dumps({
|
|
|
|
"email": self.user.email_address,
|
2018-12-17 10:33:33 -08:00
|
|
|
"password": cust_pass or self.user_password
|
2018-12-14 11:36:22 -08:00
|
|
|
}),
|
|
|
|
content_type="application/json"
|
|
|
|
)
|
|
|
|
|
2019-01-04 11:03:37 -08:00
|
|
|
def login_other_user(self):
|
|
|
|
return self.app.post(
|
|
|
|
"/api/v1/users/auth",
|
|
|
|
data=json.dumps({
|
|
|
|
"email": self.other_user.email_address,
|
|
|
|
"password": self.other_user_password
|
|
|
|
}),
|
|
|
|
content_type="application/json"
|
|
|
|
)
|
|
|
|
|
2018-11-13 05:58:02 -08:00
|
|
|
def remove_default_user(self):
|
|
|
|
User.query.filter_by(id=self.user.id).delete()
|
|
|
|
db.session.commit()
|
2018-11-28 13:56:19 -08:00
|
|
|
|
2018-12-14 11:36:22 -08:00
|
|
|
|
2018-11-28 13:56:19 -08:00
|
|
|
class BaseProposalCreatorConfig(BaseUserConfig):
|
|
|
|
def setUp(self):
|
|
|
|
super().setUp()
|
2018-12-17 10:33:33 -08:00
|
|
|
self._proposal = Proposal.create(
|
2019-01-30 09:59:15 -08:00
|
|
|
status=ProposalStatus.DRAFT,
|
2018-11-29 17:55:14 -08:00
|
|
|
title=test_proposal["title"],
|
|
|
|
content=test_proposal["content"],
|
|
|
|
brief=test_proposal["brief"],
|
|
|
|
category=test_proposal["category"],
|
|
|
|
target=test_proposal["target"],
|
|
|
|
payout_address=test_proposal["payoutAddress"],
|
2018-12-28 15:05:34 -08:00
|
|
|
deadline_duration=test_proposal["deadlineDuration"]
|
2018-11-29 17:55:14 -08:00
|
|
|
)
|
2018-12-17 10:33:33 -08:00
|
|
|
self._proposal.team.append(self.user)
|
|
|
|
db.session.add(self._proposal)
|
2019-03-14 13:29:02 -07:00
|
|
|
db.session.flush()
|
|
|
|
|
|
|
|
milestones = [
|
|
|
|
{
|
|
|
|
"title": "Milestone 1",
|
|
|
|
"content": "Content 1",
|
2019-11-13 14:38:17 -08:00
|
|
|
"days_estimated": "30",
|
2019-03-14 13:29:02 -07:00
|
|
|
"payout_percent": 50,
|
|
|
|
"immediate_payout": True
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"title": "Milestone 2",
|
|
|
|
"content": "Content 2",
|
2019-11-13 14:38:17 -08:00
|
|
|
"days_estimated": "20",
|
2019-03-14 13:29:02 -07:00
|
|
|
"payout_percent": 50,
|
|
|
|
"immediate_payout": False
|
|
|
|
}
|
|
|
|
]
|
|
|
|
|
|
|
|
Milestone.make(milestones, self._proposal)
|
2018-11-29 13:54:26 -08:00
|
|
|
|
2019-01-30 09:59:15 -08:00
|
|
|
self._other_proposal = Proposal.create(status=ProposalStatus.DRAFT)
|
2018-12-17 10:33:33 -08:00
|
|
|
self._other_proposal.team.append(self.other_user)
|
|
|
|
db.session.add(self._other_proposal)
|
2018-11-28 13:56:19 -08:00
|
|
|
db.session.commit()
|
2018-12-17 10:33:33 -08:00
|
|
|
self._proposal_id = self._proposal.id
|
|
|
|
self._other_proposal_id = self._other_proposal.id
|
|
|
|
|
|
|
|
# always return fresh (avoid detached instance issues)
|
|
|
|
@property
|
|
|
|
def proposal(self):
|
|
|
|
return Proposal.query.filter_by(id=self._proposal_id).first()
|
|
|
|
|
|
|
|
@property
|
|
|
|
def other_proposal(self):
|
|
|
|
return Proposal.query.filter_by(id=self._other_proposal_id).first()
|
2019-01-29 14:21:06 -08:00
|
|
|
|
|
|
|
def make_proposal_reminder_task(self):
|
|
|
|
proposal_reminder = ProposalReminder(self.proposal.id)
|
2019-01-31 14:56:16 -08:00
|
|
|
proposal_reminder.make_task()
|
|
|
|
|
2019-02-05 12:26:37 -08:00
|
|
|
@patch('requests.get', side_effect=mock_blockchain_api_requests)
|
2019-01-31 14:56:16 -08:00
|
|
|
def stake_proposal(self, mock_get):
|
|
|
|
# 1. submit
|
|
|
|
self.proposal.submit_for_approval()
|
|
|
|
# 2. get staking contribution
|
|
|
|
contribution = self.proposal.get_staking_contribution(self.user.id)
|
|
|
|
# 3. fake a confirmation
|
2019-02-05 17:45:57 -08:00
|
|
|
contribution.confirm(tx_id='tx', amount=str(PROPOSAL_STAKING_AMOUNT.normalize()))
|
2019-01-31 14:56:16 -08:00
|
|
|
db.session.add(contribution)
|
2019-02-21 10:43:20 -08:00
|
|
|
db.session.flush()
|
|
|
|
self.proposal.set_pending_when_ready()
|
CCRs (#86)
* CCRs API / Models boilerplate
* start on frontend
* backendy things
* Create CCR redux module, integrate API endpoints, create types
* Fix/Cleanup API
* Wire up CreateRequestDraftList
* bounty->target
* Add 'Create Request Flow' MVP
* cleanup
* Tweak filenames
* Simplify migrations
* fix migrations
* CCR Staking MVP
* tslint
* Get Pending Requests into Profile
* Remove staking requirement
* more staking related removals
* MVP Admin integration
* Make RFP when CCR is accepted
* Add pagination to CCRs in Admin
Improve styles for Proposals
* Hookup notifications
Adjust copy
* Simplify ccr->rfp relationship
Add admin approval email
Fixup copy
* Show Message on RFP Detail
Make Header CTAs change based on draft status
Adjust proposal card style
* Bugfix: Show header for non signed in users
* Add 'create a request' to intro
* Profile Created CCRs
RFP CCR attribution
* ignore
* CCR Price in USD (#85)
* init profile tipjar backend
* init profile tipjar frontend
* fix lint
* implement tip jar block
* fix wrapping, hide tip block on self
* init backend proposal tipjar
* init frontend proposal tipjar
* add hide title, fix bug
* uncomment rate limit
* rename vars, use null check
* allow address and view key to be unset
* add api tests
* fix tsc errors
* fix lint
* fix CopyInput styling
* fix migrations
* hide tipping in proposal if address not set
* add tip address to create flow
* redesign campaign block
* fix typo
* init backend changes
* init admin changes
* init frontend changes
* fix backend tests
* update campaign block
* be - init rfp usd changes
* admin - init rfp usd changes
* fe - fully adapt api util functions to usd
* fe - init rfp usd changes
* adapt profile created to usd
* misc usd changes
* add tip jar to dedicated card
* fix tipjar bug
* use zf light logo
* switch to zf grants logo
* hide profile tip jar if address not set
* add comment, run prettier
* conditionally add info icon and tooltip to funding line
* admin - disallow decimals in RFPs
* fe - cover usd string edge case
* add Usd as rfp bounty type
* fix migration order
* fix email bug
* adapt CCRs to USD
* implement CCR preview
* fix tsc
* Copy Updates and UX Tweaks (#87)
* Add default structure to proposal content
* Landing page copy
* Hide contributors tab for v2 proposals
* Minor UX tweaks for Liking/Following/Tipping
* Copy for Tipping Tooltip, proposal explainer for review, and milestone day estimate notice.
* Fix header styles bug and remove commented out styles.
* Revert "like" / "unfollow" hyphenication
* Comment out unused tests related to staking
Increase PROPOSAL_TARGET_MAX in .env.example
* Comment out ccr approval email send until ready
* Adjust styles, copy.
* fix proposal prune test (#88)
* fix USD display in preview, fix non-unique key (#90)
* Pre-stepper explainer for CCRs.
* Tweak styles
* Default content for CCRs
* fix tsc
* CCR approval and rejection emails
* add back admin_approval_ccr email templates
* Link ccr author name to profile in RFPs
* copy tweaks
* copy tweak
* hookup mangle user command
* Fix/add endif in jinja
* fix tests
* review
* fix review
2019-12-05 17:01:02 -08:00
|
|
|
|
|
|
|
|
|
|
|
class BaseCCRCreatorConfig(BaseUserConfig):
|
|
|
|
def setUp(self):
|
|
|
|
super().setUp()
|
|
|
|
self._ccr = CCR.create(
|
|
|
|
status=ProposalStatus.DRAFT,
|
|
|
|
title=test_ccr["title"],
|
|
|
|
content=test_ccr["content"],
|
|
|
|
brief=test_ccr["brief"],
|
|
|
|
target=test_ccr["target"],
|
|
|
|
user_id=self.user.id
|
|
|
|
)
|
|
|
|
self._ccr_id = self._ccr.id
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
# always return fresh (avoid detached instance issues)
|
|
|
|
@property
|
|
|
|
def ccr(self):
|
|
|
|
return CCR.query.filter_by(id=self._ccr_id).first()
|