예제 #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%.')
예제 #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.')
예제 #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.')
예제 #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)
예제 #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
예제 #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%')
예제 #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?')
예제 #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%')
예제 #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)
예제 #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.')
예제 #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')
예제 #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%.')
예제 #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')
예제 #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?')