def test_create_job_permission_exception(): """ /SA030/ """ try: user = User.get_user_by_username("createjobuser4") except UserNotFoundException: user = User("createjobuser4", "token") try: admin = User.get_user_by_username("false_admin1") except UserNotFoundException: admin = User("false_admin1", "token") request = { "source": "source", "target": "target", "user": "******", "for_user": "******", "email": [True, True, False] } json_string = json.dumps(request) with pytest.raises(PermissionException): app.create_job(json_string)
def test_get_credentials_by_user(): """ /SA710/ """ try: user = User.get_user_by_username("creduser") except UserNotFoundException: user = User("creduser", "token123") request = { "username": "******", } json_string = json.dumps(request) response = json.loads(app.get_credentials_by_user(json_string)) assert response["token"] == "token123" try: user = User.get_user_by_username("credadmin") except UserNotFoundException: user = User("credadmin", "token321") request = { "username": "******", } json_string = json.dumps(request) response = json.loads(app.get_credentials_by_user(json_string)) assert response["token"] == "token321"
def test_create_job_admin(): """ /SA020/ """ try: user = User.get_user_by_username("createjobuser4") except UserNotFoundException: user = User("createjobuser4", "token") try: admin = User.get_user_by_username("admin1") except UserNotFoundException: admin = Administrator("admin1", "token") request = { "source": "source", "target": "target", "user": "******", "for_user": "******", "email": [True, True, False] } json_string = json.dumps(request) job_id = app.create_job(json_string) job = Job.get_job_by_id(job_id) assert job.get_job_id() == job_id assert job.has_start_notification() assert not job.has_end_notification() assert job.has_error_notification() assert job.get_target_alias() == "target" assert job.get_user().get_username() == "createjobuser4"
def test_resume_exception(): """ /SA920/ """ try: user = User.get_user_by_username("resumeuser") except UserNotFoundException: user = User("resumeuser", "token") job = Job('storageA', 'storageB', '~/.data/', [True, False, True], user) job.set_status(JobStatus.ACTIVE) job_id = job.get_job_id() request = { "job_id": job_id, } json_string = json.dumps(request) with pytest.raises(SemanticException): app.resume(json_string) """ /SA930/ """ request = { "job_id": "87497294723947289374823[7936593653456348756t3487657834658723452345", } json_string = json.dumps(request) with pytest.raises(JobNotFoundException): app.resume(json_string)
def test_verify_user_exceptions(): """ /SA1130/ """ # Invalid token given try: user = User.get_user_by_username("verifyadmin") except UserNotFoundException: user = Administrator("verifyadmin", "token3") request = {"user": "******", "token": "invalidtoken"} json_string = json.dumps(request) with pytest.raises(PermissionException): app.verify_user(json_string) """ /SA1140/ """ # Invalid token in database try: user = User.get_user_by_username("uyefv") except UserNotFoundException: user = User("uyefv", "token3") request = {"user": "******", "token": "token1"} json_string = json.dumps(request) with pytest.raises(PermissionException): app.verify_user(json_string)
def ensure_existance(self, username): try: User.get_user_by_username(username) except UserNotFoundException: if username in self._config_handler.get_administrators(): Administrator(username) else: User(username)
def test_done_job(): try: user = User.get_user_by_username("uyefv") except UserNotFoundException: user = User("uyefv", "token") job = Job('storageA', 'storageB', '~/.data/', [True, True, True], user) job.set_status(JobStatus.DONE) notification_handler.resolve_notification(job)
def test_error_job(): try: user = User.get_user_by_username("uyefv") except UserNotFoundException: user = User("uyefv", "token") job = Job('storageA', 'storageB', '~/.data/', [False, False, False], user) job.set_error("Target not mounted") job.set_status(JobStatus.PAUSED) notification_handler.resolve_notification(job)
def test_user(): try: user = User.get_user_by_username("testuser") except UserNotFoundException: user = User("testuser", "token") assert user.get_token() == "token" assert user.get_username() == "testuser" assert user.get_user_type() == UserRole.User
def test_get_log_different_days(): """ /SA240/ """ try: user1 = User.get_user_by_username("loguser2") jobs = Job.get_jobs([user1.get_username()], [ JobStatus.PAUSED, JobStatus.QUEUED, JobStatus.ACTIVE, JobStatus.DONE ]) for current_job in jobs: current_job.set_status(JobStatus.ACTIVE) except UserNotFoundException: user1 = User("loguser2", "token") timestamp = datetime.date.today() - datetime.timedelta(days=2) active_job_ids_user1 = [] job1 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job1.set_status(JobStatus.DONE) job1.set_start_time(timestamp) job1.set_end_time(timestamp) job1.set_enqueue_time(timestamp) active_job_ids_user1.append(job1.get_job_id()) job2 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job2.set_status(JobStatus.DONE) job2.set_start_time(timestamp) job2.set_end_time(timestamp) job2.set_enqueue_time(timestamp) active_job_ids_user1.append(job2.get_job_id()) job3 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job3.set_status(JobStatus.DONE) job3.set_start_time(timestamp) job3.set_end_time(timestamp) job3.set_enqueue_time(timestamp) active_job_ids_user1.append(job3.get_job_id()) # Log for last 3 days request = {"days": "3", "user": "******", "for_user": "******"} json_string = json.dumps(request) response = json.loads(app.get_log(json_string)) assert len(response) == 3 for job in response: assert job['job_id'] in active_job_ids_user1 # Log for last day request = {"days": "1", "user": "******", "for_user": "******"} json_string = json.dumps(request) response = json.loads(app.get_log(json_string)) assert len(response) == 0
def test_create_job_config_exception(): """Test for max. allowed number of active jobs per user""" """ /SA040/ """ try: user = User.get_user_by_username("createjobuser2") except UserNotFoundException: user = User("createjobuser2", "token") request = { "source": "source", "target": "target", "user": "******", "for_user": "******", "email": [True, True, True] } json_string = json.dumps(request) try: job_id = app.create_job(json_string) job = Job.get_job_by_id(job_id) job.set_status(JobStatus.QUEUED) except PermissionException: pass try: job_id = app.create_job(json_string) job = Job.get_job_by_id(job_id) job.set_status(JobStatus.QUEUED) except PermissionException: pass try: job_id = app.create_job(json_string) job = Job.get_job_by_id(job_id) job.set_status(JobStatus.QUEUED) except PermissionException: pass try: job_id = app.create_job(json_string) job = Job.get_job_by_id(job_id) job.set_status(JobStatus.QUEUED) except PermissionException: pass try: job_id = app.create_job(json_string) job = Job.get_job_by_id(job_id) job.set_status(JobStatus.QUEUED) assert 1 == 0 except PermissionException: assert 1 == 1
def test_cancel_job_wrong_administrator(): """ /SA130/ """ try: user = User.get_user_by_username("canceljobuser3") except UserNotFoundException: user = User("canceljobuser3", "token") try: admin = User.get_user_by_username("canceljobfalseadmin33") except UserNotFoundException: admin = User("canceljobfalseadmin33", "token") job = Job('storageA', 'storageB', '~/.data/', [True, True, True], user) job_id = job.get_job_id() job.set_status(JobStatus.ACTIVE) request = {"job_id": job_id, "user": "******"} json_string = json.dumps(request) with pytest.raises(PermissionException): app.cancel_job(json_string)
def test_verify_admin(): """ /SA1120/ """ try: user = User.get_user_by_username("verifyuser") except UserNotFoundException: user = User("verifyuser", "token2") request = {"user": "******", "token": "token2"} json_string = json.dumps(request) response = json.loads(app.verify_user(json_string)) assert response["role"] == "User"
def test_cancel_job(): try: johann = User.get_user_by_username('johann') except UserNotFoundException: johann = User('johann', 'jtoken') job = Job('dmd_home', 'dmd1', 'home/centos/testdata/johann-directory-1', [False, False, False], johann) job_id = job.id master = Master.get_master() master.add_to_queue(job) master.cancel_job(job) worker = master.get_workers()[0] assert worker.name == 'worker1' assert worker.status.name == 'WAITING' assert Job.get_job_by_id(job_id).status.name == 'CANCELED'
def get_workers(self, ): workers = [] worker1 = Worker('worker1', 'WAITING', None, '192.168.0.1:1234', ['storageA', 'storageB']) workers.append(worker1) try: user = User.get_user_by_username("workeruser1") except UserNotFoundException: user = User("workeruser1", "token") job = Job('storageA', 'storageB', '~/.data/', [True, True, True], user) worker2 = Worker('worker2', 'ACTIVE', job.get_job_id(), '192.168.0.2:1234', None) workers.append(worker2) return workers
def test_resume(): """ /SA910/ """ try: user = User.get_user_by_username("resumeuser") except UserNotFoundException: user = User("resumeuser", "token") job = Job('storageA', 'storageB', '~/.data/', [True, False, True], user) job.set_status(JobStatus.PAUSED) job_id = job.get_job_id() request = { "job_id": job_id, } json_string = json.dumps(request) app.resume(json_string)
def test_cancel_job(): """ /SA110/ """ try: user = User.get_user_by_username("canceljobuser1") except UserNotFoundException: user = User("canceljobuser1", "token") job = Job('storageA', 'storageB', '~/.data/', [True, True, True], user) job_id = job.get_job_id() job.set_status(JobStatus.ACTIVE) request = {"job_id": job_id, "user": "******"} json_string = json.dumps(request) app.cancel_job(json_string) assert Job.get_job_by_id(job_id).get_status() == JobStatus.CANCELED
def test_build_log(): try: user = User.get_user_by_username("rbuser") except UserNotFoundException: user = User("rbuser", "token") job1 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user) job1_id = job1.get_job_id() job1.set_status(JobStatus.DONE) timestamp = datetime.datetime.now() job1.set_enqueue_time(timestamp) job1.set_end_time(timestamp) job2 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user) job2_id = job2.get_job_id() job2.set_status(JobStatus.DONE) timestamp = datetime.datetime.now() job2.set_enqueue_time(timestamp) job2.set_end_time(timestamp) job1 = Job.get_job_by_id(job1_id) job2 = Job.get_job_by_id(job2_id) answer = json.loads(rb.build_log([job1, job2])) job1 = Job.get_job_by_id(job1_id) assert answer[0]["job_id"] == job1.get_job_id() assert answer[0]["source"] == job1.get_source_alias( ) + ":" + job1.get_source_relative_path() assert answer[0]["target"] == job1.get_target_alias() assert answer[0]["enqueue_time"] == job1.get_enqueue_time().isoformat() assert answer[0]["end_time"] == job1.get_end_time().isoformat() assert answer[0]["creator"] == job1.get_user().get_username() assert answer[0]["status"] == job1.get_status().name assert answer[0]["error"] == job1.get_error() job2 = Job.get_job_by_id(job2_id) assert answer[1]["job_id"] == job2.get_job_id() assert answer[1]["source"] == job2.get_source_alias( ) + ":" + job2.get_source_relative_path() assert answer[1]["target"] == job2.get_target_alias() assert answer[1]["enqueue_time"] == job2.get_enqueue_time().isoformat() assert answer[1]["end_time"] == job2.get_end_time().isoformat() assert answer[1]["creator"] == job2.get_user().get_username() assert answer[1]["status"] == job2.get_status().name assert answer[1]["error"] == job2.get_error()
def test_build_job(): try: user = User.get_user_by_username("rbuser") except UserNotFoundException: user = User("rbuser", "token") job = Job('storageA', 'storageB', '~/.data/', [True, True, True], user) job.set_status(JobStatus.QUEUED) timestamp = datetime.datetime.now() job.set_enqueue_time(timestamp) answer = json.loads(rb.build_job(job)) assert answer["job_id"] == job.get_job_id() assert answer["source"] == job.get_source_alias( ) + ":" + job.get_source_relative_path() assert answer["target"] == job.get_target_alias() assert answer["enqueue_time"] == job.get_enqueue_time().isoformat() assert answer["creator"] == job.get_user().get_username() assert answer["status"] == job.get_status().name return
def test_inheritance(): try: user = User.get_user_by_username("testuser5") except UserNotFoundException: user = User("testuser5", "token") user.set_user_type(UserRole.Administrator) assert user.get_user_type() == UserRole.Administrator administrator = User.get_user_by_username("testuser5") assert administrator.get_user_type() == UserRole.Administrator assert isinstance(administrator, Administrator) administrator.set_user_type(UserRole.User) user = User.get_user_by_username("testuser5") assert user.get_user_type() == UserRole.User assert not isinstance(user, Administrator) assert isinstance(user, User)
def test_get_directory(): """ /AS010/ """ try: user1 = User.get_user_by_username("user1ldap") except UserNotFoundException: user1 = User("user1ldap", "token") request = { "target": "archive1", "user": "******", "for_user": "******" } json_string = json.dumps(request) response = json.loads(app.get_directory_list(json_string)) assert len(response) == 1 assert len(response['archive1']) == 2 assert response['archive1'][0] == "/user1ldap-first_directory" assert response['archive1'][1] == "/user1ldap-second_directory"
def test_cancel_job_semantic_exception(): """ /SA140/ """ try: user = User.get_user_by_username("canceljobuser4") except UserNotFoundException: user = User("canceljobuser4", "token") try: admin = User.get_user_by_username("canceljobadmin4") except UserNotFoundException: admin = Administrator("canceljobadmin4", "token") job = Job('storageA', 'storageB', '~/.data/', [True, True, True], user) job_id = job.get_job_id() job.set_status(JobStatus.DONE) request = {"job_id": job_id, "user": "******"} json_string = json.dumps(request) with pytest.raises(SemanticException): app.cancel_job(json_string)
def test_get_directory2(): """ /AS020/ """ try: user1 = User.get_user_by_username("user1ldap") except UserNotFoundException: user1 = User("user1ldap", "token") request = {"target": "", "user": "******", "for_user": "******"} json_string = json.dumps(request) response = json.loads(app.get_directory_list(json_string)) print(response) assert len(response) == 4 assert len(response['archive1']) == 2 assert response['archive1'][0] == "/user1ldap-first_directory" assert response['archive1'][1] == "/user1ldap-second_directory" assert len(response['centos']) == 3 assert response['centos'][0] == "/user1ldap-memories-1" assert response['centos'][1] == "/user1ldap-memories-2" assert response['centos'][2] == "/user1ldap-experiments-1"
def test_success_job(env): try: johann = User.get_user_by_username('johann') except UserNotFoundException: johann = User('johann', 'jtoken') job = Job(source_alias = 'dmd_home', target_alias = 'archive1', source_relative_path = 'export/master_data/tests/johann-directory-1', notification = [False, False, False], user = johann) job_id = job.id master = Master.get_master() worker = master.get_workers()[0] assert worker.name == 'worker1' assert worker.status.name == 'WAITING' master.add_to_queue(job) time.sleep(5) while (worker.status.name == 'ACTIVE'): #wait for worker to finish time.sleep(5) assert worker.status.name == 'WAITING' assert Job.get_job_by_id(job_id).status.name == 'DONE' #make sure the file was actually copied assert os.path.exists("/export/archive1/1-johann-directory.tar")
def verify_user_via_token(self, username, token): """ Verifies the identity of user. If user doesn't exist in the database, he will be created after given token will be compared with remote_token, that is stored by user. Given token is compared with database entry. :param username: user that has to be verified :param token: user credentials string :return: verified User """ try: user = User.get_user_by_username(username) except UserNotFoundException: remote_token = search_class.get_user_credentials(username) if remote_token != token: return False if username in self._config_handler.get_administrators(): user = Administrator(username, remote_token) else: user = User(username, remote_token) # In case a User was registered using munge a token is not present in the data base entry if not user.get_token(): remote_token = search_class.get_user_credentials(username) user.set_token(remote_token) # Check if the token match if user.get_token() != token: # Update database entry in case credentials have changed remote_token = search_class.get_user_credentials(username) if remote_token != user.get_token(): user.set_token(remote_token) if user.get_token() != token: return False return True
def test_get_log(): """ 1. Admin requests logs of user. /SA210/ 2. User requests his own logs /SA220/ 3. Another user(not admin) requests logs of user /SA230/ :return: """ try: user1 = User.get_user_by_username("loguser1") jobs = Job.get_jobs([user1.get_username()], [ JobStatus.PAUSED, JobStatus.QUEUED, JobStatus.ACTIVE, JobStatus.DONE ]) for current_job in jobs: current_job.set_status(JobStatus.ACTIVE) except UserNotFoundException: user1 = User("loguser1", "token") timestamp = datetime.datetime.now() active_job_ids_user1 = [] job1 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job1.set_status(JobStatus.DONE) job1.set_start_time(timestamp) job1.set_end_time(timestamp) job1.set_enqueue_time(timestamp) active_job_ids_user1.append(job1.get_job_id()) job2 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job2.set_status(JobStatus.DONE) job2.set_start_time(timestamp) job2.set_end_time(timestamp) job2.set_enqueue_time(timestamp) active_job_ids_user1.append(job2.get_job_id()) job3 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job3.set_status(JobStatus.DONE) job3.set_start_time(timestamp) job3.set_end_time(timestamp) job3.set_enqueue_time(timestamp) active_job_ids_user1.append(job3.get_job_id()) # -----------1------------ try: admin = User.get_user_by_username("logadmin1") except UserNotFoundException: admin = Administrator("logadmin1", "token") request = {"days": "5", "user": "******", "for_user": "******"} json_string = json.dumps(request) response = json.loads(app.get_log(json_string)) assert len(response) == 3 for job in response: assert job['job_id'] in active_job_ids_user1 # -----------2------------ request = {"days": "5", "user": "******", "for_user": "******"} json_string = json.dumps(request) response = json.loads(app.get_log(json_string)) assert len(response) == 3 for job in response: assert job['job_id'] in active_job_ids_user1 # -----------3------------ try: false_admin = User.get_user_by_username("logadminfalse1") except UserNotFoundException: false_admin = User("logadminfalse1", "token") request = {"days": "5", "user": "******", "for_user": "******"} json_string = json.dumps(request) with pytest.raises(PermissionException): app.get_log(json_string)
def test_get_jobs(): #Build users and jobs try: user1 = User.get_user_by_username("user1") jobs = Job.get_jobs([user1.get_username()], [ JobStatus.PAUSED, JobStatus.QUEUED, JobStatus.ACTIVE, JobStatus.PAUSED ]) for current_job in jobs: current_job.set_status(JobStatus.DONE) except UserNotFoundException: user1 = User("user1", "token") try: user2 = User.get_user_by_username("user2") jobs = Job.get_jobs([user2.get_username()], [ JobStatus.PAUSED, JobStatus.QUEUED, JobStatus.ACTIVE, JobStatus.PAUSED ]) for current_job in jobs: current_job.set_status(JobStatus.DONE) except UserNotFoundException: user2 = User("user2", "token") try: user3 = User.get_user_by_username("user3") jobs = Job.get_jobs([user3.get_username()], [ JobStatus.PAUSED, JobStatus.QUEUED, JobStatus.ACTIVE, JobStatus.PAUSED ]) for current_job in jobs: current_job.set_status(JobStatus.DONE) except UserNotFoundException: user1 = User("user3", "token") active_job_ids_user1 = [] job1_1 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job1_1.set_status(JobStatus.ACTIVE) active_job_ids_user1.append(job1_1.get_job_id()) job1_2 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job1_2.set_status(JobStatus.ACTIVE) active_job_ids_user1.append(job1_2.get_job_id()) job1_3 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job1_3.set_status(JobStatus.ACTIVE) active_job_ids_user1.append(job1_3.get_job_id()) queued_job_ids_user1 = [] job1_4 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job1_4.set_status(JobStatus.QUEUED) queued_job_ids_user1.append(job1_4.get_job_id()) job1_5 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job1_5.set_status(JobStatus.QUEUED) queued_job_ids_user1.append(job1_5.get_job_id()) job1_6 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job1_6.set_status(JobStatus.QUEUED) queued_job_ids_user1.append(job1_6.get_job_id()) canceled_job_ids_user1 = [] job1_7 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job1_7.set_status(JobStatus.CANCELED) canceled_job_ids_user1.append(job1_7.get_job_id()) job1_8 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job1_8.set_status(JobStatus.CANCELED) canceled_job_ids_user1.append(job1_8.get_job_id()) job1_9 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user1) job1_9.set_status(JobStatus.CANCELED) canceled_job_ids_user1.append(job1_9.get_job_id()) active_jobs_user1 = active_job_ids_user1.copy() queued_jobs_user1 = queued_job_ids_user1.copy() canceled_jobs_user1 = canceled_job_ids_user1.copy() jobs = Job.get_jobs([user1.get_username()], [JobStatus.ACTIVE]) assert len(jobs) == 3 for job in jobs: if job.get_job_id() not in active_jobs_user1: assert 1 == 0 else: assert 1 == 1 active_jobs_user1.remove(job.get_job_id()) assert active_jobs_user1 == [] active_jobs_user1 = active_job_ids_user1.copy() jobs = Job.get_jobs([user1.get_username()], [JobStatus.ACTIVE, JobStatus.QUEUED]) assert len(jobs) == 6 for job in jobs: if job.get_job_id() not in active_jobs_user1: if job.get_job_id() not in queued_jobs_user1: assert 1 == 0 else: assert 1 == 1 queued_jobs_user1.remove(job.get_job_id()) else: assert 1 == 1 active_jobs_user1.remove(job.get_job_id()) assert active_jobs_user1 == [] assert queued_jobs_user1 == [] active_jobs_user1 = active_job_ids_user1.copy() queued_jobs_user1 = queued_job_ids_user1.copy() user2 = User.get_user_by_username("user2") active_job_ids_user2 = [] job2_1 = Job('storageC', 'storageD', '~/.data/', [True, True, True], user2) job2_1.set_status(JobStatus.ACTIVE) active_job_ids_user2.append(job2_1.get_job_id()) job2_2 = Job('storageC', 'storageD', '~/.data/', [True, True, True], user2) job2_2.set_status(JobStatus.ACTIVE) active_job_ids_user2.append(job2_2.get_job_id()) job2_3 = Job('storageC', 'storageD', '~/.data/', [True, True, True], user2) job2_3.set_status(JobStatus.ACTIVE) active_job_ids_user2.append(job2_3.get_job_id()) queued_job_ids_user2 = [] job2_4 = Job('storageC', 'storageD', '~/.data/', [True, True, True], user2) job2_4.set_status(JobStatus.QUEUED) queued_job_ids_user2.append(job2_4.get_job_id()) job2_5 = Job('storageC', 'storageD', '~/.data/', [True, True, True], user2) job2_5.set_status(JobStatus.QUEUED) queued_job_ids_user2.append(job2_5.get_job_id()) job2_5 = Job('storageC', 'storageD', '~/.data/', [True, True, True], user2) job2_5.set_status(JobStatus.QUEUED) queued_job_ids_user2.append(job2_5.get_job_id()) active_jobs_user2 = active_job_ids_user2.copy() queued_jobs_user2 = queued_job_ids_user2.copy() jobs = Job.get_jobs( [user1.get_username(), user2.get_username()], [JobStatus.ACTIVE]) assert len(jobs) == 6 for job in jobs: if job.get_job_id() not in active_jobs_user1: if job.get_job_id() not in active_jobs_user2: assert 1 == 0 else: assert 1 == 1 active_jobs_user2.remove(job.get_job_id()) else: assert 1 == 1 active_jobs_user1.remove(job.get_job_id()) assert active_jobs_user1 == [] assert active_jobs_user2 == [] active_jobs_user1 = active_job_ids_user1.copy() active_jobs_user2 = active_job_ids_user2.copy() job3 = Job('storageA', 'storageB', '~/.data/', [True, True, True], user3) job3.set_status(JobStatus.PAUSED) time = datetime.datetime.now() - datetime.timedelta(days=10) job3.set_end_time(time) jobs = Job.get_jobs(None, [JobStatus.PAUSED], 8) assert len(jobs) == 0 jobs = Job.get_jobs(None, [JobStatus.PAUSED], 12) assert len(jobs) == 1
def test_get_directory_list(): """ 1. Administrator requests directory list of another user /SA610/ 2. User requests his own directory list /SA620/ 3. Another user (not Administrator) requests directory list of user /SA630/ """ try: admin = User.get_user_by_username("diradmin") except UserNotFoundException: admin = Administrator("diradmin", "token") try: user1 = User.get_user_by_username("diruser1") except UserNotFoundException: user1 = User("diruser1", "token") try: user2 = User.get_user_by_username("diruser2") except UserNotFoundException: user2 = User("diruser2", "token") # --------1-------- request = { "target": "testtarget", "user": "******", "for_user": "******" } json_string = json.dumps(request) response = json.loads(app.get_directory_list(json_string)) assert len(response) == 1 assert len(response['testtarget']) == 3 assert response['testtarget'][0] == "directory1" assert response['testtarget'][1] == "directory2" assert response['testtarget'][2] == "directory3" # --------2-------- request = { "target": "testtarget", "user": "******", "for_user": "******" } json_string = json.dumps(request) response = json.loads(app.get_directory_list(json_string)) assert len(response) == 1 assert len(response['testtarget']) == 3 assert response['testtarget'][0] == "directory1" assert response['testtarget'][1] == "directory2" assert response['testtarget'][2] == "directory3" # --------3-------- request = { "target": "testtarget", "user": "******", "for_user": "******" } json_string = json.dumps(request) with pytest.raises(PermissionException): json.loads(app.get_directory_list(json_string))
import pytest from exceptions.user_not_found_exception import UserNotFoundException from master.master import Master from master.worker import Worker from application.system.job import Job from application.system.user import User """ This test assumes an empty database """ try: user = User.get_user_by_username("xyz") except UserNotFoundException: user = User("xyz", "token") jobA = Job('storageA', 'storageB', '~/.data/', [True, True, True], user) jobB = Job('storageB', 'storageC', '~/.data/', [True, True, True], user) jobC = Job('storageC', 'storageD', '~/.data/', [True, True, True], user) workerA = Worker('A', 'WAITING', None, 'host:1234', ['storageA', 'storageB']) workerB = Worker('B', 'WAITING', None, 'host:1234', ['storageA', 'storageB']) @pytest.mark.order1 def test_constructor(): master = Master.get_master() assert (type(master) is Master) master2 = Master.get_master() assert (master == master2)