コード例 #1
0
def test_get_one_api(mock_ps):
    app = create_app()
    mock_ps.return_value.retrieve_one.return_value = \
        Person(name='wrong', primary_email='ncwk')
    with app.test_client() as c:
        rv = c.get('/person/123')
        assert rv.status_code == 200
コード例 #2
0
    def get(self, document=None):
        if document is None:
            return make_custom_response(
                '{"message": "El parametro de búsqueda no se envio correctamente"}',
                400, 'Application/json')

        player = Person(document)
        player, player_exists = current_user.get_player_information(player)

        if player_exists:
            return player.__dict__
        else:
            return make_custom_response('{"message": "not found"}', 404,
                                        'application/json')
コード例 #3
0
    def post(self):
        try:
            data = json.loads(request.data)
            new_player = Person(document=data['document'],
                                names=data['names'],
                                lastnames=data['lastnames'],
                                phone=data['phone'],
                                address=data['address'],
                                email=data['email'])
            if current_user.register_new_player(new_player, data['password']):
                return make_custom_response('{"message": "ok"', 200,
                                            'application/json}')

        except (json.decoder.JSONDecodeError, KeyError):
            return make_custom_response(
                '{"message": "Formato del cuerpo no valido"}', 400,
                'Application/json')
コード例 #4
0
 def setUp(self):
     self.person_controller = PersonController()
     self.client = MongoClient()
     self.database = self.client.catalogo_personas
     self.person = Person("Diana", 32, "*****@*****.**")
コード例 #5
0
    def _get_random_person(self):
        name = random_word(10)
        age = random_number(65)
        email = random_email()

        return Person(name=name, age=age, email=email)
コード例 #6
0
 def create(self, name, primary_email):
     new_person = Person(name=name, primary_email=primary_email)
     self.db.session.add(new_person)
     self.db.session.commit()
     return True
コード例 #7
0
from app.api.person import formatter
import pytest

from app.model.person import Person


@pytest.mark.parametrize('person_test', [
    [Person(name='nis', primary_email='x@y')],
    [
        Person(name='pqr', primary_email='p@q'),
        Person(name='ikh', primary_email='p@j')
    ],
])
def test_formatter(person_test):
    result = formatter(person_test)
    assert len(person_test) == len(result)
    assert person_test[0].primary_email == result[0]['primary email']
コード例 #8
0
 def test_email_should_not_be_mandatory(self):
     person = Person('Pepe')
     assert_equal("", person.email)
コード例 #9
0
 def test_should_have_name_of_the_person(self):
     expected_name = random_word(10)
     person = Person(expected_name)
     actual_name = person.name
     assert_equal(expected_name, actual_name)
コード例 #10
0
 def test_should_have_the_email_of_the_person(self):
     expected_email = '*****@*****.**'
     person = Person('Pepe', email=expected_email)
     actual_email = person.email
     assert_equal(expected_email, actual_email)
コード例 #11
0
 def test_age_should_be_zero_when_age_is_not_given(self):
     person = Person('Pepe')
     assert_equal(0, person.age)
コード例 #12
0
 def test_should_have_the_age_of_the_person(self):
     expected_age = 25
     person = Person('Pepe', expected_age)
     actual_age = person.age
     assert_equal(expected_age, actual_age)
コード例 #13
0
def upgrade(migrate_engine):
    Session = sessionmaker(bind=migrate_engine)
    session = Session()
    # Upgrade operations go here. Don't create your own engine; bind
    # migrate_engine to your metadata
    objects = [
        Shop(id=1, name='ラビットハウス'),
        Shop(id=2, name='フルール・ド・ラパン'),
        Shop(id=3, name='甘兎庵'),
    ]
    session.bulk_save_objects(objects)
    session.commit()

    objects = [
        Office(id=1, name='アイムエンタープライズ'),
        Office(id=2, name='アクセルワン'),
        Office(id=3, name='大沢事務所'),
        Office(id=4, name='青二プロダクション'),
        Office(id=5, name='響'),
        Office(id=6, name='東京俳優生活協同組合'),
        Office(id=7, name='Rush Style'),
    ]
    session.bulk_save_objects(objects)
    session.commit()

    objects = [
        Person(id=1, name='保登 心愛', nickname='ココア', age=15, height=154, birthday='04-10', blood_type='B', shop_id=1),
        Person(id=2, name='香風 智乃', nickname='チノ', age=13, height=144, birthday='12-04', blood_type='AB', shop_id=1),
        Person(id=3, name='天々座 理世', nickname='リゼ', age=16, height=160, birthday='02-14', blood_type='A', shop_id=1),
        Person(id=4, name='宇治松 千夜', nickname='千夜', age=15, height=157, birthday='09-19', blood_type='O', shop_id=3),
        Person(id=5, name='桐間 紗路', nickname='シャロ', age=15, height=151, birthday='07-15', blood_type='A', shop_id=2),
        Person(id=6, name='ティッピーゴールデンフラワリーオレンジペコ', nickname='ティッピー', age=None, height=None, birthday=None, blood_type=None, shop_id=1),
        Person(id=7, name='香風 タカヒロ', nickname='タカヒロ', age=None, height=None, birthday=None, blood_type=None, shop_id=1),
        Person(id=8, name='保登 モカ', nickname='モカ', age=None, height=None, birthday='03-13', blood_type=None, shop_id=None),
        Person(id=9, name='条河 麻耶', nickname='マヤ', age=13, height=140, birthday='08-08', blood_type='O', shop_id=None),
        Person(id=10, name='奈津 恵', nickname='メグ', age=13, height=145, birthday='11-02', blood_type='A', shop_id=None),
        Person(id=11, name='青山 翠', nickname='青山 ブルーマウンテン', age=None, height=163, birthday='10-27', blood_type='B', shop_id=None),
        Person(id=12, name='真手 凛', nickname='', age=None, height=None, birthday=None, blood_type=None, shop_id=None),
    ]
    session.bulk_save_objects(objects)
    session.commit()

    objects = [
        VoiceActor(id=1, name='佐倉 綾音', height=157, birthday='1994-01-29', office_id=1),
        VoiceActor(id=2, name='水瀬 いのり', height=154, birthday='1995-12-02', office_id=2),
        VoiceActor(id=3, name='種田 梨沙', height=153, birthday='1988-07-12', office_id=3),
        VoiceActor(id=4, name='佐藤 聡美', height=153, birthday='1986-05-08', office_id=4),
        VoiceActor(id=5, name='内田 真礼', height=155, birthday='1989-12-27', office_id=1),
        VoiceActor(id=6, name='清川 元夢', height=182, birthday='1935-04-09', office_id=6),
        VoiceActor(id=7, name='速水 奨', height=174, birthday='1958-08-02', office_id=7),
        VoiceActor(id=8, name='茅野 愛衣', height=153, birthday='1987-09-13', office_id=3),
        VoiceActor(id=9, name='徳井 青空', height=159, birthday='1989-12-26', office_id=5),
        VoiceActor(id=10, name='村川 梨衣', height=152, birthday='1990-06-01', office_id=6),
        VoiceActor(id=11, name='早見 沙織', height=164, birthday='1991-05-29', office_id=1),
        VoiceActor(id=12, name='木村 珠莉', height=150.5, birthday='1987-06-07', office_id=6),
    ]
    session.bulk_save_objects(objects)
    session.commit()

    objects = [
        CharacterVoice(voice_actor_id=1, person_id=1),
        CharacterVoice(voice_actor_id=2, person_id=2),
        CharacterVoice(voice_actor_id=3, person_id=3),
        CharacterVoice(voice_actor_id=4, person_id=4),
        CharacterVoice(voice_actor_id=5, person_id=5),
        CharacterVoice(voice_actor_id=6, person_id=6),
        CharacterVoice(voice_actor_id=7, person_id=7),
        CharacterVoice(voice_actor_id=8, person_id=8),
        CharacterVoice(voice_actor_id=9, person_id=9),
        CharacterVoice(voice_actor_id=10, person_id=10),
        CharacterVoice(voice_actor_id=11, person_id=11),
        CharacterVoice(voice_actor_id=12, person_id=12),
    ]
    session.bulk_save_objects(objects)
    session.commit()
コード例 #14
0
    def test_select(self):
        person = self.session.query(Person.name).filter(Person.id == 1).first()
        self.assertEqual(person.name, "保登 心愛")
        persons = self.session.query(Person).filter(Person.height < 150).all()
        self.assertEqual(len(persons), 3)
        persons = self.session.query(Person).filter(
            Person.name.like("%保登%")).all()
        self.assertEqual(len(persons), 2)
        persons = self.session.query(Person).filter(Person.id.in_([1,
                                                                   2])).all()
        self.assertEqual(persons[1].name, "香風 智乃")
        persons = self.session.query(Person).filter(
            ~Person.id.in_([1, 2])).all()
        self.assertEqual(persons[0].name, "天々座 理世")
        persons = self.session.query(Person).filter(
            and_(Person.age == 13, Person.blood_type == "A")).all()
        self.assertEqual(persons[0].nickname, "メグ")
        persons = self.session.query(
            func.avg(Person.height).label("avg_height")).first()
        self.assertTrue(isinstance(persons.avg_height, float))
        print(persons)
        persons = self.session.query(func.sum(
            Person.age).label("sum_age")).first()
        # self.assertTrue(isinstance(persons.sum_age, int))
        print(persons.sum_age)
        persons = self.session.query(
            func.count(Person.id).label("count_person")).first()
        print(persons.count_person)
        persons2 = self.session.query(Person.id).count()
        print(persons2)
        persons = self.session.query(Person).limit(5).offset(5).all()
        print(persons)
        self.assertEqual(persons[0].id, 6)
        persons = self.session.query(Person).order_by(Person.id.desc()).all()
        print(persons)
        self.assertEqual(persons[0].id, 12)
        persons = self.session.query(Person.age, func.count(
            Person.age)).group_by(Person.age).all()
        print(persons)
        persons = self.session.query(Person).select_from(join(Person,
                                                              Shop)).all()
        print(persons)
        persons = self.session.query(Person).select_from(
            join(Person, Shop, Person.shop_id == Shop.id)).all()
        print(persons)
        persons = self.session.query(Person).select_from(
            outerjoin(Person, Shop, Person.shop_id == Shop.id)).all()
        print(persons)

        persons = self.session.query(Person).filter(
            Person.created_at < current_timestamp()).all()
        print(persons)

        print(self.session.execute(select([current_user()])).first())
        persons = self.session.query(
            Person.id, Person.name,
            case([
                (Person.height >= 165, '165以上'),
            ], else_='165未満')).all()
        print(persons)

        person = Person(name="秋山優花里",
                        nickname="オッドボール三等軍曹",
                        age=16,
                        birthday="06-06",
                        blood_type="O")
        self.session.add(person)
        self.session.commit()
        self.assertEqual(person.age, 16)
        person.age = 17
        self.session.commit()
        self.assertEqual(person.age, 17)
        self.session.delete(person)
        self.session.commit()