Esempio n. 1
0
 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%.')
Esempio n. 2
0
 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.')
Esempio n. 3
0
 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.')
Esempio n. 4
0
 def find(self, id):
     result = self._database.execute('select * from %s where id = %d' %
                                     (self._table, int(id)))
     row = result.fetchone()
     return Template(id=row.id,
                     title=row.title,
                     subject=row.subject,
                     text=row.text)
Esempio n. 5
0
 def findAll(self):
     result = self._database.execute('select * from %s' % (self._table))
     templates = []
     for row in result:
         templates.append(
             Template(id=row.id,
                      title=row.title,
                      subject=row.subject,
                      text=row.text))
     return templates
Esempio n. 6
0
 def test_template_can_contain_percentage_sign_without_a_defined_variables(self):
     template = Template('Hello %greeting% 5% remains!')
     template.variables = {'greeting': 'there'}
     self.assertEqual(template.text, 'Hello there 5% remains!')
 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 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%')
Esempio n. 9
0
 def test_template_variables_still_work_over_multiple_lines(self):
     template = Template("Hello %firstname%!\n Is your lastname %lastname%?")
     template.variables = {'firstname': 'Michael', 'lastname': 'McMillan'}
     self.assertEqual(template.text, 'Hello Michael!\n Is your lastname McMillan?')
Esempio n. 10
0
 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%')
Esempio n. 11
0
 def test_template_can_extract_variables_from_text(self):
     variables = Template.extract_variables('Hello %firstname%. You are %age% years old?')
     self.assertEqual('firstname' in variables, True)
     self.assertEqual('age'       in variables, True)
Esempio n. 12
0
 def test_template_variable_extraction_ignores_doubled_percentages(self):
     variables = Template.extract_variables('Hello %%firstname%%. You are %age% years old?')
     self.assertEqual('age' in variables, True)
 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.')
Esempio n. 14
0
 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')
Esempio n. 15
0
 def test_template_can_replace_variables_with_values(self):
     template = Template('Hello %firstname% %lastname%!')
     template.variables = {'firstname': 'Michael', 'lastname': 'McMillan'}
     self.assertEqual(template.text, 'Hello Michael McMillan!')
 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_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%.')
Esempio n. 18
0
 def test_template_has_a_default_subject(self):
     template = Template('This is a template with a default title.',
                         subject='Subject')
     self.assertEqual(template.subject, 'Subject')
Esempio n. 19
0
 def test_template_variable_can_be_used_multiple_times(self):
     template = Template('Hello %name%. Do you like the name %name%?')
     template.variables = {'name': 'Michael'}
     self.assertEqual(template.text, 'Hello Michael. Do you like the name Michael?')