def test_event_copy(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") url = url_for('events.copy_event', event_id=event.id) rv = self.app.get(url, follow_redirects=True) self.assertTrue("Copy of event1" in rv.data, msg=rv.data)
def test_unpublished_event_view_attempt(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event Saved") rv = self.app.get(url_for('event_detail.display_event_detail_home', event_id=event.id), follow_redirects=True) self.assertEqual(rv.status_code, 404)
def test_scheduler_publish(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") rv = self.app.get(url_for('event_scheduler.publish', event_id=event.id), follow_redirects=True) event = DataGetter.get_event(event.id) self.assertTrue(event.schedule_published_on is not None, msg=rv.data)
def test_speakers_list(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") url = url_for('event_speakers.index_view', event_id=event.id) rv = self.app.get(url, follow_redirects=True) self.assertTrue("Speakers" in rv.data, msg=rv.data)
def parse_speakers(): with current_app.app_context(): with open('open_event/tools/fossasia/speakers.json', 'r+') as f: a = json.load(f) for spek in a['speakers']: sp = get_or_create(Speaker, name=spek['name'], organisation=spek['organisation'], email="", country="", photo="", web="", event_id=event_id, ) # sp.email = spek['email'] sp.country = spek['country'] sp.photo = spek['photo'] sp.web = spek['web'] sp.photo = spek['photo'] sp.twitter = spek['twitter'] sp.linkedin = spek['linkedin'] sp.github = spek['github'] sp.organisation = spek['organisation'] sp.biography = spek['biography'] save_to_db(sp, "Speaker")
def test_session_delete(self): with app.test_request_context(): session = ObjectMother.get_session() save_to_db(session, "Session Saved") url = url_for('event_sessions.delete_session', event_id=1, session_id=session.id) rv = self.app.get(url, follow_redirects=True) self.assertTrue("deleted" in rv.data, msg=rv.data)
def test_events_edit(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") custom_forms = ObjectMother.get_custom_form(event.id) save_to_db(custom_forms, "Custom forms saved") url = url_for('events.edit_view', event_id=event.id) data = POST_EVENT_DATA.copy() del data['copyright'] data['sponsors[name]'] = ['Sponsor 1', 'Sponsor 2'] data['sponsors[type]'] = ['Gold', 'Silver'] data['sponsors[url]'] = ["", ""] data['sponsors[description]'] = ["", ""] data['sponsors[level]'] = ["", ""] data['name'] = 'EditTestName' data['start_date'] = '07/04/2016' data['start_time'] = '19:00' data['end_date'] = '07/04/2016' data['end_time'] = '22:00' data['custom_form[name]'] = ['session_form', 'speaker_form'] data['custom_form[value]'] = [custom_forms.session_form, custom_forms.speaker_form] data = ImmutableMultiDict(data) rv = self.app.post(url, follow_redirects=True, buffered=True, content_type='multipart/form-data', data=data) self.assertTrue('EditTestName' in rv.data, msg=rv.data) self.assertTrue(data['sponsors[name]'] in rv.data, msg=rv.data)
def test_wrong_form_config(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") url = url_for('event_sessions.create_view', event_id=event.id) rv = self.app.get(url, follow_redirects=True) self.assertFalse("incorrectly configured" in rv.data, msg=rv.data)
def test_event_delete(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") url = url_for('events.delete_view', event_id=event.id) rv = self.app.get(url, follow_redirects=True) self.assertTrue("Your event has been deleted" in rv.data, msg=rv.data)
def test_event_delete(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") url = url_for('events.trash_view', event_id=event.id) rv = self.app.get(url, follow_redirects=True) self.assertTrue("Your event has been deleted" in rv.data, msg=rv.data)
def save_db_model(new_model, model_name, event_id=None): """ Save a new/modified model to database """ save_to_db(new_model, "Model %s saved" % model_name) if not event_id: update_version(event_id, False, "session_ver") return new_model
def test_restore_user_from_trash(self): user = User(password="******", email="*****@*****.**", in_trash=True) with app.test_request_context(): save_to_db(user, "User saved") restore_user(1) self.assertEqual(user.in_trash, False)
def test_published_event_view_coc(self): with app.test_request_context(): event = ObjectMother.get_event() event.state = 'Published' save_to_db(event, "Event Saved") rv = self.app.get(url_for('event_detail.display_event_coc', event_id=event.id), follow_redirects=True) self.assertTrue("Code of Conduct" in rv.data, msg=rv.data)
def test_event_publish(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") url = url_for('events.publish_event', event_id=event.id) rv = self.app.get(url, follow_redirects=True) event = DataGetter.get_event(event.id) self.assertEqual("Published", event.state, msg=event.state)
def set_settings(**kwargs): """ Update system settings """ setting = Setting(**kwargs) from open_event.helpers.data import save_to_db save_to_db(setting, 'Setting saved') current_app.config['custom_settings'] = make_dict(setting)
def test_scheduler_view(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") rv = self.app.get(url_for('event_scheduler.display_view', event_id=event.id), follow_redirects=True) self.assertTrue("Scheduler" in rv.data, msg=rv.data)
def test_api_tracks(self): self.assertEqual(self.app.get('/api/v1/event/1').status_code, 404) event = ObjectMother.get_event() track = ObjectMother.get_track() with app.test_request_context(): save_to_db(event, "Event saved") save_to_db(track, "Track saved") self.assertEqual(self.app.get('/api/v1/event/1').status_code, 200) self.assertEqual(self.app.get('/api/v1/event/1/tracks').status_code, 200)
def test_restore_event_from_trash(self): event = Event(name="event1", start_time=datetime(2003, 8, 4, 12, 30, 45), end_time=datetime(2003, 9, 4, 12, 30, 45), in_trash=True) with app.test_request_context(): save_to_db(event, "Event saved") restore_event(1) self.assertEqual(event.in_trash, False)
def test_event_delete(self): with app.test_request_context(): event = ObjectMother.get_event() register(self.app, u'*****@*****.**', u'test2') login(self.app, '*****@*****.**', 'test2') save_to_db(event, "Event saved") url = url_for('events.delete_view', event_id=event.id) rv = self.app.get(url, follow_redirects=True) self.assertTrue("Forbidden" in rv.data, msg=rv.data)
def test_session_create(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") custom_form = ObjectMother.get_custom_form(event.id) save_to_db(custom_form, "Custom form saved") url = url_for('event_sessions.create_view', event_id=event.id) rv = self.app.get(url, follow_redirects=True) self.assertTrue("Create Session" in rv.data, msg=rv.data)
def setUp(self): self.app = Setup.create_app() with app.test_request_context(): event = ObjectMother.get_event() event.owner = 1 track = ObjectMother.get_track() save_to_db(event,"Event saved") save_to_db(track, "Track saved") register(self.app,'test', '*****@*****.**', 'test')
def setUp(self): self.app = Setup.create_app() with app.test_request_context(): event = ObjectMother.get_event() event.owner = 1 track = ObjectMother.get_track() save_to_db(event, "Event saved") save_to_db(track, "Track saved") register(self.app, 'test', '*****@*****.**', 'test')
def test_speaker_delete(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") speaker = ObjectMother.get_speaker() speaker.event_id = event.id save_to_db(speaker, "Session Saved") url = url_for('event_speakers.delete', event_id=event.id, speaker_id=speaker.id) rv = self.app.get(url, follow_redirects=True) self.assertTrue("deleted" in rv.data, msg=rv.data)
def test_sessions_list(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") session = ObjectMother.get_session(event.id) save_to_db(session, "Session Saved") url = url_for('event_sessions.index_view', event_id=event.id, session_id=session.id) rv = self.app.get(url, follow_redirects=True) self.assertTrue("Sessions" in rv.data, msg=rv.data) self.assertTrue("test" in rv.data, msg=rv.data)
def test_wrong_form_config(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") speaker = ObjectMother.get_speaker() speaker.event_id = event.id save_to_db(speaker, "Speaker saved") url = url_for('event_speakers.edit_view', event_id=event.id, speaker_id=speaker.id) rv = self.app.get(url, follow_redirects=True) self.assertFalse("incorrectly configured" in rv.data, msg=rv.data)
def test_api_tracks(self): self.assertEqual(self.app.get('/api/v1/event/1').status_code, 404) event = ObjectMother.get_event() track = ObjectMother.get_track() with app.test_request_context(): save_to_db(event, "Event saved") save_to_db(track, "Track saved") self.assertEqual(self.app.get('/api/v1/event/1').status_code, 200) self.assertEqual( self.app.get('/api/v1/event/1/tracks').status_code, 200)
def test_session_reject(self): with app.test_request_context(): session = ObjectMother.get_session() self.login() save_to_db(session, "Session Saved") url = url_for('event_sessions.reject_session', event_id=1, session_id=1) rv = self.app.get(url, follow_redirects=True) self.assertTrue("Forbidden" in rv.data, msg=rv.data)
def test_session_view(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event) session = ObjectMother.get_session() session.event_id = event.id save_to_db(session, "Session Saved") url = url_for('event_sessions.session_display_view', event_id=event.id, session_id=session.id) rv = self.app.get(url, follow_redirects=True) self.assertTrue("Short abstract" in rv.data, msg=rv.data)
def setUp(self): self.app = Setup.create_app() with app.test_request_context(): event = Event(name="event1", start_time=datetime(2013, 8, 4, 12, 30, 45), end_time=datetime(2016, 9, 4, 12, 30, 45)) event.owner = 1 save_to_db(event, "Event saved") self.event_form = EventForm() self.session_form = SessionForm()
def test_session_create_post(self): with app.test_request_context(): event = ObjectMother.get_event() save_to_db(event, "Event saved") custom_form = ObjectMother.get_custom_form(event.id) save_to_db(custom_form, "Custom form saved") data = POST_SESSION_DATA data.update(POST_SPEAKER_DATA) url = url_for('event_sessions.create_view', event_id=event.id) rv = self.app.post(url, follow_redirects=True, buffered=True, content_type='multipart/form-data', data=data) self.assertTrue(data['title'] in rv.data, msg=rv.data)
def create_event(name='TestEvent', creator_email=None): """Creates Event and returns its `id`. :param name Name of Event """ event = Event(name=name, start_time=datetime(2013, 8, 4, 12, 30, 45), end_time=datetime(2016, 9, 4, 12, 30, 45)) if creator_email: event.creator = User.query.filter_by(email=creator_email).first() save_to_db(event, 'Event saved') return event.id
def create_event(name='TestEvent'): """Creates Event and returns its `id`. :param name Name of Event """ event = Event(name=name, start_time=datetime(2013, 8, 4, 12, 30, 45), end_time=datetime(2016, 9, 4, 12, 30, 45)) event.owner = 1 save_to_db(event, 'Event saved') return event.id
def test_api_tracks(self): with self.assertRaises(Exception) as context: self.app.get('/api/v1/event/1') self.assertTrue(AttributeError, context.exception) event = ObjectMother.get_event() track = ObjectMother.get_track() with app.test_request_context(): save_to_db(event, "Event saved") save_to_db(track, "Track saved") self.assertEqual(self.app.get('/api/v1/event/1').status_code, 200) self.assertEqual(self.app.get('/api/v1/event/1/tracks').status_code, 200)
def test_event_unpublish(self): with app.test_request_context(): event = ObjectMother.get_event() event.state = "Published" register(self.app, u'*****@*****.**', u'test2') login(self.app, '*****@*****.**', 'test2') save_to_db(event, "Event saved") url = url_for('events.unpublish_event', event_id=event.id) rv = self.app.get(url, follow_redirects=True) event = DataGetter.get_event(event.id) self.assertEqual("Draft", event.state, msg=event.state)
def setUp(self): self.app = Setup.create_app() with app.test_request_context(): event = Event(name="event1", start_time=datetime(2013, 8, 4, 12, 30, 45), end_time=datetime(2016, 9, 4, 12, 30, 45)) event.owner = 1 save_to_db(event,"Event saved") self.event_form = EventForm() self.session_form = SessionForm()
def create_event(name='TestEvent', creator_email=None): """Creates Event and returns its `id`. :param name Name of Event """ event = Event(name=name, start_time=datetime(2016, 4, 8, 12, 30, 45), end_time=datetime(2016, 4, 9, 12, 30, 45)) if creator_email: event.creator = User.query.filter_by(email=creator_email).first() save_to_db(event, 'Event saved') return event.id
def import_event_json(zip_path): """ Imports and creates event from json zip """ path = 'static/temp/import_event' # delete existing files if os.path.isdir(path): shutil.rmtree(path, ignore_errors=True) # extract files from zip with zipfile.ZipFile(zip_path, "r") as z: z.extractall('static/temp/import_event') # create event data = json.loads(open(path + '/event.json', 'r').read()) _, data = _trim_id(data) data = _delete_fields(('event', EventDAO), data) new_event = EventDAO.create(data, 'dont')[0] # create other services try: service_ids = {} for item in IMPORT_SERIES: data = open(path + '/%s.json' % item[0], 'r').read() dic = json.loads(data) changed_ids = create_service_from_json(dic, item, new_event.id, service_ids) service_ids[item[0]] = changed_ids.copy() except BaseError as e: EventDAO.delete(new_event.id) raise e except Exception: EventDAO.delete(new_event.id) raise ServerError() custom_form = CustomForms( event_id=new_event.id, session_form= '{"title":{"include":1,"require":1},"subtitle":{"include":0,"require":0},' '"short_abstract":{"include":1,"require":0},"long_abstract":{"include":0,' '"require":0},"comments":{"include":1,"require":0},"track":{"include":0,' '"require":0},"session_type":{"include":0,"require":0},"language":{"include":0,' '"require":0},"slides":{"include":1,"require":0},"video":{"include":0,' '"require":0},"audio":{"include":0,"require":0}}', speaker_form= '{"name":{"include":1,"require":1},"email":{"include":1,"require":1},' '"photo":{"include":1,"require":0},"organisation":{"include":1,' '"require":0},"position":{"include":1,"require":0},"country":{"include":1,' '"require":0},"short_biography":{"include":1,"require":0},"long_biography"' ':{"include":0,"require":0},"mobile":{"include":0,"require":0},' '"website":{"include":1,"require":0},"facebook":{"include":0,"require":0},' '"twitter":{"include":1,"require":0},"github":{"include":0,"require":0},' '"linkedin":{"include":0,"require":0}}') save_to_db(custom_form, "Custom form saved") return new_event
def create_services(): track = Track.get_service_name() session = Session.get_service_name() speaker = Speaker.get_service_name() sponsor = Sponsor.get_service_name() microlocation = Microlocation.get_service_name() save_to_db(Service(track), 'Service saved') save_to_db(Service(session), 'Service saved') save_to_db(Service(speaker), 'Service saved') save_to_db(Service(sponsor), 'Service saved') save_to_db(Service(microlocation), 'Service saved')
def _save(self, row): title = row["title"] subtitle = None description = row["description"] try: start_time = row["begin"].split('.')[0] end_time = row["end"].split('.')[0] event_id = self.event_id abstract = row["abstract"] format = None level = None speakers = [] track = None with current_app.app_context(): level = get_or_create(Level, name=row["level"]["id"], label_en=row["level"]["label_en"], event_id=event_id) format = get_or_create(Format, name=row["format"]["id"], label_en=row["format"]["label_en"], event_id=event_id) lang = get_or_create(Language, name=row["lang"]["id"], label_en=row["lang"]["label_en"], label_de=row["lang"]["label_en"], event_id=event_id) for speaker in row['speakers']: speakers.append( Speaker.query.filter_by(name=speaker['name']).first()) new_session = get_or_create( Session, title=title, subtitle=subtitle, description=description, start_time=datetime.strptime(start_time, '%Y-%m-%dT%H:%M:%S'), end_time=datetime.strptime(end_time, '%Y-%m-%dT%H:%M:%S'), event_id=event_id, abstract=abstract, level=level, format=format, language=lang) new_session.speakers = speakers new_session.track = Track.query.filter_by( name=row['track']['label_en']).first() save_to_db(new_session, "Session Updated") except Exception as e: print e
def update_model(model, item_id, data, event_id=None): """ Updates a model """ if event_id is not None: item = get_object_in_event(model, item_id, event_id) else: item = get_object_or_404(model, item_id) db.session.query(model).filter_by(id=item_id).update(dict(data)) # model.__table__.update().where(model.id==item_id).values(**data) save_to_db(item, "%s updated" % model.__name__) if event_id: update_version(event_id, False, "session_ver") return item
def create_model(model, data, event_id=None): """ Creates a model. If event_id is set, the model is assumed as a child of event i.e. Service Model """ if event_id is not None: get_object_or_404(EventModel, event_id) data['event_id'] = event_id new_model = model(**data) save_to_db(new_model, "Model %s saved" % model.__name__) if event_id: update_version(event_id, False, "session_ver") return new_model