コード例 #1
0
    def test_assign_resources_post_save_project(self):
        # PREPARE DATA
        self.do_token_login()
        sections = list(settings.RESOURCE_CH_SECTIONS)
        project_types = list(settings.RESOURCE_CH_TYPE_PROJECT)

        for section_type, section_name in sections:
            FakeResourceFactory.create(sections=section_type)

        for project_type, project_name in project_types:
            new_project_uuid = faker.uuid4()
            data = {
                'uuid': new_project_uuid,
                'type_project_lower': project_name
            }
            url_api = reverse('api:resources:post-save-project')

            # DO ACTION
            response = self.client.post(url_api, data=data)

            # ASSERTS
            self.assertTrue(status.is_success(response.status_code))
            resource = Resource.objects.filter_by_section(
                settings.RESOURCE_RELATION_TYPES_AND_SECTIONS[project_type]
            ).get()
            self.assertTrue(new_project_uuid in resource.project_list)
コード例 #2
0
class FakeCertificationRequestFactory(django.DjangoModelFactory):
    class Meta:
        model = CertificationRequest

    user = factory.SubFactory(FakeUserFactory)
    payment_uuid = factory.LazyAttribute(lambda x: faker.uuid4())
    payment_url = factory.LazyAttribute(lambda x: faker.uri())
    coupon = factory.SubFactory(FakeCouponFactory)
    price = factory.LazyAttribute(lambda x: faker.numerify())
コード例 #3
0
    def test_payemnts_service_notify_invalid_payment(self):
        # PREPARE DATA
        self.client.credentials(HTTP_USERNAME=settings.AUTH_SECRET_KEY)
        url = reverse(
            'api:exo-certification:webhooks-detail',
            kwargs={'pk': faker.uuid4()}
        )

        # DO ACTION
        response = self.client.put(url, data=self.prepare_notify_webhook())

        # ASSERTIONS
        self.assertTrue(status.is_client_error(response.status_code))
コード例 #4
0
    def test_add_uuid_from_resource_projects(self):
        # PREPARE DATA
        uuid_project = faker.uuid4()
        resource = FakeResourceFactory.create()
        url = reverse("api:resources:library-add-to-projects",
                      kwargs={'pk': resource.pk})

        # DO ACTION
        response = self.client.put(url, data={'uuid': uuid_project})
        resource.refresh_from_db()
        # ASSERTS
        self.assertTrue(status.is_success(response.status_code))
        self.assertTrue(uuid_project in response.data.get('projects'))
        self.assertTrue(resource.projects)
コード例 #5
0
class FakeProjectFactory(django.DjangoModelFactory):
    class Meta:
        model = Project

    uuid = factory.LazyAttribute(lambda x: faker.uuid4())
    name = factory.LazyAttribute(lambda x: faker.word())
    description = factory.LazyAttribute(lambda x: faker.text())
    start = factory.LazyAttribute(
        lambda x: faker.date_time(tzinfo=string_to_timezone('utc')))
    location = factory.LazyAttribute(
        lambda x: '{}, {}'.format(faker.city(), faker.country()))
    status = settings.PROJECT_CH_STATUS_DRAFT
    content_template = settings.PROJECT_CH_PROJECT_TEMPLATE_DEFAULT
    customer = factory.LazyAttribute(lambda x: faker.company())

    @classmethod
    def _create(cls, model_class, *args, **kwargs):
        """Override the default ``_create`` with our custom call."""
        manager = cls._get_manager(model_class)
        if not kwargs.get('created_by'):
            raise Exception('User is required')
        return manager.create_project(*args, **kwargs)
コード例 #6
0
    def test_resource_filter_by_projects(self):
        # PREPARE DATA
        size_with_uuid = 10
        size_without_uuid = 5
        uuid_project = faker.uuid4()
        url = reverse("api:resources:library-project-list")
        FakeResourceFactory.create_batch(
            size=size_with_uuid,
            status=settings.RESOURCE_CH_STATUS_AVAILABLE,
            projects=str(uuid_project))
        FakeResourceFactory.create_batch(
            size=size_without_uuid,
            status=settings.RESOURCE_CH_STATUS_AVAILABLE,
            projects='')
        self.do_token_login()

        # DO ACTION
        response = self.client.get(url, data={'projects': uuid_project})

        # ASSERTS
        self.assertTrue(status.is_success(response.status_code))
        self.assertEqual(response.data.get('count'), size_with_uuid)