Skip to content

Commit

Permalink
add tests for successful bounty api request, and successful bounty pa…
Browse files Browse the repository at this point in the history
…yout
  • Loading branch information
Jer-Sch committed Nov 3, 2021
1 parent 2f9914a commit 461f31d
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 0 deletions.
15 changes: 15 additions & 0 deletions app/dashboard/tests/factories/bounty_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from datetime import datetime, timedelta

import factory
from dashboard.models import Bounty


class BountyFactory(factory.django.DjangoModelFactory):
class Meta:
model = Bounty

web3_created = datetime.now()
is_open = True
expires_date = datetime.now() + timedelta(days=365)
raw_data = {}
bounty_owner_github_username = 'gitcoin'
13 changes: 13 additions & 0 deletions app/dashboard/tests/factories/fulfillment_factory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import factory

from dashboard.models import BountyFulfillment
from .bounty_factory import BountyFactory
from .profile_factory import ProfileFactory


class FulfillmentFactory(factory.django.DjangoModelFactory):
class Meta:
model = BountyFulfillment

bounty = factory.SubFactory(BountyFactory)
profile = factory.SubFactory(ProfileFactory)
16 changes: 16 additions & 0 deletions app/dashboard/tests/views/test_bounty_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import pytest

This comment has been minimized.

from dashboard.tests.factories.bounty_factory import BountyFactory
from rest_framework.test import APIClient


class TestBountyAPI:
def test_retrieves_activities(self, django_user_model):
github_url = {'github_url': 'https://github.com/gitcoinco/web/issues/1'}
BountyFactory(**github_url)
user = django_user_model.objects.create(username="gitcoin", password="password123")
client = APIClient()

client.force_login(user)
response = client.get('/actions/api/v0.1/bounty/', github_url, format='json')

assert response.status_code == 200
34 changes: 34 additions & 0 deletions app/dashboard/tests/views/test_bounty_payout.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
from dashboard.tests.factories.profile_factory import ProfileFactory
from dashboard.tests.factories.bounty_factory import BountyFactory
from dashboard.tests.factories.fulfillment_factory import FulfillmentFactory
from rest_framework.test import APIClient


@pytest.mark.django_db
class TestBountyPayout:
def test_pays_out_bounty(self, django_user_model):
github_url = {'github_url': 'https://github.com/gitcoinco/web/issues/1'}
BountyFactory(**github_url)
user = django_user_model.objects.create(username="gitcoin", password="password123")
ProfileFactory(user=user)
fulfillment = FulfillmentFactory()

client = APIClient()

client.force_login(user)

payload = {
'payout_type': 'fiat',
'tenant': 'testtenant',
'amount': '1',
'token_name': 'ETH',
'funder_address': '0x0',
'payout_status': 'pending',
'funder_identifier': 'test_funder_identifier',
'payout_tx_id': '0x0',
}

response = client.post(f'/api/v1/bounty/payout/{fulfillment.id}', payload)

assert response.status_code == 200

0 comments on commit 461f31d

Please sign in to comment.