Esempio n. 1
0
class GenericsTest(TestCase):

    def setUp(self):

        self.mew = Cat(name="mew")
        self.mew.save()

        self.snoopy = Dog(name="snoopy")
        self.snoopy.save()

        cat_house = AnimalHouse(animal=self.mew)
        cat_house.save()

        dog_house = AnimalHouse(animal=self.snoopy)
        dog_house.save()

    def test_polymorphic_calls(self):

        houses = AnimalHouse.objects.all()

        self.assertEquals(houses[0].animal.make_sound(), "meow!")
        self.assertEquals(houses[1].animal.make_sound(), "guau!")

    def test_generic_filter(self):        

        cat_houses = AnimalHouse.objects.filter(content_type=ContentType.objects.get_for_model(Cat))
        self.assertEquals([house.animal for house in cat_houses], [self.mew])

        dog_houses = AnimalHouse.objects.filter(content_type=ContentType.objects.get_for_model(Dog))
        self.assertEquals([house.animal for house in dog_houses], [self.snoopy])
        
Esempio n. 2
0
 def cat_finder(self):
     copy = self.waiting_for_cat.copy()
     for user, chance in zip(copy.keys(), copy.values()):
         power = chance.check()
         if power:
             cat = Cat(power=power)
             user.add_cat(cat)
             user.is_mining = False
             user.send(Message('new_cat', cat.dump()))
             self.waiting_for_cat.pop(user)
             log.debug('User %s find new cat %s' % (user, cat))
Esempio n. 3
0
def generate_cat(space):
    cat = Body(mass=1, moment=1)
    cat_shape = Cat(cat, 15)
    cat_shape.elasticity = 1
    cat.position = (50, 120)
    cat_shape.collision_type = 1

    # Setup the collision callback function Cat and Pickle under boost
    g = space.add_collision_handler(1, 6)
    g.begin = same_elem_collision

    space.add(cat, cat_shape)
Esempio n. 4
0
def create_cat():
    json = request.get_json()
    name = json['name']
    coolness = json['coolness']

    if not name or not coolness:
        abort(400)

    cat = Cat(name=name, coolness=coolness)
    db.session.add(cat)
    db.session.commit()

    return jsonify({"cat": cat.to_dict()})
Esempio n. 5
0
def add_categ():

    form = form_add_categ()
    items_py = []
    for items_iter in Items.query.all():
        items_py.append(
            (str(items_iter.id), str(items_iter.Naming),
             str(items_iter.Description), str(items_iter.Cat.name)))
    categs = []
    for categs_iter in Cat.query.all():
        categs.append((str(categs_iter.id), str(categs_iter.name)))
    if form.validate_on_submit():
        new_categ = str(form.categ_name.data)
        c1 = Cat(new_categ)
        db.session.add(c1)
        db.session.commit()
        # print ('New Category Added = {}').format(new_categ)
        message = 'Category addedddd:' + c1.name
        # Flash displays a message only on first subsequent request.
        flash(message)
        return render_template('categ_added.html',
                               title='Categ_added',
                               Items=items_py,
                               categs=categs)
        # return  render_template('index.html',user=new_categ)
    return render_template('add_categ.html',
                           title='Add Categories',
                           form=form,
                           Items=items_py,
                           categs=categs)
Esempio n. 6
0
    def test_cat_cat_toy_relationship(self):
        # establish a cat
        gwen = Cat(name='Gwen', age=19, coloring='tuxedo', gender='female')
        self.session.add(gwen)
        self.session.flush()

        # establish some toys she can play with
        available_toys = [
            'owl plush', 'feather boa', 'crinkle tunnel', 'squeaky mouse'
        ]

        for toy in available_toys:
            toy = CatToy(name=toy)
            self.session.add(toy)
        self.session.flush()

        # establish which ones she likes to play with best
        gwens_fav_toys = ['owl plush', 'feather boa']

        for toy_name in gwens_fav_toys:
            fav_toy = self.session.query(CatToy).filter(
                CatToy.name == toy_name).one()
            fav_toy_association = CatHasFavoriteToy(cat_id=gwen.id,
                                                    cat_toy_id=fav_toy.id)
            self.session.add(fav_toy_association)
        self.session.flush()
        # the CatToy objects related to the CatHasFavoriteToys
        # we just made for Gwen should now live in
        # gwen.toys
        # is there the correct amount?
        self.assertEqual(len(gwens_fav_toys), len(gwen.toys))

        # are they the correct ones?
        for cat_toy in gwen.toys:
            self.assertTrue(cat_toy.name in gwens_fav_toys)
Esempio n. 7
0
    def test_add_cat_favorite_toy(self):
        gwen = Cat(name='Gwen', age=19, coloring='tuxedo', gender='female')
        self.session.add(gwen)

        crinkle_tunnel = CatToy(name='crinkle tunnel')
        self.session.add(crinkle_tunnel)

        fav_toy = CatHasFavoriteToy(cat_id=gwen.id,
                                    cat_toy_id=crinkle_tunnel.id)
        self.session.add(fav_toy)
Esempio n. 8
0
 def on_post(self, req, resp):
     name = req.media.get('name')
     if not name:
         raise falcon.HTTPBadRequest(
             'Missing name', 'A name is required in the request body')
     cat = Cat(name=name)
     self.session.add(cat)
     self.session.commit()
     resp.media = cat
     resp.status = falcon.HTTP_OK
Esempio n. 9
0
	def post(self):
		args = parser.parse_args()
		if not args['name'] or not args['max']:
			return json.dumps("Not enough arguments"), 400
		cat = Cat.query.filter_by(name = args['name']).first()
		#Category titles must not match each other
		if not cat:
			db.session.add(Cat(args['name'], float(args['max'])))
			db.session.commit()
			return json.dumps("Category posted successfully"), 201
		else:
			return json.dumps("Category already exists"), 409
Esempio n. 10
0
def add_books_to_db(fin=books_json):
    from PyQt4 import QtCore
    from models import Book, Cat
    with open(fin, 'r') as books_file:
        data = books_file.read()
        data = json.loads(data)
    cats = data.keys()
    for c in cats:
        cat = Cat(name=c)
        cat.put()
        cat = Cat.get(name=c)[0]
        cat_id = cat.id
        for book in data[c]:
            title = book[0]
            cat_order = book[1]
            if cat_order.isdigit():
                b = Book.add(title=title, cat_id=cat_id,
                             cat_order=int(cat_order), copies=1,
                             available=True)
                if type(b) in [str, QtCore.QString]:
                    print b, title, cat_order
Esempio n. 11
0
    def setUp(self):

        self.mew = Cat(name="mew")
        self.mew.save()

        self.snoopy = Dog(name="snoopy")
        self.snoopy.save()

        cat_house = AnimalHouse(animal=self.mew)
        cat_house.save()

        dog_house = AnimalHouse(animal=self.snoopy)
        dog_house.save()
Esempio n. 12
0
def add_books_to_db(fin=books_json):
    from PyQt4 import QtCore
    from models import Book, Cat
    with open(fin, 'r') as books_file:
        data = books_file.read()
        data = json.loads(data)
    cats = data.keys()
    for c in cats:
        cat = Cat(name=c)
        cat.put()
        cat = Cat.get(name=c)[0]
        cat_id = cat.id
        for book in data[c]:
            title = book[0]
            cat_order = book[1]
            if cat_order.isdigit():
                b = Book.add(title=title,
                             cat_id=cat_id,
                             cat_order=int(cat_order),
                             copies=1,
                             available=True)
                if type(b) in [str, QtCore.QString]:
                    print b, title, cat_order
Esempio n. 13
0
def create_cats():
    Cat('Vivien', 'Female', 7, 'blue', 'DSP a', 'flock', 'images/img_8888.jpg')
    Cat('Kiona', 'Female', 7, 'blue with white', 'DSP a 09', 'brush',
        'images/kiona.jpg')
    Cat('Galaxy', 'Female', 4, 'blue tortie', 'DSP g', 'naked',
        'images/img_9037.jpg')
    Cat('Bolero', 'Male', 3, 'blue', 'DSP a', 'naked', 'images/bolero.jpg')
    Cat('Tango', 'Male', 4, 'black', 'DSP n ', 'naked', 'images/tango.jpg')
    Cat('Caligula', 'Male', 1, 'black', 'DSP n', 'naked',
        'images/catTrack.jpg')
Esempio n. 14
0
 def post(self):
     parsed_args = cat_parser.parse_args()
     cat = Cat(**parsed_args)
     session.add(cat)
     session.commit()
     return cat
Esempio n. 15
0
from __init__ import Base
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from models import Cat, CatToy, CatHasFavoriteToy

engine = create_engine('sqlite:///:memory:')
Session = sessionmaker(bind=engine)
session = Session()
Base.metadata.drop_all(bind=engine)
Base.metadata.create_all(bind=engine)

gwen = Cat(name='Gwen', age=19, coloring='tuxedo', gender='female')
session.add(gwen)
session.flush()

available_toys = [
    'owl plush', 'feather boa', 'crinkle tunnel', 'squeaky mouse'
]
for toy in available_toys:
    toy = CatToy(name=toy)
    session.add(toy)
session.flush()

gwens_fav_toys = ['owl plush', 'feather boa']

for toy_name in gwens_fav_toys:
    fav_toy = session.query(CatToy).filter(CatToy.name == toy_name).one()
    fav_toy_association = CatHasFavoriteToy(cat_id=gwen.id,
                                            cat_toy_id=fav_toy.id)
    session.add(fav_toy_association)
Esempio n. 16
0
from models import Cat, Dog


class Animal:
    pass


if __name__ == "__main__":
    gai = Cat()
    print(gai)
Esempio n. 17
0
    def test_add_cat_function(self):
        # some basic things about cats - they have names, ages, gender,
        # and coloring:

        gwen = Cat(name='Gwen', age=19, coloring='tuxedo', gender='female')
        self.session.add(gwen)