def test_should_not_validate_if_message_data_is_equal_default(self): with app.app_context(): form = CertificateForm(participants='john,[email protected]') self.assertFalse(form.validate(), 'A malformed form was validated successfully') self.assertEqual( form.errors['message'][0], 'You need provide a custom text to your form message')
def test_should_not_validate_for_msg_with_no_participant_placeholder(self): with app.app_context(): form = CertificateForm(message='message without placeholder', participants='john,[email protected]') self.assertFalse(form.validate(), 'A malformed form was validated successfully') self.assertEqual(form.errors['message'][0], 'Your message need a [participante] placeholder')
def test_should_not_validate_if_participants_dont_have_a_valid_csv(self): with app.app_context(): form = CertificateForm( message='message with [participante] placeholder', participants='wrong-format') self.assertFalse(form.validate(), 'A malformed form was validated successfully') self.assertEqual(form.errors['participants'][0], 'You provide a wrong formated participants list')
def test_should_valid_form_have_a_participants_list_with_parsed_data(self): with app.app_context(): form = CertificateForm( message='message with [participante] placeholder', participants='john,[email protected]') form.validate() self.assertTrue(form.participants_list) self.assertEqual(form.participants_list, [{ 'name': 'john', 'email': '*****@*****.**' }])
def test_should_save_on_mongodb_if_data_is_correct(self, enqueue_mock): self.client.post('/send-certificates', data={ 'logo': '123', 'message': 'abc [participante] def', 'participants': 'rael,[email protected]' }) with app.app_context(): certificate = mongo.db.certificates.find_one() self.assertTrue(certificate) self.assertEqual(certificate['logo'], '123') self.assertEqual(certificate['message'], 'abc [participante] def') self.assertEqual(certificate['participants'], [{ 'name': 'rael', 'email': '*****@*****.**' }])
def test_should_not_validate_empty_form(self): with app.app_context(): form = CertificateForm() self.assertFalse( form.validate(), 'A empty CertificateForm was validated successfully')
def test_should_have_a_textarea_to_participants(self): with app.app_context(): form = CertificateForm() self.assertEqual(form.participants.type, 'TextAreaField')
def test_should_have_a_textarea_to_message(self): with app.app_context(): form = CertificateForm() self.assertEqual(form.message.type, 'TextAreaField')
def test_should_have_a_hiddenfield_to_logo_value(self): with app.app_context(): form = CertificateForm() self.assertEqual(form.logo.type, 'HiddenField')
def test_should_have_a_filefield_to_logo(self): with app.app_context(): form = CertificateForm() self.assertEqual(form.logo_file.type, 'FileField')
def tearDown(self): with app.app_context(): mongo.db.command('dropDatabase')