Пример #1
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()
Пример #2
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()
Пример #3
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()
Пример #4
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()
Пример #5
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()
Пример #6
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()
Пример #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()
Пример #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()
Пример #9
0
    def testSecond(self):
        session.query(Event).delete()
        session.query(Person).delete()
        session.query(Place).delete()
        session.commit()

        place = Place('First place')
        place.address = 'Address'
        place.phone = 'Phone'
        place.site_url = 'http://localhost'
        persons_list = []
        persons_list.append(Person('First', Person.MUSICIAN))
        persons_list.append(Person('Second', Person.MUSICIAN))
        e = Event(self.et)
        e.place = place
        for p in persons_list:
            e.persons.append(p)
        session.add(e)
        session.commit()
        session.flush()

        first_query = self.first_query
        all_first = first_query.all()
        self.assertEquals(len(all_first), 1)
        e = all_first[0]
        place = e.place
        self.assertEquals(place.address, 'Address')
        self.assertEquals(place.phone, 'Phone')
        self.assertEquals(place.site_url, 'http://localhost')
        person_names = []
        for p in e.persons:
            person_names.append(p.name)
        self.assert_('First' in person_names)
        self.assert_('Second' in person_names)

        e = Event(EventType.findByName(session, 'live'), 'Live event')
        e.addEventStatus(EventStatus(EventStatus.LIVE_WANT))
        e.addEventStatus(EventStatus(EventStatus.LIVE_BE_HERE))
        session.add(e)
        session.commit()
        session.flush()

        events = self.live_query.all()
        self.assertEquals(len(events), 1)
        e = events[0]
        self.assertEquals(len(e.event_status_list), 2)
        self.assertEquals(e.last_status, EventStatus.LIVE_BE_HERE)
Пример #10
0
    def testSecond(self):
        session.query(Event).delete()
        session.query(Person).delete()
        session.query(Place).delete()
        session.commit()

        place = Place('First place')
        place.address = 'Address'
        place.phone = 'Phone'
        place.site_url = 'http://localhost';
        persons_list = [] 
        persons_list.append(Person('First', Person.MUSICIAN))
        persons_list.append(Person('Second', Person.MUSICIAN))
        e = Event(self.et)
        e.place = place
        for p in persons_list:
            e.persons.append(p)
        session.add(e)
        session.commit()
        session.flush()

        first_query = self.first_query
        all_first = first_query.all()
        self.assertEquals(len(all_first), 1)
        e = all_first[0]
        place = e.place
        self.assertEquals(place.address, 'Address')
        self.assertEquals(place.phone, 'Phone')
        self.assertEquals(place.site_url, 'http://localhost')
        person_names = []
        for p in e.persons:
            person_names.append(p.name)
        self.assert_('First' in person_names)
        self.assert_('Second' in person_names)
       
        e = Event(EventType.findByName(session, 'live'), 'Live event')
        e.addEventStatus(EventStatus(EventStatus.LIVE_WANT))
        e.addEventStatus(EventStatus(EventStatus.LIVE_BE_HERE))
        session.add(e)
        session.commit()
        session.flush()

        events = self.live_query.all()
        self.assertEquals(len(events), 1);
        e = events[0]
        self.assertEquals(len(e.event_status_list), 2)
        self.assertEquals(e.last_status, EventStatus.LIVE_BE_HERE)
Пример #11
0
from datetime import datetime

engine.echo = True;

metadata.drop_all(engine)
metadata.create_all(engine, checkfirst=False)

session.query(EventType).delete()
session.add(EventType('live', u'Концерт'))

it = ImageType(Entity.EVENT, u'Афиша события');
it.max_thumb_width = 126;
it.max_thumb_height = 126;
it.transform_type = ImageTransform.STD;
it.base_dir = 'event';
session.add(it)

for e in session.query(EventType):
    print e

event_type = e
e = Event(event_type, 'First')
e.time_start = datetime.now()
session.add(e)

session.commit()

print e.event_id
print e.main_image
print e.time_start
Пример #12
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
Пример #13
0
 def setUp(self):
     session.query(EventType).filter(EventType.name == 'first')
     session.commit()
     self.et = EventType('first', 'First')
     session.add(self.et)
     session.commit()
Пример #14
0
 def setUp(self):
     session.query(EventType).filter(EventType.name == 'first')
     session.commit()
     self.et = EventType('first', 'First')
     session.add(self.et)
     session.commit()
Пример #15
0
 def tearDown(self):
     session.delete(self.et)
     session.commit()
Пример #16
0
from datetime import datetime

engine.echo = True

metadata.drop_all(engine)
metadata.create_all(engine, checkfirst=False)

session.query(EventType).delete()
session.add(EventType('live', u'Концерт'))

it = ImageType(Entity.EVENT, u'Афиша события')
it.max_thumb_width = 126
it.max_thumb_height = 126
it.transform_type = ImageTransform.STD
it.base_dir = 'event'
session.add(it)

for e in session.query(EventType):
    print e

event_type = e
e = Event(event_type, 'First')
e.time_start = datetime.now()
session.add(e)

session.commit()

print e.event_id
print e.main_image
print e.time_start
Пример #17
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
Пример #18
0
 def tearDown(self):
     session.delete(self.et)
     session.commit()