def test_some_cronjobs_are_added_between_containing_comments(self): with temp_file("schedule,query.json,creds.json,token.json,performanceplatform.json") as jobs_path: generated_jobs = crontab.generate_crontab( [], jobs_path, "/path/to/my-app", 'some_id') assert_that(generated_jobs, has_item('# Begin performanceplatform.collector jobs for some_id')) assert_that(generated_jobs, has_item(contains_string("schedule"))) assert_that(generated_jobs, has_item( contains_string("-q /path/to/my-app/config/query.json"))) assert_that(generated_jobs, has_item( contains_string("-c /path/to/my-app/config/creds.json"))) assert_that(generated_jobs, has_item( contains_string("-t /path/to/my-app/config/token.json"))) assert_that(generated_jobs, has_item( contains_string("-b /path/to/my-app/config/performanceplatform.json"))) assert_that(generated_jobs, has_item('# End performanceplatform.collector jobs for some_id'))
def test_other_cronjobs_are_preserved(self): with temp_file("") as jobs_path: generated_jobs = crontab.generate_crontab(['other cronjob'], jobs_path, "/path/to/app", "some_id") assert_that(generated_jobs, has_item("other cronjob"))
def test_some_cronjobs_are_added_between_containing_comments(self): with temp_file( "schedule,collector-slug,creds.json,token.json,performanceplatform.json" ) as jobs_path: generated_jobs = crontab.generate_crontab([], jobs_path, "/path/to/my-app", 'some_id') assert_that( generated_jobs, has_item( '# Begin performanceplatform.collector jobs for some_id')) assert_that(generated_jobs, has_item(contains_string("schedule"))) assert_that(generated_jobs, has_item(contains_string("-l collector-slug"))) assert_that( generated_jobs, has_item( contains_string("-c /path/to/my-app/config/creds.json"))) assert_that( generated_jobs, has_item( contains_string("-t /path/to/my-app/config/token.json"))) assert_that( generated_jobs, has_item( contains_string( "-b /path/to/my-app/config/performanceplatform.json"))) assert_that( generated_jobs, has_item( '# End performanceplatform.collector jobs for some_id'))
def test_other_cronjobs_are_preserved(self): with temp_file("") as jobs_path: generated_jobs = crontab.generate_crontab( ['other cronjob'], jobs_path, "/path/to/app", "some_id") assert_that(generated_jobs, has_item("other cronjob"))
def test_added_jobs_run_the_crontab_module(self): with temp_file( "schedule,collector-slug,creds.json,token.json,performanceplatform.json" ) as jobs_path: generated_jobs = crontab.generate_crontab([], jobs_path, "/path/to/my-app", "some_id") assert_that(generated_jobs, has_item(contains_string("pp-collector")))
def test_added_jobs_run_the_crontab_module(self): with temp_file("schedule,query.json,creds.json,token.json,performanceplatform.json") as jobs_path: generated_jobs = crontab.generate_crontab( [], jobs_path, "/path/to/my-app", "some_id") assert_that(generated_jobs, has_item( contains_string("pp-collector")))
def test_existing_pp_cronjobs_are_purged(self): with temp_file( "schedule,collector-slug,creds.json,token.json,performanceplatform.json" ) as jobs_path: generated_jobs = crontab.generate_crontab([ '# Begin performanceplatform.collector jobs for some_id', 'other job', '# End performanceplatform.collector jobs for some_id' ], jobs_path, "/path/to/my-app", 'some_id') assert_that(generated_jobs, is_not(has_item(contains_string("other job"))))
def test_existing_pp_cronjobs_are_purged(self): with temp_file("schedule,query.json,creds.json,token.json,performanceplatform.json") as jobs_path: generated_jobs = crontab.generate_crontab( [ '# Begin performanceplatform.collector jobs for some_id', 'other job', '# End performanceplatform.collector jobs for some_id' ], jobs_path, "/path/to/my-app", 'some_id') assert_that(generated_jobs, is_not(has_item(contains_string("other job"))))
def test_can_handle_whitespace_and_comments(self): temp_contents = ( "# some comment\n" " \n" "schedule,collector-slug,creds,token,performanceplatform\n") with temp_file(temp_contents) as something: generated_jobs = crontab.generate_crontab([], something, "/path/to/my-app", "unique-id-of-my-app") job_contains = "pp-collector -l collector-slug" assert_that(generated_jobs, has_item(contains_string(job_contains)))
def test_can_use_id_for_generating_crontab_entries(self): with temp_file("something, something, something, something, dark side") as something: generated_jobs = crontab.generate_crontab( [], something, "/path/to/my-app", "unique-id-of-my-app" ) assert_that(generated_jobs, has_item('# Begin performanceplatform.collector jobs ' 'for unique-id-of-my-app')) assert_that(generated_jobs, has_item('# End performanceplatform.collector jobs ' 'for unique-id-of-my-app'))
def test_can_use_id_for_generating_crontab_entries(self): with temp_file("something, something, something, something, dark side" ) as something: generated_jobs = crontab.generate_crontab([], something, "/path/to/my-app", "unique-id-of-my-app") assert_that( generated_jobs, has_item('# Begin performanceplatform.collector jobs ' 'for unique-id-of-my-app')) assert_that( generated_jobs, has_item('# End performanceplatform.collector jobs ' 'for unique-id-of-my-app'))
def test_can_handle_whitespace_and_comments(self): temp_contents = ("# some comment\n" " \n" "schedule,query,creds,token,performanceplatforn\n") with temp_file(temp_contents) as something: generated_jobs = crontab.generate_crontab( [], something, "/path/to/my-app", "unique-id-of-my-app" ) job_contains = "pp-collector -q /path/to/my-app/config/query" assert_that(generated_jobs, has_item( contains_string(job_contains)))
def test_jobs_based_on_hostname_with_3(self, hostname): hostname.return_value = 'development-3' temp_contents = ("schedule,query,creds,token,performanceplatforn\n" "schedule2,query2,creds2,token2,performanceplatforn\n" "schedule3,query2,creds3,token3,performanceplatforn\n" ) with temp_file(temp_contents) as something: generated_jobs = crontab.generate_crontab( [], something, "/path/to/my-app", "unique-id-of-my-app" ) assert_that(generated_jobs, has_length(3))
def test_jobs_based_on_hostname_with_1(self, hostname): hostname.return_value = 'development-1' temp_contents = ( "schedule,collector-slug,creds,token,performanceplatform\n" "schedule2,collector-slug2,creds2,token2,performanceplatform\n" "schedule3,collector-slug2,creds3,token3,performanceplatform\n") with temp_file(temp_contents) as something: generated_jobs = crontab.generate_crontab([], something, "/path/to/my-app", "unique-id-of-my-app") assert_that(removeCommentsFromCrontab(generated_jobs), has_length(1)) assert_that( removeCommentsFromCrontab(generated_jobs)[0], contains_string("schedule2 "))
def test_jobs_based_on_hostname_with_1(self, hostname): hostname.return_value = 'development-1' temp_contents = ("schedule,collector-slug,creds,token,performanceplatform\n" "schedule2,collector-slug2,creds2,token2,performanceplatform\n" "schedule3,collector-slug2,creds3,token3,performanceplatform\n" ) with temp_file(temp_contents) as something: generated_jobs = crontab.generate_crontab( [], something, "/path/to/my-app", "unique-id-of-my-app" ) assert_that( removeCommentsFromCrontab(generated_jobs), has_length(1)) assert_that(removeCommentsFromCrontab( generated_jobs)[0], contains_string("schedule2 "))