def test_req_cond(self): g = fix.Group(OrderedDict({ 8: b'FIX v.lol', 350: None }), req_tags={8, 350}, req_cond=[(lambda self_: self_[350][1][351] == b'bb', '350, 1, 351 not bb')]) g.add_inner_group(fix.Group({350: b'1', 351: b'22'}, req_tags={351})) g.add_inner_group(fix.Group({350: b'aa', 351: b'bb'})) g.build() g[350, 1, 351] = b'bbb' assert_raises(ValueError, g.build)
def test_req_tags(self): g = fix.Group(OrderedDict({ 8: b'FIX v.lol', 350: None }), req_tags={8, 350}) g.add_inner_group(fix.Group({350: b'1', 351: b'22'}, req_tags={351})) g.add_inner_group(fix.Group({350: b'aa', 351: b'bb'})) g.build() del g[8] assert_raises(ValueError, g.build) g[8] = b'lol' g.build() del g[350, 0, 351] assert_raises(ValueError, g.build)
def test_group(self): g = fix.Group({8: 'oh', 9: 'ah'}) d = [(k, v) for k, v in g.items()] assert d[0][0] == 8 assert d[0][1] == 'oh' assert d[1][0] == 9 assert d[1][1] == 'ah'
def test_groupstructure(self): tlg = fix.GroupStructure({350: fix.Group([350, 351])}, validate_construct=False) assert not tlg.is_valid_construct() tlg = fix.GroupStructure({350: fix.GroupStructure([350, 351])}) assert tlg.is_valid_construct() tlg = fix.GroupStructure({350: 2}, validate_construct=False) assert not tlg.is_valid_construct() tlg = fix.GroupStructure( {350: fix.GroupStructure({ 350: None, 351: None })}) assert tlg.is_valid_construct() tlg = fix.GroupStructure( { 350: fix.GroupStructure({ 350: b'1', 351: None }, validate_construct=False), 341: 1 }, validate_construct=False) assert not tlg.is_valid_construct()
def test_deepcopy(self): g = fix.Group({8: b'8'}) g2 = copy.deepcopy(g) assert g2 == g assert g2 is not g g[8] = b'9' assert g2 != g
def setup(self): self.msg = fix.MessageWithHeader( fix.Group({ 35: b'D', 49: b'S', 56: b'T', 34: b'1', 999: b'tag 999 value' })) self.msg2 = fix.MessageWithHeader( fix.Group({ 35: b'D', 49: b'S', 56: b'T', 34: b'1', 50: b'lol', 999: b'tag 999 value' }))
def logout(self): self.log.info('logging out...') logout_msg = fix.LogoutMessage( fix.Group({ **self.header_fill, 34: str(self.seq(no_raise=True)).encode(), })) self.send_msg(bytes(logout_msg), log_level=logging.DEBUG)
def new_msg(self, msgtype_cls: type, extra: OrderedDict = None, seq=True, **kwargs): d = OrderedDict({**self.header_fill}) if seq: d[34] = str(self.seq()).encode() d.update(extra) return msgtype_cls(fix.Group(d), **kwargs)
def logon(self): self.log.info('logging on...') logon_msg = fix.LogonMessage( fix.Group({ **self.header_fill, 34: str(self.seq(no_raise=True)).encode(), 108: self.heartbeat })) self.send_msg(bytes(logon_msg), log_level=logging.DEBUG) self.logged_on = True
def setup(self): self.msg = fix.NewOrderMessage( fix.Group({ 38: b'100', 40: b'2', 44: b'1', 54: b'0', 55: b'fja', 49: b'S', 56: b'T', 34: b'1' }))
def test_add_inner_groups(self): g = fix.Group(OrderedDict({8: b'FIX v.lol', 350: None})) g.add_inner_group(fix.Group({350: b'1', 351: b'22'})) g.add_inner_group(fix.Group({350: b'aa', 351: b'bb'})) assert g.build() == \ b'8=FIX v.lol\x01350=1\x01351=22\x01350=aa\x01351=bb\x01'
def test_id_tag(self): g = fix.Group({8: b'8'}) assert g.id_tag == 8
def test_build2(self): fix.Group().build()
def test_build(self): g_build = fix.Group({8: b'8'}).build() assert g_build == b'8=8\x01'
def test_check_valid_semantics(self): g = fix.Group({8: b'8'}) assert g.is_valid_semantics() g = fix.Group({8: 8}) assert not g.is_valid_semantics() g = fix.Group({8: '8'}) assert not g.is_valid_semantics() g = fix.Group({8: fix.Group({1: b'a'})}) assert not g.is_valid_semantics() g = fix.Group({8: [fix.Group({8: b'A'})]}) assert g.is_valid_semantics() g = fix.Group({8: [fix.Group({8: b'A', 9: fix.Group({10: b'1'})})]}) assert not g.is_valid_semantics() g = fix.Group({8: [fix.Group({7: b'A'})]}) assert not g.is_valid_semantics()