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()
def setUp(self): super().setUp() self.experiment = ExperimentFactory() self.admin = UserFactory(is_staff=True, is_superuser=True) self.user = UserFactory() activitylogs.validate() activitylogs.setup()
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
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()
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)
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)
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()
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)
def setUp(self): self.user = UserFactory() auditor.validate() auditor.setup() tracker.validate() tracker.setup() activitylogs.validate() activitylogs.setup() super().setUp()
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
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
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
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)
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
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, }
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)
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
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)
def setUp(self): super().setUp() self.experiment = ExperimentFactory() self.admin = UserFactory(is_staff=True, is_superuser=True) self.user = UserFactory()
def setUp(self): super().setUp() self.user = UserFactory() self.obj1 = SearchFactory() self.obj2 = SearchFactory(content_type=content_types.BUILD_JOB)
def setUp(self): self.user = UserFactory() super().setUp()
def setUp(self): self.experiment = ExperimentFactory() self.user = UserFactory()