Example #1
0
def add_projectt():

    project = Project(description="description", user_id=1, status=ProjectStatus.active)
    db.session.add(project)
    db.session.commit()
    db.reflect()
    db.drop_all()

    return jsonify(project.serialize())
Example #2
0
 def create_project(self):
     organization = Organization.objects.get(
         slug=self.user1_params["organization_slug"]
     )
     user = MljarUser.objects.get(email=self.user1_params["email"])
     project = Project(
         title="some title",
         description="...",
         created_by=user,
         parent_organization=organization,
     )
     project.save()
     return project
    def test_project_created(self, project_created):
        """Ensure that the `project_created` task is run with the correct arguments when a new Project object is created
        and saved.
        """
        project = Project(name='Test Project',
                          authors=['Author 1'],
                          description='Project description.',
                          status=Project.ProjectStatus.PLANNED)
        project.save()

        self.assertTrue(project_created.called)
        self.assertEqual(project.name, project_created.call_args[0][0])
        self.assertEqual(project.authors, project_created.call_args[0][1])
        self.assertEqual(project.description, project_created.call_args[0][2])
        self.assertEqual(project.url, project_created.call_args[0][3])
Example #4
0
    def post(self):
        json_data = request.get_json()
        result = ProjectCreateSchema().load(json_data)

        if result.errors:
            return jsonify(result.errors), 403

        project = Project()
        parse_json_to_object(project, result.data)
        project.owner = current_identity

        db.session.add(project)
        db.session.commit()

        data = ProjectSchema().dump(project).data
        return jsonify(data)
Example #5
0
def exist_a_project(step):
    for project in step.hashes:
        Project(**project).save()
        file_name = step.hashes[0]['logo'].split('/')[-1]
        shutil.copy2(os.path.join(settings.PROJECT_ROOT_PATH, 'apps', 'projects',
                                'features', 'resources', file_name),
                   os.path.join(settings.MEDIA_ROOT, 'test', 'images', 'projects'))
Example #6
0
 def post(self, request, *args, **kwargs):
     fill_form = VacancyRegistrationForm(request.POST or None, request.FILES)
     project = Project.get_by_name(request.GET['groupName'])
     if fill_form.try_save_vacancy(request.user, project):
         return JsonResponse(self.json_answer_if_success())
     else:
         return JsonResponse(self.json_answer_if_fail(request, fill_form))
 def setUpTestData(cls):
     """Set up the test data for the test case once when the test case class is being prepared to run.
     """
     cls.project = Project(name='Test Project',
                           authors=['Author 1', 'Author 2'],
                           description='Project description.',
                           status=Project.ProjectStatus.PLANNED)
     cls.project.save()
Example #8
0
 def get(self, request, *args, **kwargs):
     group_name = request.GET['groupName']
     project = Project.get_by_name(request.GET['groupName'])
     starting_values = Membership.all_active_workers(project)
     c = self.init_context(request, group_name, 'Edit members')
     c.update({'formset': self.doc_formset_container(queryset=starting_values),
               'helper': FormSetHelper()})
     return render(request, 'registration/registration_formset.html', c)
Example #9
0
 def post(self, request, *args, **kwargs):
     fill_form = VacancyRegistrationForm(request.POST or None,
                                         request.FILES)
     project = Project.get_by_name(request.GET['groupName'])
     if fill_form.try_save_vacancy(request.user, project):
         return JsonResponse(self.json_answer_if_success())
     else:
         return JsonResponse(self.json_answer_if_fail(request, fill_form))
    def test_status_serializer_method_field(self):
        """Ensure that the project `status` serializer method field has the correct value in an API response.
        """
        url = reverse('project-list')

        response = self.client.get(f'{url}/{self.project.pk}/')
        self.assertEqual(
            Project.ProjectStatus(self.project.status).label,
            response.data['status'])
Example #11
0
    def get_status(self, obj):
        """A get method for the ProjectSerializer class' ``status`` attribute.

        Args:
            obj: The Project object that is being serialized.

        Returns:
            The verbose label associated with the ``status`` of the Project object.
        """
        return Project.ProjectStatus(obj.status).label
    def test_invalid_authors_empty_list(self):
        """Ensure that a ValidationError is raised for an object with an empty list of authors.
        """
        project = Project(
            name='Test Project',
            authors=[],
            description='Project description.',
            status=Project.ProjectStatus.PLANNED
        )

        self.assertRaises(ValidationError, project.full_clean)
    def test_project_string_representation(self):
        """Ensure that the string representation of a project object simply contains the project's name as-is.
        """
        project = Project(
            name='Test Project',
            authors=['Author 1', 'Author 2'],
            description='Project description.',
            status=Project.ProjectStatus.PLANNED
        )

        self.assertEqual(project.name, str(project))
    def test_valid_authors_two_authors(self):
        """Ensure that a ValidationError is not raised for an object with a list of authors containing two authors.
        """
        project = Project(
            name='Test Project',
            authors=['Author 1', 'Author 2'],
            description='Project description.',
            status=Project.ProjectStatus.PLANNED
        )

        self.assertNotRaises(ValidationError, project.full_clean)
    def test_invalid_authors_one_valid_one_invalid(self):
        """Ensure that a ValidationError is raised for an object with an invalid list of authors.

        A project author cannot be represented by a string of length zero.
        """
        project = Project(
            name='Test Project',
            authors=['Author 1', ''],
            description='Project description.',
            status=Project.ProjectStatus.PLANNED
        )

        self.assertRaises(ValidationError, project.full_clean)
    def test_invalid_authors_two_invalid(self):
        """Ensure that a ValidationError is raised for an object with an invalid list of authors.

        A project author cannot be represented by a string that only contains whitespace characters.
        """
        project = Project(
            name='Test Project',
            authors=['\t \r\n', ''],
            description='Project description.',
            status=Project.ProjectStatus.PLANNED
        )

        self.assertRaises(ValidationError, project.full_clean)
    def test_logo_path_properly_assigned(self):
        """Ensure that the URL and name of a project's image are properly assigned when creating a Project object.
        """
        project = Project(
            name='Test Project',
            authors=['Author 1', 'Author 2'],
            description='Project description.',
            image=self.image,
            status=Project.ProjectStatus.PLANNED
        )
        project.save()

        try:
            self.assertEqual(f'{settings.MEDIA_URL}{BASE_IMAGE_PATH}test_project/main_image.png', project.image.url)
        except AssertionError as e:
            project.delete()
            self.fail(e)

        project.delete()
    def test_image_file_deleted_with_object(self):
        """Ensure that a project's image is deleted from the disk when its associated Project object is deleted.
        """
        project = Project(
            name='Test Project',
            authors=['Author 1', 'Author 2'],
            description='Project description.',
            image=self.image,
            status=Project.ProjectStatus.PLANNED
        )
        project.save()

        path = f'{project.image.path}'
        project.delete()

        import os
        if os.path.isfile(path):
            self.fail('Project image file was not deleted along with the model instance.')
    def test_preprocess(self):
        # set user
        token = self.create_user_and_login(self.user1_params)
        organization = Organization.objects.get(slug=self.org1)
        user = MljarUser.objects.get(email=self.user1_params["email"])
        project = Project(
            title="some title",
            description="...",
            created_by=user,
            parent_organization=organization,
        )
        project.save()

        # prepare data
        local_full_file_path = "/tmp/example.csv"
        filename = "example.csv"

        relative_dir = "test"
        absolute_path = Storage().get_path(relative_dir, filename)

        data_to_file(example_X, example_y, absolute_path)

        ds = FileDataSource(
            title="my file",
            description="desc ...",
            absolute_path=absolute_path,
            file_name=filename,
            file_size=os.path.getsize(absolute_path),
            created_by=user,
            parent_organization=organization,
            parent_project=project,
        )
        ds.save()

        job_params = {
            "absolute_path": ds.absolute_path,
            "file_name": ds.file_name,
            "db_id": ds.id,
            "created_by_id": ds.created_by.id,
            "parent_organization_id": ds.parent_organization.id,
            "parent_project_id": ds.parent_project.id,
        }
        self.assertEqual(DataFrame.objects.all().count(), 0)
        ########################################################################
        # run job
        ########################################################################
        process_file = ProcessUploadedFile(job_params)
        process_file.run()
        ########################################################################
        # check if all is good
        self.assertEqual(DataFrame.objects.all().count(), 1)
        self.assertTrue(DataFrame.objects.filter(source_id=ds.id).count(), 1)
        dataframe = DataFrame.objects.get(source_id=ds.id)

        preview = self.request(
            method="get",
            endpoint="/api/v1/{0}/{1}/dataframe_preview/{2}".format(
                self.org1, project.id, dataframe.id),
            payload={},
            token=token,
            expected_status_code=200,
        )
        self.assertEqual(len(json.loads(preview.get("preview_data"))), 100)
        self.assertTrue("columns_description" in preview)
        self.assertTrue("nrows" in preview)
        self.assertTrue("ncols" in preview)

        frames = self.request(
            method="get",
            endpoint="/api/v1/{0}/{1}/dataframes".format(
                self.org1, project.id),
            payload={},
            token=token,
            expected_status_code=200,
        )
        print(frames)
Example #20
0
 def save_form(cls, fill_form, request):
     event = fill_form.save(commit=False)
     event.project = Project.get_by_name(request.GET['groupName'])
     event.save()
Example #21
0
 def test_change_status_to_finished(self):
     project = Project(start_date='2011-01-01', end_date=None)
     project | should_not | be_finished
     project.end_date = '2011-01-31'
     project.save()
     project.status | should | equal_to('finalizado')
Example #22
0
 def test_finishing(self):
     project = Project(start_date='2011-01-01', end_date=None)
     project | should_not | be_finished
     project.end_date = '2011-01-31'
     project | should | be_finished
    def test_start_mlexperiment(self):

        token = self.create_user_and_login(self.user1_params)
        organization = Organization.objects.get(slug=self.org1)
        user = MljarUser.objects.get(email=self.user1_params["email"])
        project = Project(
            title="some title",
            description="...",
            created_by=user,
            parent_organization=organization,
        )
        project.save()

        # prepare data
        local_full_file_path = "/tmp/example.csv"
        filename = "example.csv"

        relative_dir = "test"
        absolute_path = Storage().get_path(relative_dir, filename)

        data_to_file(example_X, example_y, absolute_path)

        ds = FileDataSource(
            title="my file",
            description="desc ...",
            absolute_path=absolute_path,
            file_name=filename,
            file_size=os.path.getsize(absolute_path),
            created_by=user,
            parent_organization=organization,
            parent_project=project,
        )
        ds.save()

        job_params = {
            "absolute_path": ds.absolute_path,
            "file_name": ds.file_name,
            "db_id": ds.id,
            "created_by_id": ds.created_by.id,
            "parent_organization_id": ds.parent_organization.id,
            "parent_project_id": ds.parent_project.id,
        }

        self.assertEqual(DataFrame.objects.all().count(), 0)
        process_file = ProcessUploadedFile(job_params)
        process_file.run()
        time.sleep(1)  # not nice but till no websockets, let's use it
        self.assertEqual(DataFrame.objects.all().count(), 1)
        self.assertTrue(DataFrame.objects.filter(source_id=ds.id).count(), 1)

        mljar_df = DataFrame.objects.get(source_id=ds.id)

        print(mljar_df.columns_details)

        ### start ml experiment ###
        mlexperiment = MLExperiment(
            title="exp 1",
            description="na na ...",
            params={
                "data_usage": {
                    "train_absolute_path": mljar_df.absolute_path
                },
                "metric": {
                    "optimize": "logloss",
                    "monitor": ["logloss", "auc"]
                },
                "validation": {
                    "validation_type": "split",
                    "train_ratio": 0.5,
                    "shuffle": True,
                },
                "preprocessing": {},
            },
            column_usage={
                "target": ["target"],
                "input": ["feature_{0}".format(i) for i in range(4)],
            },
            created_by_id=user.id,
            parent_organization_id=organization.id,
            parent_project_id=project.id,
        )
        mlexperiment.save()

        job_params = {
            "db_id": mlexperiment.id,
            "params": mlexperiment.params,
            "column_usage": mlexperiment.column_usage,
            "created_by_id": mlexperiment.created_by.id,
            "parent_organization_id": mlexperiment.parent_organization.id,
            "parent_project_id": mlexperiment.parent_project.id,
        }
        automl = StartMLExperiment(job_params)
        automl.run()
        mlexperiment = MLExperiment.objects.get(pk=mlexperiment.id)
        print(mlexperiment.status)
        time.sleep(1.5)
        mlexperiment = MLExperiment.objects.get(pk=mlexperiment.id)
        print(mlexperiment.status)

        self.assertEqual(mlexperiment.status, "done")
Example #24
0
 def test_finishing(self):
     project = Project(start_date='2011-01-01', end_date=None)
     project |should_not| be_finished
     project.end_date = '2011-01-31'
     project |should| be_finished
Example #25
0
 def test_change_status_to_finished(self):
     project = Project(start_date='2011-01-01', end_date=None)
     project |should_not| be_finished
     project.end_date = '2011-01-31'
     project.save()
     project.status |should| equal_to('finalizado')
Example #26
0
def generate_fake():
    """
        generate fake users with projects & tasks
    """
    with application.app_context():
        from apps.users.models import User
        from apps.projects.models import Project
        from apps.tasks.models import Task

        fake = Faker()

        users = []
        for _ in range(5):
            user = User(
                name=fake.name(),
                email=fake.email(),
                password=generate_password_hash('123456')
            )
            db.session.add(user)
            db.session.flush()

            users.append(user)

        # save users
        db.session.commit()

        projects = []
        for user in users:
            for _ in range(random.randint(3, 5)):
                is_shared = fake.boolean(chance_of_getting_true=60)
                project = Project(
                    owner_id=user.id,
                    is_shared=is_shared,
                    name=fake.word()
                )
                db.session.add(project)
                db.session.flush()

                if is_shared:
                    rand_count = random.randint(1, 2)
                    rand_collabs = random.sample(users, k=rand_count)
                    while user.id in [x.id for x in rand_collabs]:
                        rand_collabs = random.sample(users, k=rand_count)

                    for collab in rand_collabs:
                        project.collaborators.append(collab)
                        db.session.add(project)
                        db.session.flush()

                projects.append(project)

        # save projects
        db.session.commit()

        for project in projects:
            tasks = []
            all_collabs = [x for x in project.collaborators.all()]
            all_collabs.append(project.owner)
            for _ in range(random.randint(4, 6)):
                creator = random.choice(all_collabs)
                notify_date = fake.date_time_this_month(before_now=False, after_now=True)
                task = Task(
                    creator_id=creator.id,
                    project_id=project.id,
                    text=' '.join(fake.words(nb=random.randint(1, 2))),
                    note=fake.sentence(),
                    notification_date=notify_date,
                    completion_date=notify_date
                )

                if project.is_shared:
                    is_assigned = fake.boolean(chance_of_getting_true=70)
                    if is_assigned:
                        assigned_to_user = random.choice(all_collabs)
                        task.assigned_to_user_id = assigned_to_user.id

                db.session.add(task)
                db.session.flush()
                tasks.append(task)

            for _ in range(random.randint(1, 2)):
                task = random.choice(tasks)
                task.is_completed = True
                task.completed_at = task.completion_date
                task.completed_by_user_id = task.assigned_to_user_id or task.creator_id

                db.session.add(task)
                db.session.flush()

            project.tasks_order = list([x.id for x in tasks])
            db.session.add(project)
            db.session.flush()

        # save tasks
        db.session.commit()
Example #27
0
 def save_form(cls, fill_form, request):
     event = fill_form.save(commit=False)
     event.project = Project.get_by_name(request.GET['groupName'])
     event.save()