Ejemplo n.º 1
0
 def setUp(self):
     self.cluster = Cluster.load()
     self.admin = UserFactory(is_staff=True, is_superuser=True)
     self.user = UserFactory()
     self.publisher = PublishTrackerService()
     self.publisher.setup()
     super().setUp()
Ejemplo n.º 2
0
 def setUp(self):
     super().setUp()
     self.experiment = ExperimentFactory()
     self.admin = UserFactory(is_staff=True, is_superuser=True)
     self.user = UserFactory()
     activitylogs.validate()
     activitylogs.setup()
Ejemplo n.º 3
0
 def setUp(self):
     super().setUp()
     self.user = UserFactory()
     self.obj1 = Bookmark.objects.create(
         user=self.user, content_object=self.factory_class())  # pylint:disable=not-callable
     self.obj2 = Bookmark.objects.create(
         user=self.user, content_object=self.factory_class())  # pylint:disable=not-callable
Ejemplo n.º 4
0
 def setUpTestData(cls):
     super().setUpTestData()
     if cls.ADMIN_USER:
         user = UserFactory(is_staff=True, is_superuser=True)
         cls.auth_client = AuthorizedClient(user=user)
     else:
         cls.auth_client = AuthorizedClient()
Ejemplo n.º 5
0
 def setUp(self):
     super().setUp()
     self.user = UserFactory()
     activitylogs.validate()
     activitylogs.setup()
     self.project = ProjectFactory()
     activitylogs.record(ref_id=uuid.uuid4(),
                         event_type=USER_ACTIVATED,
                         instance=self.user,
                         actor_id=self.user.id,
                         actor_name=self.user.username)
     activitylogs.record(ref_id=uuid.uuid4(),
                         event_type=PROJECT_DELETED_TRIGGERED,
                         instance=self.project,
                         actor_id=self.user.id,
                         actor_name=self.user.username)
     self.experiment = ExperimentFactory()
     activitylogs.record(ref_id=uuid.uuid4(),
                         event_type=EXPERIMENT_DELETED_TRIGGERED,
                         instance=self.experiment,
                         actor_id=self.user.id,
                         actor_name=self.user.username)
     self.job = JobFactory()
     activitylogs.record(ref_id=uuid.uuid4(),
                         event_type=JOB_VIEWED,
                         instance=self.job,
                         actor_id=self.user.id,
                         actor_name=self.user.username)
Ejemplo n.º 6
0
 def __init__(self,
              access_token='',
              authentication_type=AuthenticationTypes.TOKEN,
              **defaults):
     super().__init__(**defaults)
     user = defaults.get('user', UserFactory())
     self.login_user(user, access_token, authentication_type)
Ejemplo n.º 7
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.internal_client = InternalClient(service=cls.INTERNAL_SERVICE)
     if cls.ADMIN_USER:
         user = UserFactory(is_staff=True, is_superuser=True)
         cls.auth_client = AuthorizedClient(user=user)
     else:
         cls.auth_client = AuthorizedClient()
Ejemplo n.º 8
0
 def test_validate_username(self):
     user = UserFactory(username='******')
     self.assertEqual(IdentityWizard.validate_username('sdf sdf'),
                      'sdf-sdf')
     self.assertEqual(IdentityWizard.validate_username('sdf.sdf'),
                      'sdf-sdf')
     self.assertEqual(IdentityWizard.validate_username('sdf'), 'sdf')
     self.assertNotEqual(IdentityWizard.validate_username(user.username),
                         user.username)
Ejemplo n.º 9
0
 def setUp(self):
     self.user = UserFactory()
     auditor.validate()
     auditor.setup()
     tracker.validate()
     tracker.setup()
     activitylogs.validate()
     activitylogs.setup()
     super().setUp()
Ejemplo n.º 10
0
 def test_create_key_validation_passes_for_different_owner(self):
     assert ConfigOption.objects.count() == 0
     ConfigOption.objects.create(owner=self.owner, key='key', value="foo")
     assert ConfigOption.objects.count() == 1
     # Using new owner with same keys should work
     user = UserFactory()  # Creates a new owner
     owner = Owner.objects.get(name=user.username)
     ConfigOption.objects.create(owner=owner, key='key', value="bar")
     assert ConfigOption.objects.count() == 2
Ejemplo n.º 11
0
 def test_create_key_validation_passes_for_different_owner(self):
     assert self.model_class.objects.count() == 0
     self.model_class.objects.create(owner=self.owner, name='my_store')
     assert self.model_class.objects.count() == 1
     # Using new owner with same keys should work
     user = UserFactory()  # Creates a new owner
     owner = Owner.objects.get(name=user.username)
     self.model_class.objects.create(owner=owner, name='my_store')
     assert self.model_class.objects.count() == 2
Ejemplo n.º 12
0
 def test_create_key_validation_passes_for_different_owner(self):
     assert GitAccess.objects.count() == 0
     GitAccess.objects.create(owner=self.owner, name='my_gitlab_access')
     assert GitAccess.objects.count() == 1
     # Using new owner with same items should work
     user = UserFactory()  # Creates a new owner
     owner = Owner.objects.get(name=user.username)
     GitAccess.objects.create(owner=owner, name='my_gitlab_access')
     assert GitAccess.objects.count() == 2
Ejemplo n.º 13
0
 def setUp(self):
     super().setUp()
     self.user = UserFactory()
     self.project = ProjectFactory(user=self.user)
     self.project_job = JobFactory(project=self.project, name='unique')
     self.job = JobFactory(name='unique2')
     self.project_experiment = ExperimentFactory(project=self.project,
                                                 name='unique')
     self.experiment = ExperimentFactory(name='unique2')
     self.instance_mock = InstanceSpec(self.user.id, self.project.id)
     self.wrong_instance_mock = InstanceSpec(-1, -1)
Ejemplo n.º 14
0
 def test_create_name_validation_passes_for_different_owner(self):
     assert K8SSecret.objects.count() == 0
     K8SSecret.objects.create(owner=self.owner,
                              name='my_secret',
                              secret_ref='my_secret')
     assert K8SSecret.objects.count() == 1
     # Using new owner with same name should work
     user = UserFactory()  # Creates a new owner
     owner = Owner.objects.get(name=user.username)
     K8SSecret.objects.create(owner=owner,
                              name='my_secret',
                              secret_ref='my_secret')
     assert K8SSecret.objects.count() == 2
Ejemplo n.º 15
0
 def setUp(self):
     self.user = UserFactory()
     super().setUp()
     self.tested_events = {
         user_events.USER_REGISTERED,
         user_events.USER_UPDATED,
         user_events.USER_ACTIVATED,
         user_events.USER_DELETED,
         user_events.USER_LDAP,
         user_events.USER_GITHUB,
         user_events.USER_GITLAB,
         user_events.USER_BITBUCKET,
         user_events.USER_AZURE,
     }
Ejemplo n.º 16
0
 def setUp(self):
     super().setUp()
     self.user = UserFactory()
     activitylogs.validate()
     activitylogs.setup()
     self.project = ProjectFactory()
     activitylogs.record(event_type=PROJECT_DELETED_TRIGGERED,
                         instance=self.project,
                         actor_id=self.user.id)
     self.experiment = ExperimentFactory()
     activitylogs.record(event_type=EXPERIMENT_DELETED_TRIGGERED,
                         instance=self.experiment,
                         actor_id=self.user.id)
     self.job = JobFactory()
     activitylogs.record(event_type=JOB_VIEWED,
                         instance=self.job,
                         actor_id=self.user.id)
Ejemplo n.º 17
0
 def setUp(self):
     super().setUp()
     self.user = UserFactory()
     self.obj1 = self.factory_class()  # pylint:disable=not-callable
     self.obj2 = self.factory_class()  # pylint:disable=not-callable
Ejemplo n.º 18
0
    def test_handle_new_files_task(self):
        assert self.model_class.objects.count() == 0
        user = self.auth_client.user
        repo_name = self.project.name
        uploaded_file = self.get_upload_file()

        self.auth_client.put(self.url,
                             data={'repo': uploaded_file},
                             content_type=MULTIPART_CONTENT)

        upload_file_path = '{}/{}/{}.tar.gz'.format(
            conf.get('UPLOAD_MOUNT_PATH'), user.username, repo_name)
        # Assert the the task handler takes care of cleaning the upload root after
        # committing changes
        self.assertFalse(os.path.exists(upload_file_path))

        # Assert repo model was created
        assert self.model_class.objects.count() == 1
        repo = self.model_class.objects.first()

        # Assert new git repo was created in the repos root and that also the tar file was deleted
        code_file_path = '{}/{}/{}/{}'.format(
            conf.get('REPOS_MOUNT_PATH'), user.username, self.project.name, self.project.name)
        tar_code_file_path = repo.get_tmp_tar_path()
        self.assertFalse(os.path.exists(tar_code_file_path))
        self.assertTrue(os.path.exists(code_file_path))
        # Assert that the code_file_path is a git repo
        git_file_path = '{}/.git'.format(code_file_path)
        self.assertTrue(os.path.exists(git_file_path))
        # Get last commit
        commit_hash, commit = git.get_last_commit(code_file_path)
        assert commit.author.email == user.email
        assert commit.author.name == user.username

        # Make a new upload with repo_new.tar.gz containing 2 files
        new_uploaded_file = self.get_upload_file('updated_repo')
        self.auth_client.put(self.url,
                             data={'repo': new_uploaded_file},
                             content_type=MULTIPART_CONTENT)

        upload_file_path = '{}/{}/{}.tar.gz'.format(
            conf.get('UPLOAD_MOUNT_PATH'), user.username, repo_name)
        # Assert the the task handler takes care of cleaning the upload root after
        # committing changes
        self.assertFalse(os.path.exists(upload_file_path))

        # Assert same git repo was used in the repos root and that also the tar file was deleted
        self.assertFalse(os.path.exists(tar_code_file_path))
        self.assertTrue(os.path.exists(code_file_path))
        # Assert that the code_file_path is a git repo
        self.assertTrue(os.path.exists(git_file_path))
        # Get last commit
        commit_hash, commit = git.get_last_commit(code_file_path)
        assert commit.author.email == user.email
        assert commit.author.name == user.username
        # Assert that we committed 3 files (2 files in new_repo.tar.gz one file was deleted)
        assert len(git.get_committed_files(code_file_path, commit_hash)) == 3

        # Make a new upload with repo_with_folder.tar.gz containing 1 file one dir with fil
        new_uploaded_file = self.get_upload_file('repo_with_folder')
        self.auth_client.put(self.url,
                             data={'repo': new_uploaded_file},
                             content_type=MULTIPART_CONTENT)

        upload_file_path = '{}/{}/{}.tar.gz'.format(
            conf.get('UPLOAD_MOUNT_PATH'), user.username, repo_name)
        # Assert the the task handler takes care of cleaning the upload root after
        # committing changes
        self.assertFalse(os.path.exists(upload_file_path))

        # Assert same git repo was used in the repos root and that also the tar file was deleted
        self.assertFalse(os.path.exists(tar_code_file_path))
        self.assertTrue(os.path.exists(code_file_path))
        # Assert that the code_file_path is a git repo
        self.assertTrue(os.path.exists(git_file_path))
        # Get last commit
        commit_hash, commit = git.get_last_commit(code_file_path)
        assert commit.author.email == user.email
        assert commit.author.name == user.username
        # Assert that we committed 3 files
        # (1 file updated 1 deleted, and one folder with 1 file added)
        assert len(git.get_committed_files(code_file_path, commit_hash)) == 3

        # Check that other user cannot commit to this repo
        new_user = UserFactory()
        self.auth_client.login_user(new_user)
        new_uploaded_file = self.get_upload_file('updated_repo')
        response = self.auth_client.put(self.url,
                                        data={'repo': new_uploaded_file},
                                        content_type=MULTIPART_CONTENT)

        assert response.status_code in (status.HTTP_401_UNAUTHORIZED, status.HTTP_403_FORBIDDEN)
        upload_file_path = '{}/{}/{}.tar.gz'.format(
            conf.get('UPLOAD_MOUNT_PATH'), new_user.username, repo_name)
        # Assert the the task handler takes care of cleaning the upload root after
        # committing changes
        self.assertFalse(os.path.exists(upload_file_path))

        # Assert same git repo was used in the repos root and that also the tar file was deleted
        self.assertFalse(os.path.exists(tar_code_file_path))
        self.assertTrue(os.path.exists(code_file_path))
        # Assert that the code_file_path is a git repo
        self.assertTrue(os.path.exists(git_file_path))
        # Get last commit and check it did not change
        new_commit_hash, new_commit = git.get_last_commit(code_file_path)
        assert commit.author.email == new_commit.author.email
        assert commit.author.name == new_commit.author.name
        assert new_commit_hash == commit_hash

        # Log old user, otherwise other tests will crash
        self.auth_client.login_user(user)
Ejemplo n.º 19
0
 def setUp(self):
     super().setUp()
     self.experiment = ExperimentFactory()
     self.admin = UserFactory(is_staff=True, is_superuser=True)
     self.user = UserFactory()
Ejemplo n.º 20
0
 def setUp(self):
     super().setUp()
     self.user = UserFactory()
     self.obj1 = SearchFactory()
     self.obj2 = SearchFactory(content_type=content_types.BUILD_JOB)
Ejemplo n.º 21
0
 def setUp(self):
     self.user = UserFactory()
     super().setUp()
Ejemplo n.º 22
0
 def setUp(self):
     self.experiment = ExperimentFactory()
     self.user = UserFactory()