U
    |®ŽhkV  ć                   @   s   d dl mZ d dlmZmZmZmZmZmZm	Z	m
Z
mZ d dlmZ d dlmZmZ G dd deZG dd deZG d	d
 d
eZG dd deZdS )é    )ŚTestCase)	ŚAlterBlockValueOperationŚ"ListChildrenToStructBlockOperationŚRemoveStreamChildrenOperationŚRemoveStructChildrenOperationŚRenameStreamChildrenOperationŚRenameStructChildrenOperationŚ"StreamChildrenToListBlockOperationŚ$StreamChildrenToStreamBlockOperationŚ$StreamChildrenToStructBlockOperation)Śapply_changes_to_raw_data)Ś	factoriesŚmodelsc                   @   s`   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dd Zdd Zdd ZdS )ŚFieldChildBlockTestz+Tests involving changes to top level blocksc                 C   s    t jdddddjj}|| _d S )NśChar Block 1śChar Block 2)Ścontent__0__char1__valueZcontent__1__char2__valueZcontent__2__char1__valueŚcontent__3__char2__value©r   ZSampleModelFactoryŚcontentŚraw_data©Śselfr   © r   ś/var/www/dating/data/www/fatepal.com/env/lib/python3.8/site-packages/wagtail/tests/streamfield_migrations/test_simple_structures.pyŚsetUp   s    ü
zFieldChildBlockTest.setUpc                 C   sī   t | jdtdddtjjd}|  |d d d” |  |d d d” |  |d d	 | jd d	 ” |  |d d	 | jd d	 ” |  |d d
 | jd d
 ” |  |d d
 | jd d
 ” |  |d | jd ” |  |d | jd ” dS )zėRename `char1` blocks to `renamed1`

        Check whether all `char1` blocks have been renamed correctly.
        Check whether ids and values for renamed blocks are intact.
        Check whether other block types are intact.
        Ś Śchar1Śrenamed1©Zold_nameŚnew_name©r   Zblock_path_strZ	operationZstreamfieldr   Śtypeé   ŚidŚvalueé   é   N©r   r   r   r   ŚSampleModelr   ŚassertEqual©r   Zaltered_raw_datar   r   r   Śtest_rename   s"     ’ś	zFieldChildBlockTest.test_renamec                 C   s\   t | jdtddtjjd}|  t|d” |  |d | jd ” |  |d | jd ” d	S )
zRemove all `char1` blocks

        Check whether all `char1` blocks have been removed and whether other blocks are intact.
        r   r   ©Śnamer!   r#   r   r&   r'   N©r   r   r   r   r)   r   r*   Ślenr+   r   r   r   Śtest_remove:   s    üzFieldChildBlockTest.test_removec                 C   sZ  t | jdtdddtjjd}|  t|d” |  |d | jd ” |  |d | jd ” |  |d	 d
 d” |  t|d	 d d	” |  |d	 d d d
 d” |  |d	 d d d
 d” |  |d	 d d d | jd d ” |  |d	 d d d | jd	 d ” |  |d	 d d d | jd d ” |  |d	 d d d | jd	 d ” dS )aŹ  Combine all `char1` blocks into a new ListBlock named `list1`

        Check whether no `char1` blocks are present among the stream children and whether other
        blocks are intact.
        Check whether a new `list1` block has been added to the stream children and whether it has
        child blocks corresponding to the previous `char1` blocks.
        Check whether the ids and values from the `char1` blocks are intact in the list children.
        r   r   Ślist1©Ś
block_nameZlist_block_namer!   r'   r   r&   r#   r"   r%   Śitemr$   N©r   r   r	   r   r)   r   r*   r0   r+   r   r   r   Śtest_combine_to_listblockJ   s4    	 ’ś	&& ’ ’z-FieldChildBlockTest.test_combine_to_listblockc                 C   s   t | jdtdddtjjd}|  t|d” |  |d | jd ” |  |d | jd ” |  |d	 | jd	 ” |  |d
 | jd
 ” dS )zŽCombine all `simplestruct` blocks into a new ListBlock named `list1`
        We have no `simplestruct` blocks in our existing data, so there should be no list1 blocks
        created and the data should be intact.
        r   Śsimplestructr2   r3   r!   é   r   r&   r#   r'   Nr6   r+   r   r   r   Ś.test_combine_to_listblock_no_existing_childrenn   s     ’ś	zBFieldChildBlockTest.test_combine_to_listblock_no_existing_childrenc                 C   sČ   t | jdtdgddtjjd}|  t|d” |  |d | jd ” |  |d | jd ” |  |d	 d
 d” |  t|d	 d d	” |  |d	 d d | jd ” |  |d	 d d | jd	 ” dS )a„  Combine all `char1` blocks as children of a new StreamBlock named `stream1`

        Check whether no `char1` blocks are present among the (top) stream children and whether
        other blocks are intact.
        Check whether a new `stream1` block has been added to the (top) stream children.
        Check whether the new `stream1` block has the `char1` blocks as children and whether they
        are intact.
        r   r   Śstream1©Zblock_namesZstream_block_namer!   r'   r   r&   r#   r"   r%   N©r   r   r
   r   r)   r   r*   r0   r+   r   r   r   Ś'test_combine_single_type_to_streamblock   s     
 ’ś	z;FieldChildBlockTest.test_combine_single_type_to_streamblockc                 C   sŚ   t | jdtddgddtjjd}|  t|d” |  |d d	 d” |  t|d d
 d” |  |d d
 d | jd ” |  |d d
 d | jd ” |  |d d
 d | jd ” |  |d d
 d | jd ” dS )aņ  Combine all `char1` and `char2` blocks as children of a new StreamBlock named `stream1`

        Check whether no `char1` or `char2` blocks are present among the (top) stream children.
        Check whether a new `stream1` block has been added to the (top) stream children.
        Check whether the new `stream1` block has the `char1` and `char2` blocks as children and
        that they are intact.

        Note:
            We only have `char1` and `char2` blocks in our existing data.
        r   r   Śchar2r;   r<   r!   r&   r   r"   r%   r9   r#   r'   Nr=   r+   r   r   r   Ś*test_combine_multiple_types_to_streamblock    s      ’ś	z>FieldChildBlockTest.test_combine_multiple_types_to_streamblockc                 C   s   t | jdtdgddtjjd}|  t|d” |  |d | jd ” |  |d | jd ” |  |d	 | jd	 ” |  |d
 | jd
 ” dS )zīCombine all `simplestruct` blocks as children of a new StreamBlock named `stream1`
        We have no `simplestruct` blocks in our existing data, so there should be no stream1 blocks
        created and the data should be intact.
        r   r8   r;   r<   r!   r9   r   r&   r#   r'   Nr=   r+   r   r   r   Ś0test_combine_to_streamblock_no_existing_children¾   s     ’ś	zDFieldChildBlockTest.test_combine_to_streamblock_no_existing_childrenc                 C   są   t | jdtddtjjd}|  |d d d” |  |d d d” |  |d | jd ” |  |d	 | jd	 ” |  d|d d
 ” |  d|d d
 ” |  |d d
 d | jd d
 ” |  |d d
 d | jd d
 ” dS )a«  Move each `char1` block inside a new StructBlock named `struct1`

        Check whether each `char1` block has been replaced with a `struct1` block in the stream
        children.
        Check whether other blocks are intact.
        Check whether each `struct1` block has a `char1` child and whether it has the value of the
        previous `char1` block.

        Note:
            Block ids are not preserved here.
        r   r   Zstruct1r!   r   r"   r#   r&   r'   r%   N)r   r   r   r   r)   r   r*   ŚassertInr+   r   r   r   Śtest_to_structblockÓ   s(    ü ’ ’z'FieldChildBlockTest.test_to_structblockc                 C   s   t | jdtddtjjd}|  |d d d” |  |d d | jd d ” |  |d d d” |  |d	 d | jd	 d ” d
S )zĀChange the value of each `char1` block to `foo`

        Check whether the value of each `char1` block has changed to `foo`.
        Check whether the values of other blocks are intact.
        r   Zfoo)Ś	new_valuer!   r   r%   r&   r#   r'   N)r   r   r   r   r)   r   r*   r+   r   r   r   Śtest_alter_valueö   s    üz$FieldChildBlockTest.test_alter_valueN)Ś__name__Ś
__module__Ś__qualname__Ś__doc__r   r,   r1   r7   r:   r>   r@   rA   rC   rE   r   r   r   r   r      s   	$#r   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )ŚFieldStructChildBlockTestz|Tests involving changes to direct children of a StructBlock

    We use `simplestruct` blocks as the StructBlocks here.
    c                 C   s    t jdddddjj}|| _d S )Nr   r8   r   )r   Ś
content__1Ś
content__2r   r   r   r   r   r   r     s    ü
zFieldStructChildBlockTest.setUpc                 C   sĘ   t | jdtdddtjjd}|  |d | jd ” |  |d | jd ” |  |d d	 | jd d	 ” |  |d
 d	 | jd
 d	 ” |  |d d | jd d ” |  |d
 d | jd
 d ” dS )įs  Test whether other blocks and data not passed to an operation are intact.

        We are checking whether the parts of the data which are not passed to an operation are
        intact. Since the recursion process depends just on the block path and block structure,
        this check is independent of the operation used. We will use a rename operation for now.
        r8   r   r   r   r!   r   r'   r&   r$   r#   r"   N)r   r   r   r   r)   r   r*   r+   r   r   r   Ś+test_blocks_and_data_not_operated_on_intact  s     ’ś	zEFieldStructChildBlockTest.test_blocks_and_data_not_operated_on_intactc                 C   sb  t | jdtdddtjjd}|  t|d d d” |  t|d d d” |  d|d d ” |  d|d d ” |  	d|d d ” |  	d|d d ” |  |d d d | jd d d ” |  |d d d | jd d d ” |  	d	|d d ” |  	d	|d d ” |  |d d d	 | jd d d	 ” |  |d d d	 | jd d d	 ” d
S )a  Rename `simplestruct.char1` blocks to `renamed1`

        Check whether all `simplestruct.char1` blocks have been renamed correctly.
        Check whether values for renamed blocks are intact.
        Check whether other children of `simplestruct` are intact.
        r8   r   r   r   r!   r&   r%   r#   r?   N)
r   r   r   r   r)   r   r*   r0   ŚassertNotInrB   r+   r   r   r   r,   2  sB     ’ś	 ’ ’ ’ ’z%FieldStructChildBlockTest.test_renamec                 C   sģ   t | jdtddtjjd}|  t|d d d” |  t|d d d” |  d|d d ” |  d|d d ” |  	d|d d ” |  	d|d d ” |  |d d d | jd d d ” |  |d d d | jd d d ” d	S )
zøRemove `simplestruct.char1` blocks

        Check whether all `simplestruct.char1` blocks have been removed.
        Check whether other children of `simplestruct` are intact.
        r8   r   r-   r!   r&   r%   r#   r?   N)
r   r   r   r   r)   r   r*   r0   rO   rB   r+   r   r   r   r1   Z  s(    ü ’ ’z%FieldStructChildBlockTest.test_removeN©rF   rG   rH   rI   r   rN   r,   r1   r   r   r   r   rJ   
  s
   	(rJ   c                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )ŚFieldStreamChildBlockTestz|Tests involving changes to direct children of a StreamBlock

    We use `simplestream` blocks as the StreamBlocks here.
    c              
   C   s(   t jdddddddddjj}|| _d S )Nr   Śsimplestreamr   )r   rK   Z)content__1__simplestream__0__char1__valueZ)content__1__simplestream__1__char2__valueZ)content__1__simplestream__2__char1__valuerL   Z)content__2__simplestream__0__char1__valuer   r   r   r   r   r   r   }  s    ų

zFieldStreamChildBlockTest.setUpc                 C   sĘ   t | jdtdddtjjd}|  |d | jd ” |  |d | jd ” |  |d d	 | jd d	 ” |  |d
 d	 | jd
 d	 ” |  |d d | jd d ” |  |d
 d | jd
 d ” dS )rM   rR   r   r   r   r!   r   r'   r&   r$   r#   r"   Nr(   r+   r   r   r   rN     s     ’śzEFieldStreamChildBlockTest.test_blocks_and_data_not_operated_on_intactc                 C   s°  t | jdtdddtjjd}|  |d d d d	 d” |  |d d d
 d	 d” |  |d
 d d d	 d” |  |d d d d | jd d d d ” |  |d d d
 d | jd d d
 d ” |  |d
 d d d | jd
 d d d ” |  |d d d d | jd d d d ” |  |d d d
 d | jd d d
 d ” |  |d
 d d d | jd
 d d d ” |  |d d d | jd d d ” dS )a  Rename `simplestream.char1` blocks to `renamed1`

        Check whether all `simplestream.char1` blocks have been renamed correctly.
        Check whether values and ids for renamed blocks are intact.
        Check whether other children of `simplestream` are intact.
        rR   r   r   r   r!   r&   r%   r   r"   r#   r$   Nr(   r+   r   r   r   r,   ¢  sJ     ’ś	 ’ ’ ’žžžz%FieldStreamChildBlockTest.test_renamec                 C   sv   t | jdtddtjjd}|  t|d d d” |  t|d d d” |  |d d d | jd d d ” d	S )
zøRemove `simplestream.char1` blocks

        Check whether all `simplestream.char1` blocks have been removed.
        Check whether other children of `simplestream` are intact.
        rR   r   r-   r!   r&   r%   r#   r   Nr/   r+   r   r   r   r1   Ļ  s    üz%FieldStreamChildBlockTest.test_removeNrP   r   r   r   r   rQ   w  s
   -rQ   c                   @   s    e Zd ZdZdd Zdd ZdS )ŚFieldListChildBlockTestzvTests involving changes to direct children of a ListBlock

    We use `simplelist` blocks as the ListBlocks here.
    c                 C   s    t jdddddjj}|| _d S )Nr   zFoo 1zFoo 2zFoo 3)r   Zcontent__1__simplelist__0Zcontent__1__simplelist__1Zcontent__2__simplelist__0r   r   r   r   r   r   é  s    ü
zFieldListChildBlockTest.setUpc                 C   sj  t | jdtddtjjd}|  t|d d d d t” |  t|d d d d t” |  t|d d d d t” |  	d|d d d d ” |  	d|d d d d ” |  	d|d d d d ” |  |d d d d d | jd d d d ” |  |d d d d d | jd d d d ” |  |d d d d d | jd d d d ” d	S )
ao  Turn each list child into a StructBlock and move value inside as a child named `text`

        Check whether each list child has been converted to a StructBlock with a child named `text`
        in it.
        Check whether the previous value of each list child is now the value that `text` takes.

        Note:
            Block ids are not preserved here.
        Z
simplelistŚtext)r4   r!   r&   r%   r   r#   N)
r   r   r   r   r)   r   r*   r"   ŚdictrB   r+   r   r   r   rC   ņ  s0    ü   žžžz+FieldListChildBlockTest.test_to_structblockN)rF   rG   rH   rI   r   rC   r   r   r   r   rS   ć  s   	rS   N)Zdjango.testr   Z$wagtail.blocks.migrations.operationsr   r   r   r   r   r   r	   r
   r   Zwagtail.blocks.migrations.utilsr   Z#wagtail.test.streamfield_migrationsr   r   r   rJ   rQ   rS   r   r   r   r   Ś<module>   s   , yml