def setUp(self): self.ensure_test_user() self.user = User.objects.get(username=TESTUSER) self.place = Place(name='Kiberpipa', note='Bla') self.place.save() self.project = Project(id=23, name='Tehnicarjenje', responsible=self.user) self.project.save(200) self.category = Category(name='Drugo', note='Another bla.') self.category.save() self.tip = TipSodelovanja(name="Predavatelj") self.tip.save()
def setUp(self): self.ensure_test_user() self.user = User.objects.get(username=TESTUSER) self.place = Place(name="Kiberpipa", note="Bla", is_public=True) self.place.save() self.project = Project(id=23, name="Tehnicarjenje", responsible=self.user) self.project.save(200) self.category = Category(name="Drugo", note="Another bla.") self.category.save() self.tip = TipSodelovanja(name="Predavatelj") self.tip.save()
class EventTest(BaseCase): def setUp(self): self.ensure_test_user() self.user = User.objects.get(username=TESTUSER) self.place = Place(name='Kiberpipa', note='Bla') self.place.save() self.project = Project(id=23, name='Tehnicarjenje', responsible=self.user) self.project.save(200) self.category = Category(name='Drugo', note='Another bla.') self.category.save() self.tip = TipSodelovanja(name="Predavatelj") self.tip.save() def create_new_image(self): self.client.login(username=TESTUSER, password=TESTPASSWORD) resp = self.client.get('/intranet/image_crop_tool/') self.assertEqual(resp.status_code, 200) resp = self.client.post('/intranet/tmp_upload/', {'foo': ''}) self.assertEqual(resp.status_code, 200) self.assertEqual(simplejson.loads(resp.content)['status'], 'fail') # TODO: test .png f = open(os.path.join(os.path.dirname(__file__), 'test_fixtures', 'sample-1.jpg'), 'rb') resp = self.client.post('/intranet/tmp_upload/', {'image': f}) f.close() self.assertEqual(resp.status_code, 200) self.assertEqual(simplejson.loads(resp.content)['status'], 'ok') self.assertTrue('temporary_filename' in self.client.session) filename = simplejson.loads(resp.content)['filename'] self.assertEqual(self.client.session.get('temporary_filename'), filename) resp = self.client.post('/intranet/image_crop_tool/resize/', {'resize': '12,253,10,129', 'filename': filename, 'enter_your_email': ''}) self.assertEqual(resp.status_code, 200) self.assertEqual(simplejson.loads(resp.content)['status'], 'ok') resized_filename = simplejson.loads(resp.content)['resized_filename'] resp = self.client.post('/intranet/image_crop_tool/save/', {'resized_filename': resized_filename, 'title': 'To je naslov slike.', 'enter_your_email': ''}) self.assertEqual(resp.status_code, 200) self.assertEqual(simplejson.loads(resp.content)['status'], 'ok') self.image_id = IntranetImage.objects.all()[0].id def test_event_lifetime(self): self.client.login(username=TESTUSER, password=TESTPASSWORD) self.create_new_image() resp = self.client.get('/intranet/events/create/') self.assertEqual(resp.status_code, 200) now = datetime.datetime.now() tomorrow_noon = datetime.datetime(now.year, now.month, now.day, 12, 0) + datetime.timedelta(2) tomorrow_noon_fifteen = datetime.datetime(now.year, now.month, now.day, 13, 0) + datetime.timedelta(2) createdata = { 'event_repeat': 0, 'event_repeat_freq': 1, 'event_repeat_freq_type': 0, 'title': u'Dogodek v Kleti', 'project': self.project.id, 'authors': u'Gašper Žejn - Predavatelj', 'tip': 1, 'category': self.category.id, 'language': 'sl', 'responsible': 1, 'public': 'on', 'start_date': tomorrow_noon.strftime('%Y/%m/%d %H:%M'), 'end_date': tomorrow_noon_fifteen.strftime('%Y/%m/%d %H:%M'), 'require_technician': 'on', 'require_video': 'on', 'place': self.place.id, 'slides': '', 'event_image': self.image_id, 'announce': 'Test event for intranet tests.', 'note': '', 'enter_your_email': '', } resp = self.client.post('/intranet/events/create/', createdata) self.assertEqual(resp.status_code, 302) # if we don't get location, form failed redirect_url, event_id = re.match('http://\w+(/intranet/events/.*(\d+)/)$', resp._headers['location'][1]).groups() # validate urls self.assertEqual(self.client.get('/event/dogodek-v-kleti-1/', follow=True).redirect_chain[-1], ('https://example.com/event/dogodek-v-kleti-1/', 302)) resp = self.client.get(redirect_url) self.assertEqual(resp.status_code, 200) resp = self.client.get(redirect_url + 'info.txt/') self.assertEqual(resp.status_code, 200) for line in [i for i in resp.content.split('\n') if i]: self.assertEqual(re.match('^\S+:\s', line) != None, True) # autocomplete should work now because a sodelovanje was added resp = self.client.get('/intranet/autocomplete/person/', {'q': u'Gašp'}) self.assertEqual(resp.status_code, 200) self.assertEqual('\n' in resp.content, True) # new event is in the events overview page resp = self.client.get('/intranet/events/') self.assertEqual(resp.status_code, 200) self.assertEqual(resp.content.find(redirect_url) > -1, True) # add a number of visitors resp = self.client.post(redirect_url + 'count/', {'visitors': 10, 'enter_your_email': ''}) self.assertEqual(resp.status_code, 302) a_redirect_url, _ = re.match('http://\w+(/intranet/events/(\d+)/)$', resp._headers['location'][1]).groups() self.assertEqual(a_redirect_url, redirect_url) # add emails to be notified email = '*****@*****.**' resp = self.client.post('/intranet/events/%s/emails/' % event_id, {'emails': email, 'enter_your_email': ''}, follow=True) self.assertEqual(resp.status_code, 200) # check that email is listed resp = self.client.get('/intranet/events/%s/' % event_id) self.assertEqual(resp.status_code, 200) self.assertEqual(resp.content.find(email) > -1, True) # tehniki resp = self.client.get('/intranet/tehniki/') self.assertEqual(resp.status_code, 200) # volunteer resp = self.client.get('/intranet/tehniki/add/%s/' % event_id, follow=True) self.assertEqual(resp.status_code, 200) # check volunteering resp = self.client.get('/intranet/tehniki/') self.assertEqual(resp.status_code, 200) # cancel resp = self.client.get('/intranet/tehniki/cancel/%s/' % event_id, follow=True) self.assertEqual(resp.status_code, 200) self.assertEqual(resp.content.find('/intranet/tehniki/cancel/%s/' % event_id), -1) # add diary diarydata = { 'log_formal': 'no kidding', 'log_informal': 'just joking', 'length': '4', 'uniqueSpot': event_id, 'enter_your_email': '', } resp = self.client.post('/intranet/tehniki/add/', diarydata, follow=True) self.assertEqual(resp.status_code, 200) # check monthly view month = ['jan', 'feb', 'mar', 'apr', 'maj', 'jun', 'jul', 'avg', 'sep', 'okt', 'nov', 'dec'][tomorrow_noon.month - 1] resp = self.client.get('/intranet/tehniki/%s/%s/' % (tomorrow_noon.year, month)) self.assertEqual(resp.status_code, 200) # test ical resp = self.client.get('/sl/calendar/ical/') self.assertEqual(resp.status_code, 200) self.assertEqual(resp._headers['content-type'][1].startswith('text/calendar'), True)
class EventTest(BaseCase): def setUp(self): self.ensure_test_user() self.user = User.objects.get(username=TESTUSER) self.place = Place(name='Kiberpipa', note='Bla') self.place.save() self.project = Project(id=23, name='Tehnicarjenje', responsible=self.user) self.project.save(200) self.category = Category(name='Drugo', note='Another bla.') self.category.save() self.tip = TipSodelovanja(name="Predavatelj") self.tip.save() def create_new_image(self): self.client.login(username=TESTUSER, password=TESTPASSWORD) resp = self.client.get('/intranet/image_crop_tool/') self.assertEqual(resp.status_code, 200) resp = self.client.post('/intranet/tmp_upload/', {'foo': ''}) self.assertEqual(resp.status_code, 200) self.assertEqual(simplejson.loads(resp.content)['status'], 'no image uploaded') # TODO: test .png f = open(os.path.join(os.path.dirname(__file__), 'test_fixtures', 'sample-1.jpg'), 'rb') resp = self.client.post('/intranet/tmp_upload/', {'image': f}) f.close() self.assertEqual(resp.status_code, 200) self.assertEqual(simplejson.loads(resp.content)['status'], 'ok') self.assertTrue('temporary_filename' in self.client.session) filename = simplejson.loads(resp.content)['filename'] self.assertEqual(self.client.session.get('temporary_filename'), filename) resp = self.client.post('/intranet/image_crop_tool/resize/', {'resize': '12,253,10,129', 'filename': filename, 'enter_your_email': ''}) self.assertEqual(resp.status_code, 200) self.assertEqual(simplejson.loads(resp.content)['status'], 'ok') resized_filename = simplejson.loads(resp.content)['resized_filename'] resp = self.client.post('/intranet/image_crop_tool/save/', {'resized_filename': resized_filename, 'title': 'To je naslov slike.', 'enter_your_email': ''}) self.assertEqual(resp.status_code, 200) self.assertEqual(simplejson.loads(resp.content)['status'], 'ok') self.image_id = IntranetImage.objects.all()[0].id def test_event_lifetime(self): self.client.login(username=TESTUSER, password=TESTPASSWORD) self.create_new_image() resp = self.client.get('/intranet/events/create/') self.assertEqual(resp.status_code, 200) now = datetime.datetime.now() tomorrow_noon = datetime.datetime(now.year, now.month, now.day, 12, 0) + datetime.timedelta(2) tomorrow_noon_fifteen = datetime.datetime(now.year, now.month, now.day, 13, 0) + datetime.timedelta(2) createdata = { 'event_repeat': 0, 'event_repeat_freq': 1, 'event_repeat_freq_type': 0, 'title': u'Dogodek v Kleti', 'project': self.project.id, 'authors': u'Gašper Žejn - Predavatelj', 'tip': 1, 'category': self.category.id, 'language': 'sl', 'responsible': 1, 'public': 'on', 'start_date': tomorrow_noon.strftime('%Y/%m/%d %H:%M'), 'end_date': tomorrow_noon_fifteen.strftime('%Y/%m/%d %H:%M'), 'require_technician': 'on', 'require_video': 'on', 'place': self.place.id, 'slides': '', 'event_image': self.image_id, 'announce': 'Test event for intranet tests.', 'note': '', 'enter_your_email': '', } resp = self.client.post('/intranet/events/create/', createdata) self.assertEqual(resp.status_code, 302) # if we don't get location, form failed redirect_url = resp._headers['location'][1] # <iElectric> lahko predpostavljas, da je 1 event_id = 1 # validate urls self.assertEqual(self.client.get('/event/dogodek-v-kleti-1/', follow=True).redirect_chain[-1], ('http://testserver/sl/event/dogodek-v-kleti-1/', 302)) resp = self.client.get(redirect_url) self.assertEqual(resp.status_code, 200) # new event is in the events overview page resp = self.client.get('/intranet/events/') self.assertEqual(resp.status_code, 200) self.assertEqual(resp.content.find(redirect_url) > -1, True) # TODO: test archive events # add emails to be notified email = '*****@*****.**' resp = self.client.post('/intranet/events/%s/emails/' % event_id, {'emails': email, 'enter_your_email': ''}, follow=True) self.assertEqual(resp.status_code, 200) # TODO: test dezurni for events # volunteer resp = self.client.get('/intranet/events/%s/technician/take/' % event_id, follow=True) self.assertEqual(resp.status_code, 200) # TODO: test if techie is set self.assertTrue(resp.content.find('%s/technician/cancel/' % event_id) > 0) # cancel resp = self.client.get('/intranet/events/%s/technician/cancel/' % event_id, follow=True) self.assertEqual(resp.status_code, 200) self.assertEqual(resp.content.find('%s/technician/cancel/' % event_id), -1) diarydata = { 'log_formal': 'no kidding', 'log_informal': 'just joking', 'length': '4', 'uniqueSpot': event_id, 'enter_your_email': '', } self.client.get('/intranet/events/%s/technician/take/' % event_id, follow=True) resp = self.client.get('/event/dogodek-v-kleti-%s/' % event_id, follow=True) # TODO: add diary for event # test ical # TODO: move to www tests resp = self.client.get('/sl/calendar/ical/') self.assertEqual(resp.status_code, 200) self.assertEqual(resp._headers['content-type'][1].startswith('text/calendar'), True) self.assertTrue(resp.content.startswith('BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Kiberpipa//NONSGML intranet//EN\r\nBEGIN:VEVENT\r\nSUMMARY:'))
class EventTest(BaseCase): def setUp(self): self.ensure_test_user() self.user = User.objects.get(username=TESTUSER) self.place = Place(name="Kiberpipa", note="Bla", is_public=True) self.place.save() self.project = Project(id=23, name="Tehnicarjenje", responsible=self.user) self.project.save(200) self.category = Category(name="Drugo", note="Another bla.") self.category.save() self.tip = TipSodelovanja(name="Predavatelj") self.tip.save() def create_new_image(self): self.client.login(username=TESTUSER, password=TESTPASSWORD) resp = self.client.get("/intranet/image_crop_tool/") self.assertEqual(resp.status_code, 200) resp = self.client.post("/intranet/tmp_upload/", {"foo": ""}) self.assertEqual(resp.status_code, 200) self.assertEqual(simplejson.loads(resp.content)["status"], "no image uploaded") # TODO: test .png f = open(os.path.join(os.path.dirname(__file__), "test_fixtures", "sample-1.jpg"), "rb") resp = self.client.post("/intranet/tmp_upload/", {"image": f}) f.close() self.assertEqual(resp.status_code, 200) self.assertEqual(simplejson.loads(resp.content)["status"], "ok") self.assertTrue("temporary_filename" in self.client.session) filename = simplejson.loads(resp.content)["filename"] self.assertEqual(self.client.session.get("temporary_filename"), filename) resp = self.client.post( "/intranet/image_crop_tool/resize/", {"resize": "12,253,10,129", "filename": filename, "enter_your_email": ""}, ) self.assertEqual(resp.status_code, 200) self.assertEqual(simplejson.loads(resp.content)["status"], "ok") resized_filename = simplejson.loads(resp.content)["resized_filename"] resp = self.client.post( "/intranet/image_crop_tool/save/", {"resized_filename": resized_filename, "title": "To je naslov slike.", "enter_your_email": ""}, ) self.assertEqual(resp.status_code, 200) self.assertEqual(simplejson.loads(resp.content)["status"], "ok") self.image_id = IntranetImage.objects.all()[0].id def test_event_lifetime(self): self.client.login(username=TESTUSER, password=TESTPASSWORD) self.create_new_image() resp = self.client.get("/intranet/events/create/") self.assertEqual(resp.status_code, 200) now = datetime.datetime.now() tomorrow_noon = datetime.datetime(now.year, now.month, now.day, 12, 0) + datetime.timedelta(2) tomorrow_noon_fifteen = datetime.datetime(now.year, now.month, now.day, 13, 0) + datetime.timedelta(2) createdata = { "event_repeat": 0, "event_repeat_freq": 1, "event_repeat_freq_type": 0, "title": u"Dogodek v Kleti", "project": self.project.id, "authors": u"Gašper Žejn - Predavatelj", "tip": 1, "category": self.category.id, "language": "sl", "responsible": User.objects.get(username=TESTUSER).id, "public": "on", "start_date": tomorrow_noon.strftime("%Y/%m/%d %H:%M"), "end_date": tomorrow_noon_fifteen.strftime("%Y/%m/%d %H:%M"), "require_technician": "on", "require_video": "on", "place": self.place.id, "slides": "", "event_image": self.image_id, "announce": "Test event for intranet tests.", "note": "", "enter_your_email": "", } resp = self.client.post("/intranet/events/create/", createdata) self.assertEqual(resp.status_code, 302) # if we don't get location, form failed self.assertRedirects(resp, "/intranet/events/") event_id = 1 # validate urls resp = self.client.get("/event/dogodek-v-kleti-1/", follow=True) self.assertRedirects(resp, "/sl/event/dogodek-v-kleti-1/") resp = self.client.get("/sl/event/dogodek-v-kleti-1/") self.assertEqual(resp.status_code, 200) # new event is in the events overview page resp = self.client.get("/intranet/events/") self.assertEqual(resp.status_code, 200) self.assertEqual(resp.content.find("/intranet/events/%d/edit" % event_id) > -1, True) # TODO: test archive events # add emails to be notified email = "*****@*****.**" resp = self.client.post( "/intranet/events/%s/emails/" % event_id, {"emails": email, "enter_your_email": ""}, follow=True ) self.assertEqual(resp.status_code, 200) # TODO: test dezurni for events # volunteer resp = self.client.get("/intranet/events/%s/technician/take/" % event_id, follow=True) self.assertEqual(resp.status_code, 200) # TODO: test if techie is set self.assertTrue(resp.content.find("%s/technician/cancel/" % event_id) > 0) # cancel resp = self.client.get("/intranet/events/%s/technician/cancel/" % event_id, follow=True) self.assertEqual(resp.status_code, 200) self.assertEqual(resp.content.find("%s/technician/cancel/" % event_id), -1) diarydata = { "log_formal": "no kidding", "log_informal": "just joking", "length": "4", "uniqueSpot": event_id, "enter_your_email": "", } self.client.get("/intranet/events/%s/technician/take/" % event_id, follow=True) resp = self.client.get("/event/dogodek-v-kleti-%s/" % event_id, follow=True) # TODO: add diary for event # test ical # TODO: move to www tests resp = self.client.get("/sl/calendar/ical/") self.assertEqual(resp.status_code, 200) self.assertEqual(resp._headers["content-type"][1].startswith("text/calendar"), True) self.assertTrue( resp.content.startswith( "BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Kiberpipa//NONSGML intranet//EN\r\nBEGIN:VEVENT\r\nSUMMARY:" ) )