@@ -40,6 +40,8 @@ public static void DoDeployment(TestContext context) {
40
40
41
41
[ TestInitialize ]
42
42
public void CloseRunningIisExpress ( ) {
43
+ PythonVersion . AssertInstalled ( ) ;
44
+
43
45
IEnumerable < Process > running ;
44
46
while ( ( running = Process . GetProcessesByName ( "iisexpress" ) ) . Any ( ) ) {
45
47
foreach ( var p in running ) {
@@ -64,30 +66,11 @@ public void CloseRunningIisExpress() {
64
66
}
65
67
}
66
68
67
- [ TestMethod , Priority ( 0 ) ]
68
- public void DjangoNewApp ( ) {
69
- using ( var site = ConfigureIISForDjango ( AppCmdPath , InterpreterPath , "DjangoApplication.settings" ) ) {
70
- site . StartServer ( ) ;
71
-
72
- CopyDir ( "TestData" , site . SiteDir ) ;
73
-
74
- var response = site . Request ( "" ) ;
75
- Console . WriteLine ( response . ContentType ) ;
76
- var stream = response . GetResponseStream ( ) ;
77
- var content = new StreamReader ( stream ) . ReadToEnd ( ) ;
78
- Console . WriteLine ( content ) ;
79
-
80
- Assert . IsTrue ( content . IndexOf ( "Welcome to Django" ) != - 1 , "Expected \" Welcome to Django\" .\r \n Actual:\r \n " + content ) ;
81
- }
82
- }
83
-
84
69
[ TestMethod , Priority ( 0 ) ]
85
70
public void DjangoHelloWorld ( ) {
86
71
using ( var site = ConfigureIISForDjango ( AppCmdPath , InterpreterPath , "DjangoTestApp.settings" ) ) {
87
72
site . StartServer ( ) ;
88
73
89
- CopyDir ( "TestData" , site . SiteDir ) ;
90
-
91
74
var response = site . Request ( "" ) ;
92
75
Console . WriteLine ( response . ContentType ) ;
93
76
var stream = response . GetResponseStream ( ) ;
@@ -121,12 +104,8 @@ public void ConfigVariables() {
121
104
[ TestMethod , Priority ( 0 ) ]
122
105
public void LargeResponse ( ) {
123
106
using ( var site = ConfigureIISForDjango ( AppCmdPath , InterpreterPath , "DjangoTestApp.settings" ) ) {
124
- File . Copy ( "TestData\\ DjangoTestApp\\ web.config" , Path . Combine ( site . SiteDir , "web.config" ) ) ;
125
-
126
107
site . StartServer ( ) ;
127
108
128
- CopyDir ( "TestData" , site . SiteDir ) ;
129
-
130
109
var response = site . Request ( "large_response" ) ;
131
110
Console . WriteLine ( response . ContentType ) ;
132
111
var stream = response . GetResponseStream ( ) ;
@@ -151,8 +130,6 @@ public void DjangoHelloWorldParallel() {
151
130
using ( var site = ConfigureIISForDjango ( AppCmdPath , InterpreterPath , "DjangoTestApp.settings" ) ) {
152
131
site . StartServer ( ) ;
153
132
154
- CopyDir ( "TestData" , site . SiteDir ) ;
155
-
156
133
const int threadCnt = 12 ;
157
134
const int requests = 1000 ;
158
135
var tasks = new Task [ threadCnt ] ;
@@ -180,8 +157,6 @@ public void DjangoHelloWorldParallel() {
180
157
[ TestMethod , Priority ( 0 ) ]
181
158
public void CustomHandler ( ) {
182
159
using ( var site = ConfigureIISForCustomHandler ( AppCmdPath , InterpreterPath , "custom_handler.handler" ) ) {
183
- CopyDir ( "TestData" , site . SiteDir ) ;
184
-
185
160
site . StartServer ( ) ;
186
161
187
162
var response = site . Request ( "" ) ;
@@ -196,8 +171,6 @@ public void CustomHandler() {
196
171
[ TestMethod , Priority ( 0 ) ]
197
172
public void CustomCallableHandler ( ) {
198
173
using ( var site = ConfigureIISForCustomHandler ( AppCmdPath , InterpreterPath , "custom_handler.callable_handler()" ) ) {
199
- CopyDir ( "TestData" , site . SiteDir ) ;
200
-
201
174
site . StartServer ( ) ;
202
175
203
176
var response = site . Request ( "" ) ;
@@ -210,8 +183,6 @@ public void CustomCallableHandler() {
210
183
[ TestMethod , Priority ( 0 ) ]
211
184
public void ErrorHandler ( ) {
212
185
using ( var site = ConfigureIISForCustomHandler ( AppCmdPath , InterpreterPath , "custom_handler.error_handler" ) ) {
213
- CopyDir ( "TestData" , site . SiteDir ) ;
214
-
215
186
site . StartServer ( ) ;
216
187
try {
217
188
var response = site . Request ( "" ) ;
@@ -246,7 +217,7 @@ private static string CreateSite() {
246
217
public static void ConfigureIIS ( string appCmd , string appHostConfig , string python , string wfastcgi , Dictionary < string , string > envVars ) {
247
218
using ( var p = ProcessOutput . RunHiddenAndCapture (
248
219
appCmd , "set" , "config" , "/section:system.webServer/fastCGI" ,
249
- string . Format ( "/+[fullPath='{0}', arguments='\" \" \" {1}\" \" \" ']" , python , wfastcgi ) ,
220
+ string . Format ( "/+[fullPath='{0}', arguments='\" {1}\" ']" , python , wfastcgi ) ,
250
221
"/AppHostConfig:" + appHostConfig
251
222
) ) {
252
223
p . Wait ( ) ;
@@ -257,7 +228,7 @@ public static void ConfigureIIS(string appCmd, string appHostConfig, string pyth
257
228
using ( var p = ProcessOutput . RunHiddenAndCapture (
258
229
appCmd , "set" , "config" , "/section:system.webServer/handlers" ,
259
230
string . Format (
260
- "/+[name='Python_via_FastCGI',path='*',verb='*',modules='FastCgiModule',scriptProcessor='{0}|\" \" \" {1}\" \" \" ',resourceType='Unspecified']" ,
231
+ "/+[name='Python_via_FastCGI',path='*',verb='*',modules='FastCgiModule',scriptProcessor='{0}|\" {1}\" ',resourceType='Unspecified']" ,
261
232
python , wfastcgi
262
233
) ,
263
234
"/AppHostConfig:" + appHostConfig
@@ -269,9 +240,9 @@ public static void ConfigureIIS(string appCmd, string appHostConfig, string pyth
269
240
270
241
foreach ( var keyValue in envVars ) {
271
242
using ( var p = ProcessOutput . RunHiddenAndCapture (
272
- appCmd , "set" , "config" , "- section:system.webServer/fastCgi" ,
243
+ appCmd , "set" , "config" , "/ section:system.webServer/fastCgi" ,
273
244
string . Format (
274
- "/+\" [fullPath='{0}', arguments='\" \" \" {1}\" \" \" '].environmentVariables.[name='{2}',value='{3}']" ,
245
+ "/+[fullPath='{0}', arguments='\" {1}\" '].environmentVariables.[name='{2}',value='{3}']" ,
275
246
python , wfastcgi , keyValue . Key , keyValue . Value
276
247
) ,
277
248
"/commit:apphost" ,
@@ -296,6 +267,7 @@ public static void ConfigureIIS(string appCmd, string appHostConfig, string pyth
296
267
}
297
268
298
269
private static void DumpOutput ( ProcessOutput process ) {
270
+ Console . WriteLine ( process . Arguments ) ;
299
271
foreach ( var line in process . StandardOutputLines ) {
300
272
Console . WriteLine ( line ) ;
301
273
}
@@ -334,9 +306,15 @@ private static WebSite ConfigureIISForDjango(string appCmd, string python, strin
334
306
{ "PYTHONPATH" , "" } ,
335
307
{ "WSGI_HANDLER" , "django.core.handlers.wsgi.WSGIHandler()" }
336
308
}
309
+ ) ;
337
310
311
+ var module = djangoSettings . Split ( new [ ] { '.' } , 2 ) [ 0 ] ;
312
+ FileUtils . CopyDirectory (
313
+ TestData . GetPath ( Path . Combine ( "TestData" , "WFastCgi" , module ) ) ,
314
+ Path . Combine ( site , module )
338
315
) ;
339
316
317
+
340
318
Console . WriteLine ( "Site created at {0}" , site ) ;
341
319
return new WebSite ( site ) ;
342
320
}
@@ -354,16 +332,33 @@ private static WebSite ConfigureIISForCustomHandler(string appCmd, string python
354
332
{ "WSGI_HANDLER" , handler } ,
355
333
{ "WSGI_LOG" , Path . Combine ( site , "log.txt" ) }
356
334
}
357
-
358
335
) ;
359
336
337
+ var module = handler . Split ( new [ ] { '.' } , 2 ) [ 0 ] ;
338
+ try {
339
+ File . Copy (
340
+ TestData . GetPath ( "TestData\\ WFastCGI\\ " + module + ".py" ) ,
341
+ Path . Combine ( site , module + ".py" ) ,
342
+ true
343
+ ) ;
344
+ } catch ( IOException ex ) {
345
+ Console . WriteLine ( "Failed to copy {0}.py: {1}" , module , ex ) ;
346
+ }
347
+
348
+
360
349
Console . WriteLine ( "Site created at {0}" , site ) ;
361
350
return new WebSite ( site ) ;
362
351
}
363
352
364
- public virtual string InterpreterPath {
353
+ public virtual PythonVersion PythonVersion {
365
354
get {
366
- return PythonPaths . Python27 . InterpreterPath ;
355
+ return PythonPaths . Python27 ?? PythonPaths . Python27_x64 ;
356
+ }
357
+ }
358
+
359
+ public string InterpreterPath {
360
+ get {
361
+ return PythonVersion . InterpreterPath ;
367
362
}
368
363
}
369
364
@@ -376,21 +371,6 @@ public virtual string AppCmdPath {
376
371
}
377
372
}
378
373
379
- private static void CopyDir ( string source , string target ) {
380
- foreach ( var dir in Directory . GetDirectories ( source ) ) {
381
- var targetDir = Path . Combine ( target , Path . GetFileName ( dir ) ) ;
382
- //Console.WriteLine("Creating dir: {0}", targetDir);
383
- Directory . CreateDirectory ( targetDir ) ;
384
- CopyDir ( dir , targetDir ) ;
385
- }
386
-
387
- foreach ( var file in Directory . GetFiles ( source ) ) {
388
- var targetFile = Path . Combine ( target , Path . GetFileName ( file ) ) ;
389
- //Console.WriteLine("Deploying: {0} -> {1}", file, targetFile);
390
- File . Copy ( file , targetFile ) ;
391
- }
392
- }
393
-
394
374
class WebSite : IDisposable {
395
375
private readonly string _dir ;
396
376
private ProcessOutput _process ;
@@ -420,8 +400,13 @@ public void StartServer() {
420
400
public WebResponse Request ( string uri ) {
421
401
WebRequest req = WebRequest . Create (
422
402
"http://localhost:8181/" + uri
423
- ) ;
424
- return req . GetResponse ( ) ;
403
+ ) ;
404
+ try {
405
+ return req . GetResponse ( ) ;
406
+ } catch ( WebException ex ) {
407
+ Console . WriteLine ( new StreamReader ( ex . Response . GetResponseStream ( ) ) . ReadToEnd ( ) ) ;
408
+ throw ;
409
+ }
425
410
}
426
411
427
412
public void StopServer ( ) {
@@ -580,7 +565,7 @@ public void TestEnvironment() {
580
565
[ TestMethod , Priority ( 0 ) , TestCategory ( "Core" ) ]
581
566
public void TestFileSystemChanges ( ) {
582
567
var location = TestData . GetTempPath ( randomSubPath : true ) ;
583
- CopyDir ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChanges" ) , location ) ;
568
+ FileUtils . CopyDirectory ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChanges" ) , location ) ;
584
569
585
570
IisExpressTest (
586
571
location ,
@@ -609,7 +594,7 @@ public void TestFileSystemChanges() {
609
594
[ TestMethod , Priority ( 0 ) , TestCategory ( "Core" ) ]
610
595
public void TestFileSystemChangesPackage ( ) {
611
596
var location = TestData . GetTempPath ( randomSubPath : true ) ;
612
- CopyDir ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChangesPackage" ) , location ) ;
597
+ FileUtils . CopyDirectory ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChangesPackage" ) , location ) ;
613
598
614
599
IisExpressTest (
615
600
location ,
@@ -633,7 +618,7 @@ public void TestFileSystemChangesPackage() {
633
618
[ TestMethod , Priority ( 0 ) , TestCategory ( "Core" ) ]
634
619
public void TestFileSystemChangesCustomRegex ( ) {
635
620
var location = TestData . GetTempPath ( randomSubPath : true ) ;
636
- CopyDir ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChangesCustomRegex" ) , location ) ;
621
+ FileUtils . CopyDirectory ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChangesCustomRegex" ) , location ) ;
637
622
638
623
IisExpressTest (
639
624
location ,
@@ -655,7 +640,7 @@ public void TestFileSystemChangesCustomRegex() {
655
640
[ TestMethod , Priority ( 0 ) , TestCategory ( "Core" ) ]
656
641
public void TestFileSystemChangesDisabled ( ) {
657
642
var location = TestData . GetTempPath ( randomSubPath : true ) ;
658
- CopyDir ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChangesDisabled" ) , location ) ;
643
+ FileUtils . CopyDirectory ( TestData . GetPath ( @"TestData\WFastCgi\FileSystemChangesDisabled" ) , location ) ;
659
644
660
645
IisExpressTest (
661
646
location ,
@@ -1060,6 +1045,7 @@ public static implicit operator Action(GetAndValidateErrorUrl self) {
1060
1045
}
1061
1046
1062
1047
private Action CollectStaticFiles ( string location ) {
1048
+ location = TestData . GetPath ( location ) ;
1063
1049
return ( ) => {
1064
1050
using ( var p = ProcessOutput . Run (
1065
1051
InterpreterPath ,
@@ -1168,7 +1154,7 @@ params Action[] actions
1168
1154
IisExpressPath ,
1169
1155
new [ ] { "/config:" + appConfig , "/site:WebSite1" , "/systray:false" , "/trace:info" } ,
1170
1156
null ,
1171
- new [ ] { new KeyValuePair < string , string > ( "WSGI_LOG" , Path . Combine ( location , "log.txt" ) ) } ,
1157
+ env ,
1172
1158
false ,
1173
1159
new OutputRedirector ( "IIS" )
1174
1160
) ) {
@@ -1205,7 +1191,8 @@ public override void WriteErrorLine(string line) {
1205
1191
1206
1192
private static string IisExpressPath {
1207
1193
get {
1208
- var iisExpressPath = Registry . GetValue ( "HKEY_LOCAL_MACHINE\\ SOFTWARE\\ Microsoft\\ IISExpress\\ 8.0" , "InstallPath" , null ) as string ;
1194
+ var iisExpressPath = Registry . GetValue ( "HKEY_LOCAL_MACHINE\\ SOFTWARE\\ Microsoft\\ IISExpress\\ 10.0" , "InstallPath" , null ) as string ??
1195
+ Registry . GetValue ( "HKEY_LOCAL_MACHINE\\ SOFTWARE\\ Microsoft\\ IISExpress\\ 8.0" , "InstallPath" , null ) as string ;
1209
1196
if ( iisExpressPath == null ) {
1210
1197
Assert . Inconclusive ( "Can't find IIS Express" ) ;
1211
1198
return null ;
0 commit comments