Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
29895fd
Added pytest as a runner
skalanux Nov 1, 2021
4e9cc7c
Added pytest as a runner on Makefile
skalanux Nov 1, 2021
6c4ac36
Added joboffers app
skalanux Nov 1, 2021
df131a9
Some fixes to the JobOffer model
skalanux Nov 2, 2021
ef2d0eb
Added initial joboffer detail
germanp Nov 3, 2021
2c5eb45
Added initial job offer add form
germanp Nov 4, 2021
2fc23d9
Changed joboffer's urls to use their namespace
germanp Nov 5, 2021
30766da
Added some basic pytest's fixtures
germanp Nov 5, 2021
897d8b5
Updated JobOffer's factory to include all the needed fields
germanp Nov 5, 2021
c2cf432
Added joboffer creation test
germanp Nov 5, 2021
1afda83
Added joboffer admin page
germanp Nov 9, 2021
132ae04
Moved add button to bottom of the page (joboffers)
germanp Nov 10, 2021
8532aa3
Added search button in admin page (joboffers)
germanp Nov 10, 2021
10c34c3
Merge branch 'master' of github.com:PyAr/pyarweb
germanp Nov 10, 2021
02c6a4e
Added joboffer edit view
germanp Nov 11, 2021
44a3e60
Merge branch 'master' of github.com:PyAr/pyarweb
germanp Nov 16, 2021
bc63463
Changed joboffer's choices to their long version
germanp Nov 25, 2021
0f17870
Merge branch 'PyAr:master' into master
germanp Nov 30, 2021
2a929ad
Merge branch 'PyAr:master' into master
germanp Dec 13, 2021
3cc96a3
Merge branch 'PyAr:master' into master
germanp Dec 23, 2021
2b8954a
Merge branch 'PyAr:master' into master
germanp Jan 3, 2022
383e794
Merge branch 'PyAr:master' into master
germanp Jan 10, 2022
7e4d5a2
Merge branch 'PyAr:master' into master
germanp Jan 13, 2022
c8dce89
Merge branch 'PyAr:master' into master
skalanux Jan 21, 2022
7eb809a
Merge branch 'PyAr:master' into master
germanp Jan 24, 2022
8994f06
Merge branch 'PyAr:master' into master
germanp Jan 25, 2022
d96b2b1
Merge branch 'PyAr:master' into master
germanp Jan 26, 2022
ce4bbeb
Merge branch 'PyAr:master' into master
IanPuchetti Feb 2, 2022
bc3553b
Merge branch 'PyAr:master' into master
germanp Feb 8, 2022
6a7577b
Merge branch 'PyAr:master' into master
germanp Feb 15, 2022
5a2e76c
Merge branch 'PyAr:master' into master
skalanux Feb 21, 2022
f13235a
Merge branch 'PyAr:master' into master
skalanux Feb 21, 2022
119af8c
Merge branch 'PyAr:master' into master
skalanux Feb 22, 2022
08fb7c7
Merge branch 'PyAr:master' into master
skalanux Mar 7, 2022
b814814
Merge branch 'PyAr:master' into master
germanp Mar 11, 2022
eec0ead
Merge branch 'PyAr:master' into master
skalanux Mar 16, 2022
8f7c3af
Merge branch 'PyAr:master' into master
skalanux Apr 7, 2022
94b3daf
Merge branch 'PyAr:master' into master
germanp Apr 18, 2022
44cddb9
Merge branch 'PyAr:master' into master
germanp Apr 21, 2022
1330e84
Merge branch 'PyAr:master' into master
germanp Apr 21, 2022
7c60055
Merge branch 'PyAr:master' into master
germanp Apr 21, 2022
fb128e7
Merge branch 'PyAr:master' into master
germanp May 6, 2022
ee42f0a
Merge branch 'PyAr:master' into master
germanp May 17, 2022
9334040
Merge branch 'PyAr:master' into master
germanp Jun 2, 2022
91c22b7
Merge branch 'PyAr:master' into master
germanp Jun 7, 2022
ae2b3cf
Merge branch 'PyAr:master' into master
germanp Jun 15, 2022
c44a897
Merge branch 'PyAr:master' into master
germanp Jun 21, 2022
431199a
Merge branch 'PyAr:master' into master
germanp Jun 28, 2022
f8eb983
Merge branch 'PyAr:master' into master
germanp Jul 5, 2022
6ed745d
Fixed permission issue for analytics button on company detail view
germanp Jul 7, 2022
4af7945
Removed company's owner field
germanp Jul 7, 2022
824b59b
Implemented company association when creating and the related pemissions
germanp Jul 8, 2022
1294918
Fixed formatting issues
germanp Jul 8, 2022
8c82ffd
Merge branch 'PyAr:master' into master
germanp Jul 11, 2022
880addf
Merge branch 'PyAr:master' into master
germanp Jul 14, 2022
e2b5a09
Merge branch 'master' into 63-cambiar-el-formulario-de-alta-de-empres…
germanp Jul 14, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions jobs/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def setUp(self):

def test_jobs_view_list(self):
job = JobFactory(owner=self.user)
company = CompanyFactory(owner=self.user, rank=3)
company = CompanyFactory(rank=3)
sponsored_job = JobFactory(owner=self.user, company=company)
sponsored_job2 = JobFactory(owner=self.user, company=company)

Expand All @@ -42,11 +42,11 @@ def test_jobs_view_list_with_tags(self):
self.assertEqual(len(response.context["job_list"]), 1)

def test_jobs_view_list_regular_and_sponsored(self):
sponsored_company = CompanyFactory(name='Name', owner=self.user, rank=3)
sponsored_company = CompanyFactory(name='Name', rank=3)
sponsored_job = JobFactory(owner=self.user, company=sponsored_company)
sponsored_job_2 = JobFactory(owner=self.user, company=sponsored_company)

company = CompanyFactory(name='Other name', owner=self.user, rank=0)
company = CompanyFactory(name='Other name', rank=0)
job = JobFactory(owner=self.user, company=company)
job_2 = JobFactory(owner=self.user, company=company)

Expand Down
17 changes: 17 additions & 0 deletions pycompanies/migrations/0004_remove_company_owner.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.13 on 2022-07-07 21:22

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('pycompanies', '0003_usercompanyprofile'),
]

operations = [
migrations.RemoveField(
model_name='company',
name='owner',
),
]
4 changes: 0 additions & 4 deletions pycompanies/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@

class Company(TimeStampedModel):
"""A PyAr Company that use Python."""

owner = models.ForeignKey(settings.AUTH_USER_MODEL,
related_name='companies',
on_delete=models.CASCADE)
name = models.CharField('Nombre', max_length=255, unique=True)
description = models.TextField('Descripción')
photo = models.ImageField('Logo', upload_to='pycompanies/logos')
Expand Down
5 changes: 3 additions & 2 deletions pycompanies/tests/factories.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from factory import Sequence, SubFactory
from factory import Faker, Sequence, SubFactory
from factory.django import DjangoModelFactory, ImageField

from events.tests.factories import UserFactory
Expand All @@ -10,8 +10,9 @@ class Meta:
model = Company

name = Sequence(lambda n: f'company-{n}')
owner = SubFactory(UserFactory)
photo = ImageField(color='blue')
description = Faker('text')
link = Faker('url')
rank = 1


Expand Down
106 changes: 93 additions & 13 deletions pycompanies/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import factory
import pytest

from unittest.mock import patch

from django.contrib.messages import get_messages as contrib_get_messages
from django.urls import reverse

from pycompanies.models import Company, UserCompanyProfile
from pycompanies.views import get_user_display_name
from pycompanies.tests.factories import CompanyFactory, UserCompanyProfileFactory, UserFactory
from joboffers.tests.fixtures import create_admin_client, create_publisher_client # noqa
Expand All @@ -16,8 +18,9 @@
ERROR_USER_DOES_NOT_EXIST = 'Le usuarie que ingresaste no existe.'
USER_ASSOCIATED_CORRECTLY = 'Le usuarie fue asociade correctamente.'

ADMIN_URL = reverse('companies:admin')
COMPANY_LIST_URL = reverse('companies:company_list_all')
ADMIN_URL = 'companies:admin'
LIST_URL = 'companies:company_list_all'
CREATE_URL = 'companies:add'


def get_plain_messages(request):
Expand All @@ -39,8 +42,10 @@ def test_associate_nonexistent_user(logged_client):
response = logged_client.post(ASSOCIATE_URL, data={'username': 'pepito'})
message = get_plain_messages(response)[0]

admin_url = reverse(ADMIN_URL)

assert 302 == response.status_code
assert ADMIN_URL == response.url
assert admin_url == response.url
assert ERROR_USER_DOES_NOT_EXIST == message


Expand All @@ -56,8 +61,10 @@ def test_associate_user_in_company(logged_client, user):
response = logged_client.post(ASSOCIATE_URL, data={'username': user.username})
message = get_plain_messages(response)[0]

admin_url = reverse(ADMIN_URL)

assert 302 == response.status_code
assert ADMIN_URL == response.url
assert admin_url == response.url
assert USER_ASSOCIATED_CORRECTLY == message


Expand All @@ -78,7 +85,7 @@ def test_associate_user_already_in_company(logged_client, user):
message = get_plain_messages(response)[0]

assert 302 == response.status_code
assert ADMIN_URL == response.url
assert reverse(ADMIN_URL) == response.url
assert ERROR_USER_ALREADY_IN_COMPANY == message


Expand All @@ -99,7 +106,7 @@ def test_associate_user_in_other_company(logged_client, user):
message = get_plain_messages(response)[0]

assert 302 == response.status_code
assert ADMIN_URL == response.url
assert reverse(ADMIN_URL) == response.url
assert message == ERROR_USER_IN_OTHER_COMPANY


Expand All @@ -108,7 +115,7 @@ def test_company_admin_with_no_logged_user_should_redirect(client):
"""
Should redirect if the user is not logged
"""
response = client.get(ADMIN_URL)
response = client.get(reverse(ADMIN_URL))

assert 302 == response.status_code

Expand All @@ -118,7 +125,7 @@ def test_company_admin_with_no_company_logged_user_should_redirect(logged_client
"""
Should redirect if the user is logged but not associated to a company
"""
response = logged_client.get(ADMIN_URL)
response = logged_client.get(reverse(ADMIN_URL))

assert 302 == response.status_code

Expand All @@ -131,7 +138,7 @@ def test_company_admin_with_company_logged_user_should_not_redirect(logged_clien
company = CompanyFactory.create(name='company')
UserCompanyProfileFactory.create(company=company, user=user)

response = logged_client.get(ADMIN_URL)
response = logged_client.get(reverse(ADMIN_URL))

assert 200 == response.status_code

Expand Down Expand Up @@ -227,13 +234,17 @@ def test_company_disassociate_one_user_from_company(logged_client, user):


@pytest.mark.django_db
def test_company_detail_doesnt_show_analytics_button_for_normal_user(logged_client):
def test_company_detail_doesnt_show_analytics_button_for_normal_user(user, logged_client):
"""
Test that the company page doesn't show the analytics button for authenticated users that
doesn't belong to the current company
"""
logged_user = user
client = logged_client
company = CompanyFactory.create(name='company_1')
UserCompanyProfileFactory.create(company=company)
# Associate the logged user to another company to cover this also that case
UserCompanyProfileFactory.create(user=logged_user)

target_url = reverse('companies:detail', kwargs={'pk': company.id})

Expand Down Expand Up @@ -338,6 +349,75 @@ def test_render_company_analytics_ok(
assert table_views == expected_table_views


@pytest.mark.django_db
def test_company_create_view_GET_doesnt_allow_creation_of_company_for_logged_user_with_company(
user, logged_client
):
"""
Test that the company create GET doesn't allow creation of multiple companies for GET
"""
client = logged_client
UserCompanyProfileFactory.create(user=user)

response = client.get(reverse(CREATE_URL))

assert response.status_code == 403


@pytest.mark.django_db
def test_company_create_view_POST_doesnt_allow_creation_of_company_for_logged_user_with_company(
user, logged_client
):
"""
Test that the company create POST doesn't allow creation of multiple companies
"""
client = logged_client
UserCompanyProfileFactory.create(user=user)

response = client.post(reverse(CREATE_URL))

assert response.status_code == 403


@pytest.mark.django_db
def test_company_list_view_includes_own_company_for_logged_user_with_company(
user, logged_client
):
"""
Test that the company list view does not includes own_company for user with company created
(Doesn't allow creation of multiple companies)
"""
client = logged_client
UserCompanyProfileFactory.create(user=user)

target_url = reverse(LIST_URL)

response = client.get(target_url)
assert 'own_company' in response.context_data


@pytest.mark.django_db
def test_create_company_associates_the_user_to_a_company(user, logged_client):
"""
Test that company creation associates the logged user to that company
"""
client = logged_client
target_url = reverse(CREATE_URL)

company_data = factory.build(
dict,
FACTORY_CLASS=CompanyFactory
)

assert Company.objects.count() == 0

response = client.post(target_url, company_data, format="multipart")

assert response.status_code == 302
assert Company.objects.count() == 1
assert UserCompanyProfile.objects.for_user(user=user)


def test_get_user_display_name_without_first_name_and_last_name():
"""
Test return for an user without first_name and last_name
Expand Down Expand Up @@ -385,7 +465,7 @@ def test_company_list_view_includes_user_and_own_company_for_publisher(publisher
"""
client = publisher_client

response = client.get(COMPANY_LIST_URL)
response = client.get(reverse(LIST_URL))

assert response.context_data['user'].is_authenticated
assert 'own_company' in response.context_data
Expand All @@ -399,7 +479,7 @@ def test_company_list_view_includes_user_and_own_company_for_user_without_compan
"""
client = logged_client

response = client.get(COMPANY_LIST_URL)
response = client.get(reverse(LIST_URL))

assert response.context_data['user'].is_authenticated
assert 'own_company' not in response.context_data
Expand All @@ -411,7 +491,7 @@ def test_company_list_view_includes_user_and_own_company_for_unlogged_user(clien
Test that the company list view includes user and own_company for anonymous user
"""

response = client.get(COMPANY_LIST_URL)
response = client.get(reverse(LIST_URL))

assert response.context_data['user'].is_anonymous
assert 'own_company' not in response.context_data
22 changes: 18 additions & 4 deletions pycompanies/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)

user = self.request.user
company = self.object

if UserCompanyProfile.objects.for_user(user=user) or user.is_superuser:
if UserCompanyProfile.objects.for_user(user=user, company=company) or user.is_superuser:
context['can_view_analytics'] = True
else:
context['can_view_analytics'] = False
Expand All @@ -52,7 +53,7 @@ def get_context_data(self, **kwargs):
context['user'] = self.request.user

user_company = UserCompanyProfile.objects.for_user(user=self.request.user)
if self.request.user.is_anonymous is False and user_company:
if user_company:
context['own_company'] = user_company.company
return context

Expand All @@ -63,9 +64,22 @@ class CompanyCreateView(LoginRequiredMixin, CreateView):
success_url = '/empresas/'
template_name = 'companies/company_form.html'

def dispatch(self, request, *args, **kwargs):
user = self.request.user
company_profile = UserCompanyProfile.objects.for_user(user=user)

if company_profile:
raise PermissionDenied

return super().dispatch(request, *args, **kwargs)

def form_valid(self, form):
form.instance.owner = self.request.user
return super().form_valid(form)
response = super().form_valid(form)
company = form.instance
user = self.request.user
UserCompanyProfile.objects.create(user=user, company=company)

return response


class CompanyUpdateView(LoginRequiredMixin, OwnedObject, UpdateView):
Expand Down