def test_send_monthly_invoice(self): """Method to test monthly invoices""" with self.app.test_request_context(): TicketFeesFactory(service_fee=10.23, maximum_fee=11) test_event = EventFactoryBasic(state='published') test_user = UserFactory() test_order = OrderFactory(status='completed') test_order.completed_at = datetime.datetime.now( ) - datetime.timedelta(days=30) test_order.amount = 100 test_order.event = test_event test_ticket_holder = AttendeeFactory() test_ticket_holder.event = test_event test_ticket_holder.order = test_order test_event.owner = test_user db.session.commit() send_monthly_event_invoice() event_invoice = EventInvoice.query.get(1) self.assertEqual(event_invoice.amount, 10.23)
def setUp(self): self.app = Setup.create_app() with self.app.test_request_context(): user = UserFactory() save_to_db(user) event = EventFactoryBasic() event.user_id = user.id save_to_db(event) # Authenticate User self.auth = {'Authorization': "JWT " + create_access_token(user.id, fresh=True)}
def setUp(self): self.app = Setup.create_app() with app.test_request_context(): user = UserFactory() db.session.add(user) db.session.commit() event = EventFactoryBasic() event.user_id = user.id db.session.add(event) db.session.commit() # Authenticate User self.auth = {'Authorization': "JWT " + str(_default_jwt_encode_handler(user), 'utf-8')}
def setUp(self): self.app = Setup.create_app() with app.test_request_context(): user = UserFactory() save_to_db(user) event = EventFactoryBasic() event.user_id = user.id save_to_db(event) # Authenticate User self.auth = { 'Authorization': "JWT " + str(_default_jwt_encode_handler(user), 'utf-8') }
def test_should_create_attendee_forms(self): """Method to test custom forms for attendees of an event.""" with app.test_request_context(): event = EventFactoryBasic() save_to_db(event) create_custom_forms_for_attendees(event) self.assertEqual(get_count(CustomForms.query), 3)
def test_get_identity(self): """Method to test identity of authenticated user""" with self.app.test_request_context(): user = UserFactory() save_to_db(user) event = EventFactoryBasic() event.user_id = user.id save_to_db(event) # Authenticate User self.auth = {'Authorization': "JWT " + create_access_token(user.id, fresh=True)} with self.app.test_request_context(headers=self.auth): self.assertEquals(get_identity().id, user.id)
def setUp(self): self.app = Setup.create_app() with app.test_request_context(): user = UserFactory() db.session.add(user) db.session.commit() event = EventFactoryBasic() event.user_id = user.id db.session.add(event) db.session.commit() # Authenticate User self.auth = { 'Authorization': "JWT " + _default_jwt_encode_handler(user) }
def test_get_identity(self): with app.test_request_context(): user = UserFactory() db.session.add(user) db.session.commit() event = EventFactoryBasic() event.user_id = user.id db.session.add(event) db.session.commit() # Authenticate User self.auth = {'Authorization': "JWT " + _default_jwt_encode_handler(user)} with app.test_request_context(headers=self.auth): self.assertEquals(get_identity().id, user.id)
def test_safe_query(self): with app.test_request_context(): event = EventFactoryBasic() db.session.add(event) db.session.commit() obj = safe_query(db, Event, 'id', event.id, 'event_id') self.assertEqual(obj.name, event.name)
def test_save_to_db(self): """Method to test the function save_to_db""" with self.app.test_request_context(): obj = EventFactoryBasic() save_to_db(obj) event = db.session.query(Event).filter(Event.id == obj.id).first() self.assertEqual(obj.name, event.name)
def test_safe_query(self): """Method to test the function safe_query""" with self.app.test_request_context(): event = EventFactoryBasic() save_to_db(event) obj = safe_query(db, Event, 'id', event.id, 'event_id') self.assertEqual(obj.name, event.name)
def test_should_not_expire_valid_orders(self): """Method to test to not mark valid orders as expired""" with app.test_request_context(): obj = OrderFactory() event = EventFactoryBasic() obj.event = event set_expiry_for_order(obj) self.assertEqual(obj.status, 'pending')
def test_get_identity(self): """Method to test identity of authenticated user""" with app.test_request_context(): user = UserFactory() save_to_db(user) event = EventFactoryBasic() event.user_id = user.id save_to_db(event) # Authenticate User self.auth = { 'Authorization': "JWT " + str(_default_jwt_encode_handler(user), 'utf-8') } with app.test_request_context(headers=self.auth): self.assertEquals(get_identity().id, user.id)
def test_export(self): """Test to check event contents in pentabarfxml format""" with app.test_request_context(): test_event = EventFactoryBasic() save_to_db(test_event) pentabarf_export = PentabarfExporter() pentabarf_string = pentabarf_export.export(test_event.id) pentabarf_original = fromstring(pentabarf_string) self.assertEqual(fromstring(tostring(pentabarf_original))[0][0].text, "example") self.assertEqual(fromstring(tostring(pentabarf_original))[0][1].text, "2099-12-13")
def test_should_expire_outdated_order(self): """Method to test expiration of outdated orders""" with app.test_request_context(): obj = OrderFactory() event = EventFactoryBasic() obj.event = event obj.created_at = datetime.now( timezone.utc) - timedelta(minutes=obj.event.order_expiry_time) set_expiry_for_order(obj) self.assertEqual(obj.status, 'expired')
def test_export(self): """Test to check event contents in pentabarfxml format""" with self.app.test_request_context(): test_event = EventFactoryBasic() save_to_db(test_event) pentabarf_export = PentabarfExporter() pentabarf_string = pentabarf_export.export(test_event.id) pentabarf_original = fromstring(pentabarf_string) self.assertEqual( pentabarf_original.find('conference/title').text, "example") self.assertEqual( pentabarf_original.find('conference/start').text, "2099-12-13")
def test_export(self): """Test to check event contents in xCal format""" with app.test_request_context(): test_event = EventFactoryBasic() save_to_db(test_event) xcal = XCalExporter() xcal_string = xcal.export(test_event.id) xcal_original = fromstring(xcal_string) self.assertEqual( fromstring(tostring(xcal_original))[0][3].text, "example") self.assertEqual( fromstring(tostring(xcal_original))[0][2].text, "Schedule for sessions at example")
def test_date_db_populate(self): """ Events Validate Date - Tests if validation works on values stored in db and not given in 'data' :return: """ with app.test_request_context(): schema = EventSchema() obj = EventFactoryBasic() save_to_db(obj) original_data = {'data': {'id': 1}} data = {} EventSchema.validate_date(schema, data, original_data)
def test_get_or_create(self): with app.test_request_context(): event = EventFactoryBasic() save_to_db(event) obj, is_created = get_or_create(Event, name=event.name) self.assertEqual(event.id, obj.id) self.assertFalse(is_created) obj, is_created = get_or_create(Event, name="new event", starts_at=event.starts_at, ends_at=event.ends_at) self.assertNotEqual(event.id, obj.id) self.assertTrue(is_created)
def test_create_export_job(self): """Method to test export job before creation""" with app.test_request_context(): test_related_event = EventFactoryBasic() save_to_db(test_related_event) test_export_job = ExportJobFactory() save_to_db(test_export_job) test_export_job.event = test_related_event export_event_id = test_export_job.event.id test_task_id = test_export_job.task user = create_user(email='*****@*****.**', password='******') login_user(user) create_export_job(test_task_id, export_event_id) export_job = ExportJob.query.filter_by( event=test_related_event).first() self.assertEqual(export_job.event.name, 'example') self.assertEqual(export_job.user_email, '*****@*****.**')