-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unit test for UserCanMakeCompanyView
- Loading branch information
Showing
3 changed files
with
47 additions
and
6 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,23 +6,35 @@ | |
|
||
@pytest.fixture | ||
def user(): | ||
return UserAccount.objects.create_user( | ||
return UserAccount.objects.create( | ||
first_name="John", | ||
last_name="Doe", | ||
email="[email protected]", | ||
password="XXXXXXXXXXX", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def user_second(): | ||
return UserAccount.objects.create_user( | ||
return UserAccount.objects.create( | ||
first_name="Jane", | ||
last_name="Doe", | ||
email="[email protected]", | ||
password="XXXXXXXXXXX", | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def user_no_available_companies(): | ||
return UserAccount.objects.create( | ||
first_name="John", | ||
last_name="Doe", | ||
email="[email protected]", | ||
password="XXXXXXXXXXX", | ||
num_of_available_companies=0 | ||
) | ||
|
||
|
||
@pytest.fixture | ||
def job_offer(user): | ||
return JobOffer.objects.create( | ||
|
@@ -44,4 +56,4 @@ def job_offer_with_company(user, company): | |
return JobOffer.objects.create( | ||
title="Test Job Offer", | ||
company=company | ||
) | ||
) |
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 |
---|---|---|
@@ -1 +1,30 @@ | ||
import pytest | ||
from tests.fixtures import user, user_no_available_companies | ||
from rest_framework.test import force_authenticate, APIRequestFactory | ||
from company.views import UserCanMakeCompanyView | ||
|
||
factory = APIRequestFactory() | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_success_check_if_user_is_able_to_create_company_return_true(user): | ||
view = UserCanMakeCompanyView.as_view() | ||
|
||
request = factory.get('/api/company/user/check/new') | ||
force_authenticate(request, user=user) | ||
response = view(request) | ||
|
||
assert response.status_code == 200 | ||
assert response.data["info"] == "true" | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_success_check_if_user_is_not_able_to_create_company_return_false(user_no_available_companies): | ||
view = UserCanMakeCompanyView.as_view() | ||
|
||
request = factory.get('/api/company/user/check/new') | ||
force_authenticate(request, user=user_no_available_companies) | ||
response = view(request) | ||
|
||
assert response.status_code == 200 | ||
assert response.data["info"] == "false" |