def __init__(self, ssh_client): Job.__init__(self) self.ssh_client = ssh_client self._raw_output = [] self._last_log = None self._parser = RemoteScriptOutputParser()
def test_board_can_extract_jobs_by_status(self): jobs = [ Job(status='pending'), Job(status='active'), Job(status='active') ] board = Board(jobs=jobs) self.assertEqual(len(board.jobs_by_status('pending')), 1)
def test_exception_is_not_thrown_when_job_without_company_is_provided( self): template = Template('Your job is titled: %job.company%.') template.job = Job(title='Developer', place='Trondheim', position='Fulltid') self.assertEqual(template.text, 'Your job is titled: %job.company%.')
def test_job_with_a_non_active_status_can_be_previewed_if_correct_token_supplied( self): controller = mock_job_controller(JobController(database=None)) controller.job_repository.find.return_value = Job(id=1, status='pending', edit_url='s3cR3t') controller.preview(id=1, token='s3cR3t') assert controller.abort.called == False
def test_job_can_be_loaded_after_object_has_been_constructed(self): template = Template( 'Your job is titled: %job.title% and is %job.position% type job.') template.job = Job(title='Developer', place='Trondheim', position='Fulltid') self.assertEqual( template.text, 'Your job is titled: Developer and is Fulltid type job.')
def test_multiple_job_properties_can_be_referenced_in_template(self): template = Template( 'Your job is titled: %job.title% and is %job.position% type job.') template.job = Job(title='Developer', place='Trondheim', position='Fulltid') self.assertEqual( template.text, 'Your job is titled: Developer and is Fulltid type job.')
def get_job_from_request(self, job=None): job = job or Job() job.company = self.company_repository.find( self.request.form['company']) job.title = self.request.form.get('title') job.status = self.request.form.get('status') job.description = self.request.form.get('description') job.due_date = self.request.form.get('due_date') job.start_date = self.request.form.get('start_date') job.position = self.request.form.get('position') job.place = self.request.form.get('place') job.apply_url = self.request.form.get('apply_url') return job
def find(self, id): result = self._database.execute('select * from %s where id = %d' % (self._table, id)) row = result.fetchone() if row is None: return None company = self._companyRepository.find(row.company_id) job = Job(id=row.id, title=row.title, description=row.description, due_date=row.due_date, company=company, place=row.place, position=row.position, start_date=row.start_date, status=row.status, edit_url=row.edit_url, apply_url=row.apply_url) return job
def findAll(self): result = self._database.execute('select * from %s order by id desc' % (self._table)) jobs = [] for row in result: company = self._companyRepository.find(row.company_id) job = Job(id=row.id, title=row.title, description=row.description, due_date=row.due_date, company=company, place=row.place, position=row.position, start_date=row.start_date, status=row.status, edit_url=row.edit_url, apply_url=row.apply_url) jobs.append(job) return jobs
def test_board_can_set_jobs_in_constructor(self): jobs = [Job(), Job(), Job()] board = Board(jobs = jobs) self.assertEqual(len(board.jobs), 3)
def test_board_ignores_expired_jobs_when_extracting_by_status(self): jobs = [Job(due_date=datetime.date(1991, 4, 20), status='dead')] board = Board(jobs=jobs) self.assertEqual(len(board.jobs_by_status('dead')), 1)
def test_job_can_override_its_unique_url_in_init(self): job = Job(edit_url='some-random-url-in-init') self.assertEqual(job.edit_url, 'some-random-url-in-init')
def test_board_ignores_sort_if_attribute_does_not_exist(self): jobs = [Job(title="cccccc"), Job(title="bbbbbb"), Job(title="aaaaaa")] board = Board(jobs = jobs) not_sorted_jobs = board.jobs_sorted_by(attribute = 'non-existent-field') self.assertEqual(not_sorted_jobs[0].title, "Cccccc")
def test_job_with_a_non_active_status_returns_404(self): controller = mock_job_controller(JobController(database=None)) controller.job_repository.find.return_value = Job(id=1, status='pending') controller.view(id=1) assert controller.abort.call_args[0][0] == 404
def test_job_raises_exception_if_due_date_is_after_start_date_in_setter( self): with self.assertRaisesRegexp(JobException, 'before'): job = Job(due_date=datetime.date(2000, 1, 1), start_date=datetime.date(2001, 1, 1)) job.due_date = datetime.date(2005, 1, 1)
def test_job_properties_are_not_replaced_when_property_is_none(self): template = Template('Your job is at: %job.place%') template.job = Job(title='Developer', place=None, position='Deltid') self.assertEqual(template.text, 'Your job is at: %job.place%')
def test_job_does_not_raise_exception_if_start_date_is_same_as_due_date(self): job = Job(due_date = datetime.date(2000, 1, 1)) job.start_date = datetime.date(2000, 1, 1)
def test_job_raises_exception_if_due_date_is_after_start_date_in_setter(self): with self.assertRaisesRegexp(JobException, 'before'): job = Job(due_date = datetime.date(2000, 1, 1), start_date = datetime.date(2001, 1, 1)) job.due_date = datetime.date(2005, 1, 1)
def test_job_raises_exception_if_start_date_is_before_due_date_in_setter(self): with self.assertRaisesRegexp(JobException, 'after'): job = Job(due_date = datetime.date(2000, 1, 1)) job.start_date = datetime.date(1999, 1, 1)
def test_job_with_an_active_status_does_not_return_404(self): controller = mock_job_controller(JobController(database=None)) controller.job_repository.find.return_value = Job(id=2, status='active') controller.view(id=2) assert controller.abort.called == False
Apache 2.0 http://www.apache.org/licenses/LICENSE-2.0 """ # --- Imports import sys from src.job.job import Job from src.application.app import App # --- Setup debug = True # --- Classes / globals job = Job() application = App() version = application.version # --- Private funcs def _version(): print({"name":"viki", "version":version}) def _usage(): """ Print viki-cli usage""" print('Usage:') print(' viki h|help') print(' viki ll|list')
def test_both_dates_are_included_in_exception_message(self): with self.assertRaisesRegexp(JobException, '2000|1999'): Job(due_date=datetime.date(2000, 1, 1), start_date=datetime.date(1999, 1, 1))
def test_job_raises_exception_if_start_date_is_before_due_date_in_setter( self): with self.assertRaisesRegexp(JobException, 'after'): job = Job(due_date=datetime.date(2000, 1, 1)) job.start_date = datetime.date(1999, 1, 1)
def test_job_raises_exception_if_start_date_is_before_due_date_in_constructor( self): with self.assertRaisesRegexp(JobException, 'after'): Job(due_date=datetime.date(2000, 1, 1), start_date=datetime.date(1999, 1, 1))
def test_job_does_not_raise_exception_if_start_date_is_same_as_due_date( self): job = Job(due_date=datetime.date(2000, 1, 1)) job.start_date = datetime.date(2000, 1, 1)
def test_job_gets_assinged_a_unique_url_for_editing(self): edit_urls = [] for i in range(0, 3): edit_url = Job().edit_url self.assertEqual(edit_url in edit_urls, False) edit_urls.append(edit_url)
def test_job_can_have_a_start_date_without_a_due_date_as_long_as_its_after( self, mock_date_today): mock_date_today.return_value = datetime.date(2000, 1, 1) job = Job(start_date=datetime.date(2001, 1, 1))
def test_job_apply_url_is_pound_sign_by_default(self): self.assertEqual(Job().apply_url, '#')
def test_board_can_sort_jobs_by_title(self): jobs = [Job(title="cccccc"), Job(title="bbbbbb"), Job(title="aaaaaa")] board = Board(jobs = jobs) sorted_jobs = board.jobs_sorted_by(attribute = 'title') self.assertEqual(sorted_jobs[0].title, "Aaaaaa")
def test_job_properties_can_be_referenced_when_job_is_provided_to_template( self): template = Template('Your job is titled: %job.title%') template.job = Job(title='Developer', place='Oslo', position='Deltid') self.assertEqual(template.text, 'Your job is titled: Developer')
def test_board_does_not_sort_by_default(self): jobs = [Job(title="xxxxxx"), Job(title="bbbbbb"), Job(title="aaaaaa")] board = Board(jobs = jobs) self.assertEqual(board.jobs[0].title, "Xxxxxx")
def test_job_can_override_its_unique_url(self): job = Job() job.edit_url = 'some-random-url' self.assertEqual(job.edit_url, 'some-random-url')
def test_job_can_have_an_apply_url(self): job = Job(apply_url='http://company.com/apply') self.assertEqual(job.apply_url, 'http://company.com/apply')
def test_job_due_date_can_be_string(self): job = Job(due_date = datetime.date(2001, 1, 1)) job.start_date = '2015-08-19'