11package org .openapitools .codegen .python ;
22
3+ import static org .assertj .core .api .Assertions .assertThat ;
4+ import static org .openapitools .codegen .languages .AbstractPythonConnexionServerCodegen .MOVE_TESTS_UNDER_PYTHON_SRC_ROOT ;
35import static org .openapitools .codegen .languages .AbstractPythonConnexionServerCodegen .PYTHON_SRC_ROOT ;
46import static org .openapitools .codegen .languages .AbstractPythonConnexionServerCodegen .USE_PYTHON_SRC_ROOT_IN_IMPORTS ;
57
911import java .util .Objects ;
1012
1113import com .google .common .collect .ImmutableMap ;
12- import org .apache .commons .lang3 .ObjectUtils ;
1314import org .apache .commons .lang3 .StringUtils ;
1415import org .openapitools .codegen .CodegenConstants ;
1516import org .openapitools .codegen .languages .AbstractPythonConnexionServerCodegen ;
16- import org .testng .Assert ;
1717import org .testng .annotations .DataProvider ;
1818import org .testng .annotations .Test ;
1919
@@ -29,11 +29,12 @@ public void test(String description, Map<String, Object> additionalProperties, S
2929 codegen .additionalProperties ().putAll (additionalProperties );
3030 codegen .processOpts ();
3131 String pythonSrcRoot = Objects .toString (codegen .additionalProperties ().get (PYTHON_SRC_ROOT ), null );
32- Assert .assertEquals (pythonSrcRoot , expectedValues .pythonSrcRoot );
33- Assert .assertEquals (codegen .apiPackage (), expectedValues .expectedApiPackage );
34- Assert .assertEquals (codegen .modelFileFolder (), expectedValues .expectedModelFileFolder );
35- Assert .assertEquals (codegen .apiFileFolder (), expectedValues .expectedApiFileFolder );
36- Assert .assertEquals (codegen .toModelImport (modelName ), expectedValues .expectedImport );
32+ assertThat (pythonSrcRoot ).isEqualTo (expectedValues .pythonSrcRoot );
33+ assertThat (codegen .apiPackage ()).isEqualTo (expectedValues .expectedApiPackage );
34+ assertThat (codegen .modelFileFolder ()).isEqualTo (expectedValues .expectedModelFileFolder );
35+ assertThat (codegen .apiFileFolder ()).isEqualTo (expectedValues .expectedApiFileFolder );
36+ assertThat (codegen .apiTestFileFolder ()).isEqualTo (expectedValues .expectedApiTestFileFolder );
37+ assertThat (codegen .toModelImport (modelName )).isEqualTo (expectedValues .expectedImport );
3738 }
3839
3940 @ DataProvider
@@ -47,6 +48,7 @@ public Object[][] data() {
4748 "openapi_server.controllers" ,
4849 platformAgnosticPath ("generated-code" , "connexion" , "openapi_server" , "models" ),
4950 platformAgnosticPath ("generated-code" , "connexion" , "openapi_server" , "controllers" ),
51+ platformAgnosticPath ("generated-code" , "connexion" , "test" ),
5052 null )
5153 },
5254 new Object []{
@@ -57,6 +59,7 @@ public Object[][] data() {
5759 "openapi_server.controllers" ,
5860 platformAgnosticPath ("generated-code" , "connexion" , "test_root" , "openapi_server" , "models" ),
5961 platformAgnosticPath ("generated-code" , "connexion" , "test_root" , "openapi_server" , "controllers" ),
62+ platformAgnosticPath ("generated-code" , "connexion" , "test" ),
6063 "test_root" )
6164 },
6265 new Object []{
@@ -67,6 +70,19 @@ public Object[][] data() {
6770 "test_root.openapi_server.controllers" ,
6871 platformAgnosticPath ("generated-code" , "connexion" , "test_root" , "openapi_server" , "models" ),
6972 platformAgnosticPath ("generated-code" , "connexion" , "test_root" , "openapi_server" , "controllers" ),
73+ platformAgnosticPath ("generated-code" , "connexion" , "test" ),
74+ null )
75+ },
76+ new Object []{
77+ "Python src in import and tests under python src root" ,
78+ ImmutableMap .of (PYTHON_SRC_ROOT , "test_root" , USE_PYTHON_SRC_ROOT_IN_IMPORTS , "true" ,
79+ MOVE_TESTS_UNDER_PYTHON_SRC_ROOT , "true" ),
80+ "TestModel" ,
81+ new ExpectedValues ("from test_root.openapi_server.models.test_model import TestModel" ,
82+ "test_root.openapi_server.controllers" ,
83+ platformAgnosticPath ("generated-code" , "connexion" , "test_root" , "openapi_server" , "models" ),
84+ platformAgnosticPath ("generated-code" , "connexion" , "test_root" , "openapi_server" , "controllers" ),
85+ platformAgnosticPath ("generated-code" , "connexion" , "test_root" , "test" ),
7086 null )
7187 },
7288 new Object []{
@@ -79,15 +95,26 @@ public Object[][] data() {
7995 "test_root.test_package.controllers" ,
8096 platformAgnosticPath ("generated-code" , "connexion" , "test_root" , "test_package" , "models" ),
8197 platformAgnosticPath ("generated-code" , "connexion" , "test_root" , "test_package" , "controllers" ),
98+ platformAgnosticPath ("generated-code" , "connexion" , "test" ),
99+ null )
100+ },
101+ new Object []{
102+ "Python src in import with specified package and tests under python src root" ,
103+ ImmutableMap .of (PYTHON_SRC_ROOT , "test_root" ,
104+ USE_PYTHON_SRC_ROOT_IN_IMPORTS , "true" ,
105+ CodegenConstants .PACKAGE_NAME , "test_package" ,
106+ MOVE_TESTS_UNDER_PYTHON_SRC_ROOT , "true" ),
107+ "TestModel" ,
108+ new ExpectedValues ("from test_root.test_package.models.test_model import TestModel" ,
109+ "test_root.test_package.controllers" ,
110+ platformAgnosticPath ("generated-code" , "connexion" , "test_root" , "test_package" , "models" ),
111+ platformAgnosticPath ("generated-code" , "connexion" , "test_root" , "test_package" , "controllers" ),
112+ platformAgnosticPath ("generated-code" , "connexion" , "test_root" , "test" ),
82113 null )
83114 }
84115 };
85116 }
86117
87- private static String platformAgnosticPath (String ... nodes ) {
88- return StringUtils .join (nodes , File .separatorChar );
89- }
90-
91118 private static class MockAbstractPythonConnexionServerCodegen extends AbstractPythonConnexionServerCodegen {
92119 public MockAbstractPythonConnexionServerCodegen (String templateDirectory , boolean fixBodyNameValue ) {
93120 super (templateDirectory , fixBodyNameValue );
@@ -99,16 +126,22 @@ private static class ExpectedValues {
99126 public final String expectedApiPackage ;
100127 public final String expectedModelFileFolder ;
101128 public final String expectedApiFileFolder ;
129+ public final String expectedApiTestFileFolder ;
102130 public final String pythonSrcRoot ;
103131
104132 public ExpectedValues (String expectedImport , String expectedApiPackage , String expectedModelFileFolder ,
105- String expectedApiFileFolder , String pythonSrcRoot ) {
133+ String expectedApiFileFolder , String expectedApiTestFileFolder , String pythonSrcRoot ) {
106134 this .expectedImport = expectedImport ;
107135 this .expectedApiPackage = expectedApiPackage ;
108136 this .expectedModelFileFolder = expectedModelFileFolder ;
109137 this .expectedApiFileFolder = expectedApiFileFolder ;
138+ this .expectedApiTestFileFolder = expectedApiTestFileFolder ;
110139 this .pythonSrcRoot = pythonSrcRoot != null ? pythonSrcRoot + File .separatorChar : null ;
111140 }
112141 }
113142
143+ private static String platformAgnosticPath (String ... nodes ) {
144+ return StringUtils .join (nodes , File .separatorChar );
145+ }
146+
114147}
0 commit comments