-
-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding tests for creating projects on portfolio page (#9553)
* adding tests for creating projects on portfolio page * update test function name * set http to empty string in URL field * test now to a point we can make the change * ads unique contraint over title, link, and profile * revert change to default tab and change whitespace in test * update migrations Co-authored-by: Kevin Solorio <[email protected]>
- Loading branch information
Showing
8 changed files
with
109 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 2.2.24 on 2021-10-01 19:05 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('dashboard', '0188_remove_profile_tribe_priority'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddConstraint( | ||
model_name='portfolioitem', | ||
constraint=models.UniqueConstraint(fields=('profile', 'title', 'link'), name='unique_title_link_per_profile'), | ||
), | ||
] |
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
Empty file.
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,67 @@ | ||
from django.test import Client | ||
|
||
import pytest | ||
from dashboard.models import PortfolioItem | ||
from dashboard.tests.factories.profile_factory import ProfileFactory | ||
|
||
|
||
class TestProfileTabProjectCreation: | ||
def test_project_creation_fails_when_url_does_not_start_with_http(self, django_user_model): | ||
user = django_user_model.objects.create(username="gitcoin", password="password123") | ||
project_data = dict(project_title="My New Project", URL="gitcoin.co", tags="") | ||
ProfileFactory(user=user, handle="gitcoin", hide_profile=False) | ||
|
||
client = Client(HTTP_USER_AGENT='chrome') | ||
client.force_login(user) | ||
response = client.post('/gitcoin/portfolio', project_data) | ||
messages = [m.message for m in response.context['messages']] | ||
|
||
assert response.status_code == 200 | ||
assert "Invalid link." in messages | ||
assert "Portfolio Item added." not in messages | ||
|
||
def test_project_creation_fails_when_not_logged_in(self, django_user_model): | ||
user = django_user_model.objects.create(username="gitcoin", password="password123") | ||
project_data = dict(project_title="My New Project", URL="https://gitcoin.co", tags="") | ||
ProfileFactory(user=user, handle="gitcoin", hide_profile=False) | ||
|
||
client = Client(HTTP_USER_AGENT='chrome') | ||
response = client.post('/gitcoin/portfolio', project_data) | ||
messages = [m.message for m in response.context['messages']] | ||
|
||
assert response.status_code == 200 | ||
assert "Not Authorized" in messages | ||
assert "Portfolio Item added." not in messages | ||
|
||
def test_project_created(self, django_user_model): | ||
user = django_user_model.objects.create(username="gitcoin", password="password123") | ||
project_data = dict(project_title="My New Project", URL="http://gitcoin.co", tags="") | ||
ProfileFactory(user=user, handle="gitcoin", hide_profile=False) | ||
|
||
client = Client(HTTP_USER_AGENT='chrome') | ||
client.force_login(user) | ||
response = client.post('/gitcoin/portfolio', project_data) | ||
messages = [m.message for m in response.context['messages']] | ||
|
||
assert response.status_code == 200 | ||
assert "Portfolio Item added." in messages | ||
|
||
@pytest.mark.django_db(transaction=True) | ||
def test_project_creation_fails_when_project_already_exists(self, django_user_model): | ||
user = django_user_model.objects.create(username="gitcoin", password="password123") | ||
project_data = dict(project_title="My New Project", URL="http://gitcoin.co", tags="") | ||
profile = ProfileFactory(user=user, handle="gitcoin", hide_profile=False) | ||
PortfolioItem.objects.create( | ||
profile=profile, | ||
title=project_data['project_title'], | ||
link=project_data['URL'], | ||
tags=[] | ||
) | ||
|
||
client = Client(HTTP_USER_AGENT='chrome') | ||
client.force_login(user) | ||
response = client.post('/gitcoin/portfolio', project_data) | ||
messages = [m.message for m in response.context['messages']] | ||
|
||
assert response.status_code == 200 | ||
assert "Portfolio Already Exists." in messages |
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