Skip to content

Commit 8f54d46

Browse files
ksoloKevin Soloriogdixon
authored
Testing workshop (#9668)
* updated to ignore tool versions for local python version management * remove whitespace * update factory locations for testing workshop * update module path for cy_create_grants * update factories and tests * prep for testing workshop * tests from workshop * updated location of factory in import * update test and factory for grant_clr * Update .gitignore Co-authored-by: Graham Dixon <[email protected]> Co-authored-by: Kevin Solorio <[email protected]> Co-authored-by: Graham Dixon <[email protected]>
1 parent 0cd2af9 commit 8f54d46

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+119
-144
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,6 @@ _build/
6161
# cypress artifacts
6262
cypress/videos
6363
cypress/screenshots
64+
65+
# asdf-vm (https://asdf-vm.com/)
66+
.tool-versions
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .bounty_factory import BountyFactory
2+
from .fulfillment_factory import FulfillmentFactory
3+
from .profile_factory import ProfileFactory

app/dashboard/tests/factories/bounty_factory.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ class BountyFactory(factory.django.DjangoModelFactory):
88
class Meta:
99
model = Bounty
1010

11-
web3_created = datetime.now()
12-
is_open = True
13-
expires_date = datetime.now() + timedelta(days=365)
14-
raw_data = {}
15-
bounty_owner_github_username = 'gitcoin'
11+
web3_created = factory.LazyFunction(datetime.now)
12+
is_open = factory.Faker('pybool')
13+
expires_date = factory.LazyFunction(lambda: datetime.now() + timedelta(days=365))
14+
raw_data = factory.LazyFunction(dict)
15+
bounty_owner_github_username = factory.LazyFunction(lambda: 'gitcoin')

app/dashboard/tests/factories/profile_factory.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ class Meta:
99
model = Profile
1010

1111
handle = factory.Sequence(lambda n: "Contributor_%03d" % n)
12-
data = {}
12+
data = factory.LazyFunction(dict)
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from attr import has
2+
import pytest
3+
4+
from dashboard.models import BountyFulfillment
5+
from dashboard.tests.factories.fulfillment_factory import FulfillmentFactory
6+
from dashboard.tests.factories.bounty_factory import BountyFactory
7+
8+
@pytest.mark.django_db
9+
class TestBountyFulfillmentProperties:
10+
def test_fulfillment_has_bounty(self):
11+
fulfillment = FulfillmentFactory()
12+
assert hasattr(fulfillment, 'bounty')
13+
14+
def test_deleting_bounty_deletes_fulfillment(self):
15+
bounty = BountyFactory()
16+
fulfillment = FulfillmentFactory(bounty=bounty)
17+
18+
bounty.delete()
19+
20+
with pytest.raises(BountyFulfillment.DoesNotExist):
21+
fulfillment.refresh_from_db()

app/dashboard/tests/views/test_bounty_api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from dashboard.tests.factories.bounty_factory import BountyFactory
2+
from dashboard.tests.factories import BountyFactory
33
from rest_framework.test import APIClient
44

55

@@ -13,4 +13,4 @@ def test_retrieves_activities(self, django_user_model):
1313
client.force_login(user)
1414
response = client.get('/actions/api/v0.1/bounty/', github_url, format='json')
1515

16-
assert response.status_code == 200
16+
assert response.status_code == 200

app/dashboard/tests/views/test_bounty_payout.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import pytest
2-
from dashboard.tests.factories.profile_factory import ProfileFactory
3-
from dashboard.tests.factories.bounty_factory import BountyFactory
4-
from dashboard.tests.factories.fulfillment_factory import FulfillmentFactory
2+
from dashboard.tests.factories import ProfileFactory, BountyFactory, FulfillmentFactory
53
from rest_framework.test import APIClient
64

75

@@ -31,4 +29,4 @@ def test_pays_out_bounty(self, django_user_model):
3129

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

34-
assert response.status_code == 200
32+
assert response.status_code == 200

app/dashboard/tests/views/test_profile_projects.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import pytest
44
from dashboard.models import PortfolioItem
5-
from dashboard.tests.factories.profile_factory import ProfileFactory
5+
from dashboard.tests.factories import ProfileFactory
66

77

88
class TestProfileTabProjectCreation:

app/grants/management/commands/cy_create_grants.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from django.core.management.base import BaseCommand
44

5-
from grants.tests.models.factories.grant_factory import GrantFactory
5+
from grants.tests.factories import GrantFactory
66

77

88
class Command(BaseCommand):

0 commit comments

Comments
 (0)