@@ -2887,6 +2887,92 @@ def test_display_name_non_string_raises(self):
28872887 with self .assertRaises (TypeError ):
28882888 self .od ._build_create_entity ("new_TestTable" , {}, display_name = 123 )
28892889
2890+ # --- HTTP request structure -------------------------------------------
2891+
2892+ def test_returns_post_request (self ):
2893+ """_build_create_entity returns a POST _RawRequest."""
2894+ req = self .od ._build_create_entity ("new_TestTable" , {})
2895+ self .assertEqual (req .method , "POST" )
2896+
2897+ def test_url_targets_entity_definitions (self ):
2898+ """_build_create_entity URL ends with /EntityDefinitions."""
2899+ req = self .od ._build_create_entity ("new_TestTable" , {})
2900+ self .assertTrue (req .url .endswith ("/EntityDefinitions" ))
2901+
2902+ def test_solution_appended_to_url (self ):
2903+ """_build_create_entity appends SolutionUniqueName to URL when solution is given."""
2904+ req = self .od ._build_create_entity ("new_TestTable" , {}, solution = "MySolution" )
2905+ self .assertIn ("SolutionUniqueName=MySolution" , req .url )
2906+
2907+ def test_no_solution_no_query_string (self ):
2908+ """_build_create_entity URL has no query string when solution is omitted."""
2909+ req = self .od ._build_create_entity ("new_TestTable" , {})
2910+ self .assertNotIn ("?" , req .url )
2911+
2912+ # --- Payload structure ------------------------------------------------
2913+
2914+ def test_schema_name_in_payload (self ):
2915+ """_build_create_entity sets SchemaName in the payload."""
2916+ body = self ._body ()
2917+ self .assertEqual (body ["SchemaName" ], "new_TestTable" )
2918+
2919+ def test_static_payload_fields (self ):
2920+ """_build_create_entity sets fixed metadata fields correctly."""
2921+ body = self ._body ()
2922+ self .assertEqual (body ["OwnershipType" ], "UserOwned" )
2923+ self .assertFalse (body ["HasActivities" ])
2924+ self .assertFalse (body ["IsActivity" ])
2925+ self .assertTrue (body ["HasNotes" ])
2926+
2927+ def test_description_uses_label (self ):
2928+ """_build_create_entity Description reflects the display label."""
2929+ body = self ._body (display_name = "My Table" )
2930+ label = body ["Description" ]["LocalizedLabels" ][0 ]["Label" ]
2931+ self .assertIn ("My Table" , label )
2932+
2933+ # --- Primary column derivation ----------------------------------------
2934+
2935+ def test_primary_column_derived_from_table_prefix (self ):
2936+ """Primary column SchemaName uses table prefix when no primary_column given."""
2937+ body = self ._body ()
2938+ attrs = body ["Attributes" ]
2939+ primary = next (a for a in attrs if a .get ("IsPrimaryName" ))
2940+ self .assertEqual (primary ["SchemaName" ], "new_Name" )
2941+
2942+ def test_primary_column_explicit (self ):
2943+ """_build_create_entity uses explicit primary_column when provided."""
2944+ req = self .od ._build_create_entity ("new_TestTable" , {}, primary_column = "new_CustomName" )
2945+ body = json .loads (req .body )
2946+ attrs = body ["Attributes" ]
2947+ primary = next (a for a in attrs if a .get ("IsPrimaryName" ))
2948+ self .assertEqual (primary ["SchemaName" ], "new_CustomName" )
2949+
2950+ def test_primary_column_derived_no_prefix (self ):
2951+ """Primary column defaults to 'new_Name' when table has no underscore."""
2952+ req = self .od ._build_create_entity ("TestTable" , {})
2953+ body = json .loads (req .body )
2954+ primary = next (a for a in body ["Attributes" ] if a .get ("IsPrimaryName" ))
2955+ self .assertEqual (primary ["SchemaName" ], "new_Name" )
2956+
2957+ # --- Column inclusion -------------------------------------------------
2958+
2959+ def test_columns_included_in_attributes (self ):
2960+ """_build_create_entity includes provided columns in Attributes."""
2961+ body = (
2962+ self ._body .__func__ (self , ** {})
2963+ if False
2964+ else json .loads (self .od ._build_create_entity ("new_TestTable" , {"new_Price" : "decimal" }).body )
2965+ )
2966+ schemas = [a ["SchemaName" ] for a in body ["Attributes" ]]
2967+ self .assertIn ("new_Price" , schemas )
2968+
2969+ def test_unsupported_column_type_raises (self ):
2970+ """_build_create_entity raises ValidationError for unsupported column type."""
2971+ from PowerPlatform .Dataverse .core .errors import ValidationError
2972+
2973+ with self .assertRaises (ValidationError ):
2974+ self .od ._build_create_entity ("new_TestTable" , {"new_Bad" : "unsupported_type" })
2975+
28902976
28912977if __name__ == "__main__" :
28922978 unittest .main ()
0 commit comments