Exemplo n.º 1
0
    def testFirst(self):
        first_query = self.first_query
        session.query(Event).delete()
        session.commit()
        session.flush()

        e = Event(self.et)
        e.title = 'First event'
        e.time_start = datetime(1970, 1, 1, 0, 0)
        e.time_end = datetime(1970, 1, 1, 3, 0)
        e.description = 'First description'
        e.source_type = EventSourceType.EMPTY
        session.add(e)
        session.commit()

        all_first = first_query.all()
        self.assertEquals(len(all_first), 1)
        e = all_first[0]
        self.assertEquals(e.title, 'First event')
        self.assertEquals(e.time_start, datetime(1970, 1, 1, 0, 0))
        self.assertEquals(e.time_end, datetime(1970, 1, 1, 3, 0))
        self.assertEquals(e.description, 'First description')
        self.assertEquals(e.source_type, EventSourceType.EMPTY)
        self.assertEquals(e.event_type.name, 'first')

        all_date_empty = session.query(Event).filter(
            Event.time_start == date(1971, 1, 1)).all()
        self.assertEquals(len(all_date_empty), 0)
        all_date_fine = session.query(Event).filter(
            Event.time_start == date(1970, 1, 1)).all()
        self.assertEquals(len(all_date_fine), 1)
        session.delete(e)
        session.commit()
Exemplo n.º 2
0
    def testFirst(self):
        first_query = self.first_query
        session.query(Event).delete()
        session.commit()
        session.flush()

        e = Event(self.et)
        e.title = 'First event'
        e.time_start = datetime(1970, 1, 1, 0, 0)
        e.time_end = datetime(1970, 1, 1, 3, 0)
        e.description = 'First description'
        e.source_type = EventSourceType.EMPTY 
        session.add(e)
        session.commit()

        all_first = first_query.all()
        self.assertEquals(len(all_first), 1)
        e = all_first[0]
        self.assertEquals(e.title, 'First event');
        self.assertEquals(e.time_start, datetime(1970, 1, 1, 0, 0))
        self.assertEquals(e.time_end, datetime(1970, 1, 1, 3, 0))
        self.assertEquals(e.description, 'First description')
        self.assertEquals(e.source_type, EventSourceType.EMPTY)
        self.assertEquals(e.event_type.name, 'first')

        all_date_empty = session.query(Event).filter(Event.time_start == date(1971, 1, 1)).all() 
        self.assertEquals(len(all_date_empty), 0)
        all_date_fine = session.query(Event).filter(Event.time_start == date(1970, 1, 1)).all() 
        self.assertEquals(len(all_date_fine), 1)
        session.delete(e)
        session.commit()
Exemplo n.º 3
0
    def testThird(self):
        e = Event(self.et)
        e.title = 'First event'
        e.source_type = EventSourceType.EMPTY
        session.add(e)
        session.commit()

        e.event_status_list.append(EventStatus(EventStatus.EMPTY))
        e.event_status_list.append(EventStatus(EventStatus.LIVE_BE_HERE))
        self.assertEquals(e.last_status, EventStatus.LIVE_BE_HERE)

        session.delete(e)
        session.commit()
Exemplo n.º 4
0
    def testThird(self):
        e = Event(self.et)
        e.title = 'First event'
        e.source_type = EventSourceType.EMPTY 
        session.add(e)
        session.commit()

        e.event_status_list.append(EventStatus(EventStatus.EMPTY))
        e.event_status_list.append(EventStatus(EventStatus.LIVE_BE_HERE))
        self.assertEquals(e.last_status, EventStatus.LIVE_BE_HERE)

        session.delete(e) 
        session.commit()
Exemplo n.º 5
0
    def testDefThumb(self):
        it = ImageType(ImageType.TARGET_NONE)
        it.max_thumb_height = 345
        it.max_thumb_width = 234
        session.add(it)
        session.commit()
        ret = it.mkDefThumb()
        self.assertEquals(ret, True)
        self.assert_(it.def_thumb_path)
        fp = FileProcess()
        self.assertNotEquals(it.def_thumb_path[0], '/')
        info = ImageInfo(fp.fullPath(it.def_thumb_path))
        self.assertEquals(info.is_image(), True)
        self.assertEquals(info.height, 345)
        self.assertEquals(info.width, 234)

        session.delete(it)
        session.commit()
Exemplo n.º 6
0
    def testDefThumb(self):
        it = ImageType(ImageType.TARGET_NONE)
        it.max_thumb_height = 345
        it.max_thumb_width = 234
        session.add(it)
        session.commit()
        ret = it.mkDefThumb()
        self.assertEquals(ret, True)
        self.assert_(it.def_thumb_path)
        fp = FileProcess()
        self.assertNotEquals(it.def_thumb_path[0], '/')
        info = ImageInfo(fp.fullPath(it.def_thumb_path))
        self.assertEquals(info.is_image(), True)
        self.assertEquals(info.height, 345)
        self.assertEquals(info.width, 234)

        session.delete(it)
        session.commit()
Exemplo n.º 7
0
    def testAddImageToDb(self):
        it = ImageType(ImageType.TARGET_NONE)
        it.max_thumb_height = 50
        it.max_thumb_width = 150
        it.base_dir = 'b/a'
        it.transform_type = ImageTransform.STD
        session.add(it)
        img = Image(it)
        ret = img.uploadFromFile(fileInTestDir('img/test.jpg'))
        self.assert_(ret)
        session.add(img)
        session.commit()
        old_thumb_path = img.thumb_path
        old_image_path = img.image_path
        self.assert_(os.path.isfile(FileProcess.fullPath(img.thumb_path)))
        self.assert_(os.path.isfile(FileProcess.fullPath(img.image_path)))
        split_p = img.thumb_path.split(os.path.sep)
        self.assert_('b' in split_p)
        self.assert_('a' in split_p)
        self.assert_('img' in split_p)
        split_p = img.image_path.split(os.path.sep)
        self.assert_('b' in split_p)
        self.assert_('a' in split_p)
        self.assert_('img' in split_p)
        self.assert_(img.thumb_width <= 150)
        self.assert_(img.thumb_height <= 50)
        self.assertEquals(img.content_type, ImageInfo.JPEG)
        self.assertEquals(img.image_width, 418)
        self.assertEquals(img.image_height, 604)

        ret = img.uploadFromFile(fileInTestDir('img/test.jpg'))
        self.assert_(ret)
        self.assert_(not os.path.isfile(FileProcess.fullPath(old_thumb_path)))
        self.assert_(not os.path.isfile(FileProcess.fullPath(old_image_path)))

        session.delete(img)
        session.delete(it)
        session.commit()
Exemplo n.º 8
0
    def testAddImageToDb(self):
        it = ImageType(ImageType.TARGET_NONE)
        it.max_thumb_height = 50
        it.max_thumb_width = 150
        it.base_dir = 'b/a'
        it.transform_type = ImageTransform.STD
        session.add(it)
        img = Image(it)
        ret = img.uploadFromFile(fileInTestDir('img/test.jpg'))
        self.assert_(ret)
        session.add(img)
        session.commit()
        old_thumb_path = img.thumb_path
        old_image_path = img.image_path
        self.assert_(os.path.isfile(FileProcess.fullPath(img.thumb_path)))
        self.assert_(os.path.isfile(FileProcess.fullPath(img.image_path)))
        split_p = img.thumb_path.split(os.path.sep)
        self.assert_('b' in split_p)
        self.assert_('a' in split_p)
        self.assert_('img' in split_p)
        split_p = img.image_path.split(os.path.sep)
        self.assert_('b' in split_p)
        self.assert_('a' in split_p)
        self.assert_('img' in split_p)
        self.assert_(img.thumb_width <= 150)
        self.assert_(img.thumb_height <= 50) 
        self.assertEquals(img.content_type, ImageInfo.JPEG)
        self.assertEquals(img.image_width, 418)
        self.assertEquals(img.image_height, 604) 

        ret = img.uploadFromFile(fileInTestDir('img/test.jpg'))
        self.assert_(ret)
        self.assert_(not os.path.isfile(FileProcess.fullPath(old_thumb_path)))
        self.assert_(not os.path.isfile(FileProcess.fullPath(old_image_path)))

        session.delete(img)
        session.delete(it)
        session.commit()
Exemplo n.º 9
0
	def do_POST(self):
		try:
			

			output = header
			
			ctype, pdict = cgi.parse_header(self.headers.getheader("content-type"))
			if ctype == 'multipart/form-data':
				fields = cgi.parse_multipart(self.rfile, pdict)

				restaurant = fields.get("new_rest")
				edit = fields.get("edit")

			if restaurant:
				self.send_response(301)
				self.end_headers()
				restaurant_new = Restaurant(name = restaurant[0])
				session.add(restaurant_new)
				session.commit()

				text = """
						<h2>New Restaurant was created!</h2>
						<p>Restaurant <strong>%s</strong> is added to restaurants</p>
						<a href = "/restaurants/new"><p>Back</p></a>
						<a href = "/restaurants"><p>To All restaurants</p></a>
 					""" % restaurant[0]

 				output += text
 				output += footer
				self.wfile.write(output)

 			elif edit:
 				self.send_response(301)
				self.end_headers()
 				rest_id = int(self.path.split("/")[-2])
 				new_name = edit[0]
 				old_rest = session.query(Restaurant).filter(Restaurant.id == rest_id)
 				old_name = old_rest[0].name
 				old_rest[0].name = new_name
 				session.add(old_rest[0])
 				session.commit()

 				text = """
 					<h2>You have changed the name of %s to %s.</h2>
 					<h3>Congrats!</h3>
					<a href = "/restaurants"><p>To All restaurants</p></a>
 				""" % (old_name, new_name)
 				output += text
 				output += footer
				self.wfile.write(output)

 			elif "delete" in fields.keys()[0]:
				del_command = fields.keys()[0]
				print "del del_command: ", del_command
				del_id = int(del_command.split("_")[1])
				delete_restaurant = session.query(Restaurant).filter(Restaurant.id == del_id).one()
				session.delete(delete_restaurant)
				session.commit()
				self.send_response(301)
				self.send_header('Content-type', 'text/html')
				self.send_header('Location', '/restaurants')
				self.end_headers()

		
		except Exception, e:
			print "ERROR! ", e
			pass
Exemplo n.º 10
0
    def do_POST(self):
        try:

            output = header

            ctype, pdict = cgi.parse_header(
                self.headers.getheader("content-type"))
            if ctype == 'multipart/form-data':
                fields = cgi.parse_multipart(self.rfile, pdict)

                restaurant = fields.get("new_rest")
                edit = fields.get("edit")

            if restaurant:
                self.send_response(301)
                self.end_headers()
                restaurant_new = Restaurant(name=restaurant[0])
                session.add(restaurant_new)
                session.commit()

                text = """
						<h2>New Restaurant was created!</h2>
						<p>Restaurant <strong>%s</strong> is added to restaurants</p>
						<a href = "/restaurants/new"><p>Back</p></a>
						<a href = "/restaurants"><p>To All restaurants</p></a>
 					""" % restaurant[0]

                output += text
                output += footer
                self.wfile.write(output)

            elif edit:
                self.send_response(301)
                self.end_headers()
                rest_id = int(self.path.split("/")[-2])
                new_name = edit[0]
                old_rest = session.query(Restaurant).filter(
                    Restaurant.id == rest_id)
                old_name = old_rest[0].name
                old_rest[0].name = new_name
                session.add(old_rest[0])
                session.commit()

                text = """
 					<h2>You have changed the name of %s to %s.</h2>
 					<h3>Congrats!</h3>
					<a href = "/restaurants"><p>To All restaurants</p></a>
 				""" % (old_name, new_name)
                output += text
                output += footer
                self.wfile.write(output)

            elif "delete" in fields.keys()[0]:
                del_command = fields.keys()[0]
                print "del del_command: ", del_command
                del_id = int(del_command.split("_")[1])
                delete_restaurant = session.query(Restaurant).filter(
                    Restaurant.id == del_id).one()
                session.delete(delete_restaurant)
                session.commit()
                self.send_response(301)
                self.send_header('Content-type', 'text/html')
                self.send_header('Location', '/restaurants')
                self.end_headers()

        except Exception, e:
            print "ERROR! ", e
            pass
Exemplo n.º 11
0
 def tearDown(self):
     session.delete(self.et)
     session.commit()
Exemplo n.º 12
0
 def tearDown(self):
     session.delete(self.et)
     session.commit()