Skip to content

Commit

Permalink
Write tests and small fixes
Browse files Browse the repository at this point in the history
Wrote tests that check the permissions of the user requesting and other small fixes as requested in the pr conversations
  • Loading branch information
Arash Farzaneh Taleghani committed Mar 6, 2023
1 parent bbd0302 commit 800b71c
Show file tree
Hide file tree
Showing 4 changed files with 231 additions and 136 deletions.
22 changes: 22 additions & 0 deletions lego/apps/companies/constants.py
Expand Up @@ -96,6 +96,17 @@ class COMPANY_TYPES(models.TextChoices):
GOVERNMENTAL = "company_types_governmental"


TRANSLATED_COMPANY_TYPES = {
COMPANY_TYPES.SMALL_CONSULTANT: "Liten Konsulentbedrift",
COMPANY_TYPES.MEDIUM_CONSULTANT: "Medium konsulentbedrift",
COMPANY_TYPES.LARGE_CONSULTANT: "Stor konsulentbedrift",
COMPANY_TYPES.INHOUSE: "Inhouse",
COMPANY_TYPES.TYPES_OTHERS: "Annet",
COMPANY_TYPES.START_UP: "Start-up",
COMPANY_TYPES.GOVERNMENTAL: "Statlig",
}


class COMPANY_COURSE_THEMES(models.TextChoices):
SECURITY = "company_survey_security"
AI = "company_survey_ai"
Expand All @@ -107,6 +118,17 @@ class COMPANY_COURSE_THEMES(models.TextChoices):
FINTECH = "company_survey_fintech"


TRANSLATED_COURSE_THEMES = {
COMPANY_COURSE_THEMES.SECURITY: "Sikkerhet",
COMPANY_COURSE_THEMES.AI: "Kunstlig intellligens",
COMPANY_COURSE_THEMES.DATA: "Big data",
COMPANY_COURSE_THEMES.END: "Front end/Back end",
COMPANY_COURSE_THEMES.IOT: "Internet of things",
COMPANY_COURSE_THEMES.GAMEDEV: "Spillutvikling",
COMPANY_COURSE_THEMES.SOFTSKILLS: "Softskills",
COMPANY_COURSE_THEMES.FINTECH: "Finansiell teknologi",
}

CONTACT_IN_OSLO = "contact_in_oslo"
INTERESTED = "interested"
NOT_INTERESTED = "not_interested"
Expand Down
62 changes: 28 additions & 34 deletions lego/apps/companies/fixtures/test_company_interest.yaml
@@ -1,66 +1,60 @@
- model: companies.Semester
pk: 1
fields:
semester: 'spring'
semester: "spring"
year: 2017

- model: companies.Semester
pk: 2
fields:
semester: 'autumn'
semester: "autumn"
year: 2017

- model: companies.Semester
pk: 3
fields:
semester: 'spring'
semester: "spring"
year: 2018

- model: companies.Semester
pk: 4
fields:
semester: 'autumn'
semester: "autumn"
year: 2018

- model: companies.CompanyInterest
pk: 1
fields:
company_name: 'BEKK'
contact_person: 'Bekksen'
mail: 'bekk@bekksen.no'
semesters: [1,4]
events: [
'company_presentation',
'course',
'lunch_presentation',
'breakfast_talk',
]
other_offers: ['labamba_sponsor']
comment: 'webkom webkom'
company_name: "BEKK"
contact_person: "Bekksen"
mail: "bekk@bekksen.no"
semesters: [1, 4]
company_type: "company_types_inhouse"
events:
["company_presentation", "course", "lunch_presentation", "breakfast_talk"]
other_offers: ["labamba_sponsor"]
comment: "webkom webkom"

- model: companies.CompanyInterest
pk: 2
fields:
company_name: 'Itera'
contact_person: 'Iteraz'
mail: 'bekk@itera.no'
company_name: "Itera"
contact_person: "Iteraz"
mail: "bekk@itera.no"
semesters: [1, 2, 3, 4]
events: [
'company_presentation',
'course',
'breakfast_talk',
]
other_offers: ['itdagene']
comment: 'webkom webkom webkom'
company_type: "company_types_inhouse"
events: ["company_presentation", "course", "breakfast_talk"]
other_offers: ["itdagene"]
comment: "webkom webkom webkom"

- model: companies.CompanyInterest
pk: 1
fields:
company_name: 'Capra'
contact_person: 'Caprius'
mail: 'caprius@capra.no'
semesters: [2,3]
events: ['bedex', 'other']
other_offers: ['collaboration', 'readme']
comment: 'webkom'

company_name: "Capra"
contact_person: "Caprius"
mail: "caprius@capra.no"
semesters: [2, 3]
company_type: "company_types_inhouse"
events: ["bedex", "other"]
other_offers: ["collaboration", "readme"]
comment: "webkom"
35 changes: 35 additions & 0 deletions lego/apps/companies/tests/test_company_interest.py
Expand Up @@ -49,6 +49,11 @@ def _get_detail_company_interest(pk):
return reverse("api:v1:company-interest-detail", kwargs={"pk": pk})


def _get_export_company_interest():

return reverse("api:v1:company-interest-csv")


class ListCompanyInterestTestCase(BaseAPITestCase):
fixtures = [
"test_abakus_groups.yaml",
Expand All @@ -74,6 +79,36 @@ def test_list_with_bedkom_user(self):
self.assertEqual(company_interest_list_response.status_code, status.HTTP_200_OK)
self.assertTrue(len(company_interest_list_response.json()["results"]))

def test_export_to_csv_with_abakus_user(self):
AbakusGroup.objects.get(name="Abakus").add_user(self.abakus_user)
self.client.force_authenticate(self.abakus_user)
company_interest_export_responce = self.client.get(
_get_export_company_interest()
)
self.assertEqual(
company_interest_export_responce.status_code, status.HTTP_403_FORBIDDEN
)

def test_export_to_csv_with_bedkom_user(self):
AbakusGroup.objects.get(name="Bedkom").add_user(self.abakus_user)
self.client.force_authenticate(self.abakus_user)
company_interest_export_responce = self.client.get(
f"{_get_export_company_interest()}?year=2017&semester=autumn"
)
self.assertEqual(
company_interest_export_responce.status_code, status.HTTP_200_OK
)

def test_export_to_csv_with_missing_query_parameters(self):
AbakusGroup.objects.get(name="Bedkom").add_user(self.abakus_user)
self.client.force_authenticate(self.abakus_user)
company_interest_export_responce = self.client.get(
_get_export_company_interest()
)
self.assertEqual(
company_interest_export_responce.status_code, status.HTTP_400_BAD_REQUEST
)


class CreateCompanyInterestTestCase(BaseAPITestCase):
fixtures = [
Expand Down

0 comments on commit 800b71c

Please sign in to comment.