Beispiel #1
0
 def test_nulls(self):
     selection = (_.dog[_.name('knows_sit').knows_command(
         command=Command.SIT)('knows_roll').knows_command(
             command=Command.ROLL_OVER).is_housetrained.owner[
                 _.name.hobbies[_.name(
                     'coolness').cool_factor]].best_friend[_.name].age(
                         on_date=MyDateTime(datetime.now())).birthday])
     loaded = quiz.load(
         DogQuery, selection, {
             'dog': {
                 'name': u'Rufus',
                 'knows_sit': True,
                 'knows_roll': False,
                 'is_housetrained': True,
                 'owner': None,
                 'best_friend': None,
                 'age': 3,
                 'birthday': 1540731645,
             }
         })
     assert isinstance(loaded, DogQuery)
     assert loaded == DogQuery(dog=Dog(
         name='Rufus',
         knows_sit=True,
         knows_roll=False,
         is_housetrained=True,
         owner=None,
         best_friend=None,
         age=3,
         birthday=MyDateTime(datetime.fromtimestamp(1540731645)),
     ))
Beispiel #2
0
 def test_nulls(self):
     selection = _.dog[
         _.name("knows_sit")
         .knows_command(command=Command.SIT)("knows_roll")
         .knows_command(command=Command.ROLL_OVER)
         .is_housetrained.owner[
             _.name.hobbies[_.name("coolness").cool_factor]
         ]
         .best_friend[_.name]
         .age(on_date=MyDateTime(datetime.now()))
         .birthday
     ]
     loaded = quiz.load(
         DogQuery,
         selection,
         {
             "dog": {
                 "name": "Rufus",
                 "knows_sit": True,
                 "knows_roll": False,
                 "is_housetrained": True,
                 "owner": None,
                 "best_friend": None,
                 "age": 3,
                 "birthday": 1540731645,
             }
         },
     )
     assert isinstance(loaded, DogQuery)
     assert loaded == DogQuery(
         dog=Dog(
             name="Rufus",
             knows_sit=True,
             knows_roll=False,
             is_housetrained=True,
             owner=None,
             best_friend=None,
             age=3,
             birthday=MyDateTime(datetime.fromtimestamp(1540731645)),
         )
     )
Beispiel #3
0
 def test_full(self):
     selection = (_.dog[_.name.color('knows_sit').knows_command(
         command=Command.SIT)('knows_roll').knows_command(
             command=Command.ROLL_OVER).is_housetrained.owner[
                 _.name.hobbies[_.name(
                     'coolness').cool_factor]].best_friend[_.name].age(
                         on_date=MyDateTime(datetime.now())).birthday])
     loaded = quiz.load(
         DogQuery, selection, {
             'dog': {
                 'name': u'Rufus',
                 'color': u'GOLDEN',
                 'knows_sit': True,
                 'knows_roll': False,
                 'is_housetrained': True,
                 'owner': {
                     'name':
                     u'Fred',
                     'hobbies': [{
                         'name': u'stamp collecting',
                         'coolness': 2,
                     }, {
                         'name': u'snowboarding',
                         'coolness': 8,
                     }]
                 },
                 'best_friend': {
                     'name': u'Sally',
                 },
                 'age': 3,
                 'birthday': 1540731645,
             }
         })
     # TODO: include union types
     assert isinstance(loaded, DogQuery)
     assert loaded == DogQuery(dog=Dog(
         name='Rufus',
         color=Color.GOLDEN,
         knows_sit=True,
         knows_roll=False,
         is_housetrained=True,
         owner=Human(name='Fred',
                     hobbies=[
                         Hobby(name='stamp collecting', coolness=2),
                         Hobby(name='snowboarding', coolness=8)
                     ]),
         best_friend=Sentient(name='Sally'),
         age=3,
         birthday=MyDateTime(datetime.fromtimestamp(1540731645)),
     ))
Beispiel #4
0
 def test_full(self):
     metadata = quiz.QueryMetadata(
         request=snug.GET("https://my.url/foo"), response=snug.Response(200)
     )
     selection = _.dog[
         _.name.color("knows_sit")
         .knows_command(command=Command.SIT)("knows_roll")
         .knows_command(command=Command.ROLL_OVER)
         .is_housetrained.owner[
             _.name.hobbies[_.name("coolness").cool_factor]
         ]
         .best_friend[_.name]
         .age(on_date=MyDateTime(datetime.now()))
         .birthday
     ]
     loaded = quiz.load(
         DogQuery,
         selection,
         quiz.RawResult(
             {
                 "dog": {
                     "name": "Rufus",
                     "color": "GOLDEN",
                     "knows_sit": True,
                     "knows_roll": False,
                     "is_housetrained": True,
                     "owner": {
                         "name": "Fred",
                         "hobbies": [
                             {"name": "stamp collecting", "coolness": 2},
                             {"name": "snowboarding", "coolness": 8},
                         ],
                     },
                     "best_friend": {"name": "Sally"},
                     "age": 3,
                     "birthday": 1540731645,
                 }
             },
             meta=metadata,
         ),
     )
     # TODO: include union types
     assert isinstance(loaded, DogQuery)
     assert loaded.__metadata__ == metadata
     assert loaded == DogQuery(
         dog=Dog(
             name="Rufus",
             color=Color.GOLDEN,
             knows_sit=True,
             knows_roll=False,
             is_housetrained=True,
             owner=Human(
                 name="Fred",
                 hobbies=[
                     Hobby(name="stamp collecting", coolness=2),
                     Hobby(name="snowboarding", coolness=8),
                 ],
             ),
             best_friend=Sentient(name="Sally"),
             age=3,
             birthday=MyDateTime(datetime.fromtimestamp(1540731645)),
         )
     )