示例#1
0
    def setUp(self):
        self.company = CompanyFactory(
            name='Kulfun Games',
            slug='kulfun-games',
        )

        self.company2 = CompanyFactory(
            name='Acme Corp',
            slug='acme-corp',
        )
        self.job_category = JobCategoryFactory(
            name='Game Production',
            slug='game-production'
        )

        self.job_type = JobTypeFactory(
            name='FrontEnd Developer',
            slug='frontend-developer'
        )

        self.job = ApprovedJobFactory(
            company=self.company,
            description='Lorem ipsum dolor sit amet',
            category=self.job_category,
            city='Memphis',
            region='TN',
            country='USA',
            email='*****@*****.**',
            is_featured=True
        )
        self.job.job_types.add(self.job_type)
示例#2
0
    def setUpTestData(cls):
        """
        Initialize the class by populating the database.

        Some notes:
          - The 'ignored' company is to make a clear difference in the
            response for management and members of a company.
        """

        cls.company = CompanyFactory()
        cls.ignored = CompanyFactory()

        cls.external = UserFactory(group=Group.objects.create(name="external"))
        cls.employer = UserFactory(group=Group.objects.get(id=Groups.employer))
        cls.employee = UserFactory(group=Group.objects.get(id=Groups.employee))

        cls.external_token = AuthFactory(user=cls.external)
        cls.employer_token = AuthFactory(user=cls.employer)
        cls.employee_token = AuthFactory(user=cls.employee)

        MemberFactory(account=cls.employer, company=cls.company)
        MemberFactory(account=cls.employee, company=cls.company)

        cls.management = UserFactory(group=Group.objects.get(
            id=Groups.management))

        cls.administrator = UserFactory(group=Group.objects.get(
            id=Groups.admin))

        cls.management_token = AuthFactory(user=cls.management)
        cls.administrator_token = AuthFactory(user=cls.administrator)
示例#3
0
    def setUpTestData(cls):
        employer_group = Group.objects.get(id=Groups.employer)
        employee_group = Group.objects.get(id=Groups.employee)
        managing_group = Group.objects.get(id=Groups.management)

        cls.companyA = CompanyFactory()
        cls.companyB = CompanyFactory()

        cls.employerA = UserFactory(group=employer_group)
        cls.employeeA = UserFactory(group=employee_group)

        cls.employerB = UserFactory(group=employer_group)
        cls.employeeB = UserFactory(group=employee_group)

        cls.management = UserFactory(group=managing_group)

        cls.employee_a_token = AuthFactory(user=cls.employeeA)
        cls.employer_a_token = AuthFactory(user=cls.employerA)
        cls.employee_b_token = AuthFactory(user=cls.employeeB)
        cls.employer_b_token = AuthFactory(user=cls.employerB)
        cls.management_token = AuthFactory(user=cls.management)

        MemberFactory(account=cls.employerA, company=cls.companyA)
        MemberFactory(account=cls.employeeA, company=cls.companyA)
        MemberFactory(account=cls.employerB, company=cls.companyB)
        MemberFactory(account=cls.employeeB, company=cls.companyB)
示例#4
0
def do_test_company_listing(client: APIClient, batch_size=5):
    CompanyFactory.create_batch(batch_size)

    resp = client.get(client.reverse('company-list'))
    validate_jsonapi_list_response(
        resp,
        expected_count=batch_size,
        expected_attributes=ATTRIBUTES_LIST,
        expected_relationships=RELATIONSHIPS_LIST,
    )
示例#5
0
    def setUpTestData(cls):
        cls.company = CompanyFactory()
        cls.ignored = CompanyFactory()

        cls.employer = UserFactory(group=Group.objects.get(id=Groups.employer))
        cls.employee = UserFactory(group=Group.objects.get(id=Groups.employee))
        cls.managing = UserFactory(group=Group.objects.get(
            id=Groups.management))

        cls.employee_token = AuthFactory(user=cls.employee)
        cls.employer_token = AuthFactory(user=cls.employer)
        cls.managing_token = AuthFactory(user=cls.managing)

        MemberFactory(account=cls.employer, company=cls.company)
        MemberFactory(account=cls.employee, company=cls.company)
示例#6
0
    def setUp(self):

        self.super_username = '******'
        self.super_email = '*****@*****.**'
        self.super_password = '******'

        self.creator_username = '******'
        self.creator_email = '*****@*****.**'
        self.creator_password = '******'
        self.contact = 'John Doe'

        User = get_user_model()
        self.creator = User.objects.create_user(self.creator_username,
                                                self.creator_email,
                                                self.creator_password)

        self.superuser = User.objects.create_superuser(self.super_username,
                                                       self.super_email,
                                                       self.super_password)

        self.company = CompanyFactory(name='Kulfun Games', slug='kulfun-games')

        self.job_category = JobCategoryFactory(name='Game Production',
                                               slug='game-production')

        self.job_type = JobTypeFactory(name='FrontEnd Developer',
                                       slug='frontend-developer')

        self.job1 = ReviewJobFactory(company=self.company,
                                     description='Lorem ipsum dolor sit amet',
                                     category=self.job_category,
                                     city='Memphis',
                                     region='TN',
                                     country='USA',
                                     email=self.creator.email,
                                     creator=self.creator,
                                     contact=self.contact)
        self.job1.job_types.add(self.job_type)

        self.job2 = ReviewJobFactory(company=self.company,
                                     description='Lorem ipsum dolor sit amet',
                                     category=self.job_category,
                                     city='Memphis',
                                     region='TN',
                                     country='USA',
                                     email=self.creator.email,
                                     creator=self.creator,
                                     contact=self.contact)
        self.job2.job_types.add(self.job_type)

        self.job3 = ReviewJobFactory(company=self.company,
                                     description='Lorem ipsum dolor sit amet',
                                     category=self.job_category,
                                     city='Memphis',
                                     region='TN',
                                     country='USA',
                                     email=self.creator.email,
                                     creator=self.creator,
                                     contact=self.contact)
        self.job3.job_types.add(self.job_type)
示例#7
0
    def test_create_employees(self):
        self.user.groups.add(Group.objects.get(id=2))

        company = CompanyFactory()
        members = ["*****@*****.**", "*****@*****.**"]
        content = {"company": company.id, "members": members}

        response = self.client.post(reverse("register-employees"), content)

        self.assertEqual(response.status_code, status.HTTP_201_CREATED)
        self.assertEqual(len(mail.outbox), 2)

        self.user.groups.
示例#8
0
def test_companies_update(employment: Employment):
    assert employment.role == Employment.ROLE_ADMIN
    user = employment.user
    company = employment.company

    client = APIClient()
    client.force_authenticate(user)

    other_company = CompanyFactory.create()

    patch_data = {
        "data": {
            "type": "company",
            "id": str(company.id),
            "attributes": {},
        },
    }

    # Part one - update the company where the user is admin
    new_name = 'new name'
    updated = company.updated
    assert company.name != new_name
    patch_data['data']['attributes'] = {'name': new_name}
    resp = client.patch(client.reverse('company-detail', pk=company.pk),
                        patch_data)
    validate_jsonapi_detail_response(
        resp,
        expected_attributes=ATTRIBUTES_FULL,
        expected_relationships=RELATIONSHIPS_FULL,
    )
    refreshed_company = Company.objects.get(id=company.id)
    assert refreshed_company.name == new_name
    assert refreshed_company.updated > updated

    # Part two - PUT should not be allowed
    resp = client.put(client.reverse('company-detail', pk=company.pk),
                      patch_data)
    validate_jsonapi_error_response(resp, expected_status_code=405)

    # Part three - updating is only allowed for admins, so it should fail after user is demoted to non-admin
    employment.role = Employment.ROLE_NORMAL
    employment.save()
    resp = client.patch(client.reverse('company-detail', pk=company.pk),
                        patch_data)
    validate_jsonapi_error_response(resp, expected_status_code=403)

    # Part four - try to patch company where we don't have permissions
    patch_data['data']['id'] = str(other_company.id)
    resp = client.patch(client.reverse('company-detail', pk=other_company.pk))
    validate_jsonapi_error_response(resp, expected_status_code=403)
示例#9
0
def generate_company(employers=1, employees=15):  # pragma: no cover
    company = CompanyFactory()

    ColourThemeFactory(company=company)

    employer = Group.objects.get(id=Groups.employer)
    employee = Group.objects.get(id=Groups.employee)

    for i in range(0, employers):
        account = UserFactory(group=employer)
        MemberFactory(account=account, company=company)

    for i in range(0, employees):
        account = UserFactory(group=employee)
        MemberFactory(account=account, company=company)

    return company
示例#10
0
def other_company():
    return CompanyFactory.create()
示例#11
0
def company():
    return CompanyFactory.create()