Пример #1
0
 def test_frame_as_json(self):
     frame = Frame.build('hello', data={'name': 'world'})
     frame_as_json = frame.as_json()
     frame_as_dict = json.loads(frame_as_json)
     assert isinstance(frame_as_dict['id'], str)
     assert frame_as_dict['name'] == 'hello'
     assert frame_as_dict['data'] == {'name': 'world'}
Пример #2
0
    def test_frame_meta_properties(self):
        frame1 = Frame()
        assert frame1.space is None
        assert frame1.source is None
        assert frame1.target is None
        assert frame1.timestamp is not None
        frame1.space = 'sandbox'
        assert frame1.space == 'sandbox'

        frame2 = Frame.build('test',
                             data={
                                 'yet': 'another',
                                 'test': 'eh'
                             },
                             meta={
                                 'space': 'zentropia',
                                 'source': 'stranger',
                                 'target': 'me',
                                 'timestamp': 'Just a string, really'
                             })
        assert frame2.space == 'zentropia'
        assert frame2.source == 'stranger'
        assert frame2.target == 'me'
        assert frame2.timestamp == 'Just a string, really'
        frame2.space = 'home'
        assert frame2.space == 'home'
        frame2.target = 'unknown'
        assert frame2.target == 'unknown'

        frame3 = Frame()
        frame3.target = 'test'
        assert frame3.target == 'test'
Пример #3
0
 def test_build(self):
     frame = Frame.build('test',
                         data={'a': 'test'},
                         meta={'another': 'test'})
     assert frame.name == 'test'
     assert frame.data == {'a': 'test'}
     assert 'another' in frame.meta
     assert frame.kind == KINDS.UNSET
Пример #4
0
 def test_request(self):
     request = Request()
     assert request.kind == KINDS.REQUEST
     del request
     request = Request('a test', data={'another': 'test'})
     assert request.id
     assert request.name == 'a test'
     assert request.data == {'another': 'test'}
     assert isinstance(Frame.build(**request.as_dict()), Request)
Пример #5
0
 def test_state(self):
     state = State()
     assert state.kind == KINDS.STATE
     del state
     state = State('a test', data={'another': 'test'})
     assert state.id
     assert state.name == 'a test'
     assert state.data == {'another': 'test'}
     assert isinstance(Frame.build(**state.as_dict()), State)
Пример #6
0
 def test_message(self):
     message = Message()
     assert message.kind == KINDS.MESSAGE
     del message
     message = Message('a test', data={'another': 'test'})
     assert message.id
     assert message.name == 'a test'
     assert message.data == {'another': 'test', 'text': 'a test'}
     assert isinstance(Frame.build(**message.as_dict()), Message)
Пример #7
0
 def test_event(self):
     event = Event()
     assert event.kind == KINDS.EVENT
     del event
     event = Event('a test', data={'another': 'test'})
     assert event.id
     assert event.name == 'a test'
     assert event.data == {'another': 'test'}
     assert isinstance(Frame.build(**event.as_dict()), Event)
Пример #8
0
 def test_build_event(self):
     frame = Frame.build('test',
                         data={'a': 'test'},
                         meta={'another': 'test'},
                         kind=KINDS.EVENT)
     assert frame.name == 'test'
     assert frame.data == {'a': 'test'}
     assert 'another' in frame.meta
     assert frame.kind == KINDS.EVENT
     assert isinstance(frame, Event)
Пример #9
0
 def test_build_command(self):
     frame = Frame.build('test',
                         data={'a': 'test'},
                         meta={'another': 'test'},
                         kind=KINDS.COMMAND)
     assert frame.name == 'test'
     assert frame.data == {'a': 'test'}
     assert 'another' in frame.meta
     assert frame.kind == KINDS.COMMAND
     assert isinstance(frame, Command)
Пример #10
0
 def test_response(self):
     response = Response()
     assert response.kind == KINDS.RESPONSE
     del response
     response = Response('a test', data={'another': 'test'})
     assert response.reply_to is None
     response.reply_to = 'okaythen'
     assert response.id
     assert response.name == 'a test'
     assert response.data == {'another': 'test'}
     assert response.reply_to == 'okaythen'
     assert isinstance(Frame.build(**response.as_dict()), Response)