
    T&                         S SK r S SKrS SKrS SKJr  \ R
                  R                  \ R
                  R                  \5      5      r " S S\R                  5      r
\S:X  a  \R                  " 5         gg)    N)testutilc                      ^  \ rS rSrSrS rS rU 4S jrS rS r	S r
S	 rS
 rS rS rS rS rS rS rS rSrU =r$ )RuntimeTestCase   z1Tests for the PHP external runtime fingerprinter.c                 .    [         R                  " S5      $ )Na              # Copyright 2015 Google Inc. All Rights Reserved.
            #
            # Licensed under the Apache License, Version 2.0 (the "License");
            # you may not use this file except in compliance with the License.
            # You may obtain a copy of the License at
            #
            #    http://www.apache.org/licenses/LICENSE-2.0
            #
            # Unless required by applicable law or agreed to in writing, software
            # distributed under the License is distributed on an "AS IS" BASIS,
            # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
            # See the License for the specific language governing permissions and
            # limitations under the License.

            textwrapdedentselfs    -platform/ext-runtime/php/test/runtime_test.pylicenseRuntimeTestCase.license   s        	    c                 .    [         R                  " S5      $ )Na/              # Dockerfile extending the generic PHP image with application files for a
            # single application.
            FROM gcr.io/google-appengine/php:latest

            # The Docker image will configure the document root according to this
            # environment variable.
            r   r   s    r   preambleRuntimeTestCase.preamble.   s        	r   c                 @   > [         U l        [        [        U ]  5         g N)RUNTIME_DEF_ROOTruntime_def_rootsuperr   setUp)r   	__class__s    r   r   RuntimeTestCase.setUp8   s     0ot*,r   c                     [        U R                  U5      5       nUR                  5       sS S S 5        $ ! , (       d  f       g = fr   )open	full_pathread)r   filenamefs      r   file_contentsRuntimeTestCase.file_contents<   s*    $..*+q668 ,++s	   5
Ac                    U R                  SS5        U R                  U R                  5       5        U R                  [        R                  R                  U R                  S5      5      5        U R                  [        R                  R                  U R                  S5      5      5        U R                  [        R                  R                  U R                  S5      5      5        g )Nz
index.htmlindexapp.yaml
Dockerfile.dockerignore)
write_fileassertFalsegenerate_configsospathexistsr   r   s    r   test_generate_without_php_files/RuntimeTestCase.test_generate_without_php_files@   s    g...01z(BCD|(DEF(GHIr   c                    U R                  SS5        U R                  5         U R                  S5      nU R                  SU5        U R                  SU5        U R                  SU5        U R	                  SU5        U R                  [        R                  R                  U R                  S5      5      5        U R                  [        R                  R                  U R                  S	5      5      5        g )
N	index.phpr%   r&   runtime: php

env: flex
#runtime_config:
  document_root: .

entrypointr'   r(   )
r)   r+   r"   assertInassertNotInr*   r,   r-   r.   r   r   app_yamls     r   test_generate_with_php_files,RuntimeTestCase.test_generate_with_php_filesI   s    W-%%j1&1mX.=xHx0|(DEF(GHIr   c                    U R                  SS5        U R                  5         U R                  S5      nU R                  SU5        U R                  SU5        U R                  SU5        U R	                  [
        R                  R                  U R                  S5      5      5        U R	                  [
        R                  R                  U R                  S5      5      5        g	)
zTest generate_config_data with a .php file.

Checks app.yaml contents, app.yaml is written to disk, and
Dockerfile and .dockerignore not in the directory.
r2   r%   r&   r3   r4   r5   r'   r(   N)	r)   generate_config_datar"   r7   r*   r,   r-   r.   r   r9   s     r   %test_generate_with_php_files_no_write5RuntimeTestCase.test_generate_with_php_files_no_writeV   s     	W-!!#%%j1&1mX.=xH|(DEF(GHIr   c                 B   U R                  SS5        U R                  SS9  U R                  S5      nU R                  XR	                  5       [
        R                  " S5      -   5        U R                  SU R                  5       [
        R                  " S5      -   5        g )	Nr2   r%   Tcustomr'   /            ENV DOCUMENT_ROOT /app
            r(   o            .dockerignore
            Dockerfile
            .git
            .hg
            .svn
            )	r)   r+   r"   assertEqualr   r	   r
    assert_file_exists_with_contentsr   )r   
dockerfiles     r   test_generate_custom_runtime,RuntimeTestCase.test_generate_custom_runtimeg   s    W-T*''5
]]_x H 8 & 	 	--LLNX__ .  	r   c                 &   U R                  SS5        U R                  SS9nU R                  USU R                  5       [        R
                  " S5      -   5        U R                  USU R                  5       [        R
                  " S5      -   5        g	)
z/Tests generate_config_data with custom runtime.r2   r%   TrB   r'   rD   r(   rE   Nr)   r>   #assert_genfile_exists_with_contentsr   r	   r
   r   r   	cfg_filess     r   %test_generate_custom_runtime_no_write5RuntimeTestCase.test_generate_custom_runtime_no_writez       W---T-:	00MMOhoo /  	 	00LLNX__ .  		r   c                 B   U R                  SS5        U R                  SS9  U R                  S5      nU R                  U[        R
                  " S5      5        U R                  S5      nU R                  X R                  5       [        R
                  " S5      -   5        g )	Nr2   r%   Tdeployr'   aR              # Dockerfile extending the generic PHP image with application files for a
            # single application.
            FROM gcr.io/google-appengine/php:latest

            # The Docker image will configure the document root according to this
            # environment variable.
            ENV DOCUMENT_ROOT /app
            r(   rE   )r)   r+   r"   rF   r	   r
   r   )r   rH   dockerignores      r   test_generate_with_deploy)RuntimeTestCase.test_generate_with_deploy   s    W-T*''5
X__ 6 & 	 ))/:||~ I 9 ( 	r   c                 &   U R                  SS5        U R                  SS9nU R                  USU R                  5       [        R
                  " S5      -   5        U R                  USU R                  5       [        R
                  " S5      -   5        g	)
z,Tests generate_config_data with deploy=True.r2   r%   TrT   r'   rD   r(   rE   NrL   rN   s     r   "test_generate_with_deploy_no_write2RuntimeTestCase.test_generate_with_deploy_no_write   rR   r   c                    U R                  SS5        [        R                  " SS0SS9nU R                  SUS9  U R	                  S	5      nU R                  X R                  5       [        R                  " S
5      -   5        U R	                  S5      nU R                  X0R                  5       [        R                  " S5      -   5        g )Nr2   r%   document_root	wordpress["/bin/bash", "my-cmd.sh"]runtime_configr6   TrU   appinfor'               ENV DOCUMENT_ROOT /app/wordpress

            # Allow custom CMD
            CMD ["/bin/bash", "my-cmd.sh"]
            r(   rE   )
r)   r   AppInfoFaker+   r"   rF   r   r	   r
   r   )r   rc   rH   rV   s       r   #test_generate_with_existing_appinfo3RuntimeTestCase.test_generate_with_existing_appinfo   s    W-&& /=79 	T7;''5
]]_x H 8 & 	 ))/:||~ I 9 ( 	r   c                 V   U R                  SS5        [        R                  " SS0SS9nU R                  SUS9nU R	                  US	U R                  5       [        R                  " S
5      -   5        U R	                  USU R                  5       [        R                  " S5      -   5        g)z-Tests generate_config_data with fake appinfo.r2   r%   r]   r^   r_   r`   Trb   r'   rd   r(   rE   N)	r)   r   re   r>   rM   r   r	   r
   r   r   rc   rO   s      r   ,test_generate_with_existing_appinfo_no_write<RuntimeTestCase.test_generate_with_existing_appinfo_no_write   s    W-&& /=79 --T7-K	00MMOhoo /  	 	00LLNX__ .  		r   c                    U R                  SS5        [        R                  " SS0SS/S9nU R                  SUS	9  U R	                  S
5      nU R                  X R                  5       [        R                  " S5      -   5        g )Nr2   r%   r]   r^   	/bin/bash	my-cmd.shr`   Trb   r'   rd   )	r)   r   re   r+   r"   rF   r   r	   r
   )r   rc   rH   s      r   #test_generate_with_array_entrypoint3RuntimeTestCase.test_generate_with_array_entrypoint   s    W-&& /='57 	T7;''5
]]_x H 8 & 	r   c                     U R                  SS5        [        R                  " SS0SS/S9nU R                  SUS	9nU R	                  US
U R                  5       [        R                  " S5      -   5        g)z4Tests generate_config_data with an array entrypoint.r2   r%   r]   r^   rm   rn   r`   Trb   r'   rd   N)r)   r   re   r>   rM   r   r	   r
   ri   s      r   ,test_generate_with_array_entrypoint_no_write<RuntimeTestCase.test_generate_with_array_entrypoint_no_write  sy    W-&& /='57 --T7-K	00MMOhoo /  	r   )r   )__name__
__module____qualname____firstlineno____doc__r   r   r   r"   r/   r;   r?   rI   rP   rW   rZ   rf   rj   ro   rr   __static_attributes____classcell__)r   s   @r   r   r      sY    ;$-JJJ"&.0.0: r   r   __main__)r,   r	   unittestgae_ext_runtimer   r-   dirname__file__r   TestBaser   rt   main r   r   <module>r      s`     
   $77??277??8#<= {h'' {z zMMO r   