File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -87,6 +87,11 @@ def __repr__(self):
8787 else :
8888 return self .__str__ ()
8989
90+ def __eq__ (self , other : Any ) -> bool :
91+ if not isinstance (other , JsonObject ):
92+ return False
93+ return self .to_dict () == other .to_dict ()
94+
9095
9196class JsonValidator :
9297 def __init__ (self , message : str ):
Original file line number Diff line number Diff line change @@ -54,6 +54,11 @@ def test_parse(self):
5454 block .to_dict (),
5555 )
5656
57+ def test_eq (self ):
58+ self .assertEqual (Block (), Block ())
59+ self .assertEqual (Block (type = "test" ), Block (type = "test" ))
60+ self .assertNotEqual (Block (type = "test" ), Block (type = "another test" ))
61+
5762
5863# ----------------------------------------------
5964# Section
Original file line number Diff line number Diff line change 22
33from slack_sdk .errors import SlackObjectFormationError
44from slack_sdk .models .blocks import (
5+ BlockElement ,
56 ButtonElement ,
67 DatePickerElement ,
78 TimePickerElement ,
2930from . import STRING_3001_CHARS , STRING_301_CHARS
3031
3132
33+ class BlockElementTests (unittest .TestCase ):
34+ def test_eq (self ):
35+ self .assertEqual (BlockElement (), BlockElement ())
36+ self .assertEqual (BlockElement (type = "test" ), BlockElement (type = "test" ))
37+ self .assertNotEqual (
38+ BlockElement (type = "test" ), BlockElement (type = "another test" )
39+ )
40+
41+
3242# -------------------------------------------------
3343# Interactive Elements
3444# -------------------------------------------------
Original file line number Diff line number Diff line change @@ -148,6 +148,14 @@ def test_get_non_null_attributes_nested_2(self):
148148 )
149149 self .assertDictEqual (expected , nested .get_non_null_attributes ())
150150
151+ def test_eq (self ):
152+ obj1 = SimpleJsonObject ()
153+ self .assertEqual (self .good_test_object , obj1 )
154+
155+ obj2 = SimpleJsonObject ()
156+ obj2 .test = "another"
157+ self .assertNotEqual (self .good_test_object , obj2 )
158+
151159
152160class JsonValidatorTests (unittest .TestCase ):
153161 def setUp (self ) -> None :
Original file line number Diff line number Diff line change @@ -531,3 +531,15 @@ def test_load_home_tab_view_005(self):
531531 def test_load_home_tab_view_006 (self ):
532532 with open ("tests/slack_sdk_fixture/view_home_006.json" ) as file :
533533 self .verify_loaded_view_object (file )
534+
535+ def test_eq (self ):
536+ input = {
537+ "type" : "modal" ,
538+ "blocks" : [DividerBlock ()],
539+ }
540+ another_input = {
541+ "type" : "modal" ,
542+ "blocks" : [DividerBlock (), DividerBlock ()],
543+ }
544+ self .assertEqual (View (** input ), View (** input ))
545+ self .assertNotEqual (View (** input ), View (** another_input ))
You can’t perform that action at this time.
0 commit comments