Best Python code snippet using fMBT_python
test_netlink_lib.py
Source:test_netlink_lib.py  
1# Copyright (c) 2017 Fujitsu Limited2# All Rights Reserved.3#4#    Licensed under the Apache License, Version 2.0 (the "License"); you may5#    not use this file except in compliance with the License. You may obtain6#    a copy of the License at7#8#         http://www.apache.org/licenses/LICENSE-2.09#10#    Unless required by applicable law or agreed to in writing, software11#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13#    License for the specific language governing permissions and limitations14#    under the License.15import mock16from neutron_lib import constants17import testtools18from neutron.common import exceptions19from neutron.privileged.agent.linux import netlink_constants as nl_constants20from neutron.privileged.agent.linux import netlink_lib as nl_lib21from neutron.tests import base22FAKE_ICMP_ENTRY = {'ipversion': 4, 'protocol': 'icmp',23                   'type': '8', 'code': '0', 'id': 1234,24                   'src': '1.1.1.1', 'dst': '2.2.2.2', 'zone': 1}25FAKE_TCP_ENTRY = {'ipversion': 4, 'protocol': 'tcp',26                  'sport': 1, 'dport': 2,27                  'src': '1.1.1.1', 'dst': '2.2.2.2', 'zone': 1}28FAKE_UDP_ENTRY = {'ipversion': 4, 'protocol': 'udp',29                  'sport': 1, 'dport': 2,30                  'src': '1.1.1.1', 'dst': '2.2.2.2', 'zone': 1}31class NetlinkLibTestCase(base.BaseTestCase):32    def setUp(self):33        super(NetlinkLibTestCase, self).setUp()34        nl_lib.nfct = mock.Mock()35        nl_lib.libc = mock.Mock()36    def test_open_new_conntrack_handler_failed(self):37        nl_lib.nfct.nfct_open.return_value = None38        with testtools.ExpectedException(exceptions.CTZoneExhaustedError):39            with nl_lib.ConntrackManager():40                nl_lib.nfct.nfct_open.assert_called_once_with()41            nl_lib.nfct.nfct_close.assert_not_called()42    def test_open_new_conntrack_handler_pass(self):43        with nl_lib.ConntrackManager():44            nl_lib.nfct.nfct_open.assert_called_once_with(45                nl_constants.CONNTRACK, nl_constants.NFNL_SUBSYS_CTNETLINK)46        nl_lib.nfct.nfct_close.assert_called_once_with(nl_lib.nfct.nfct_open(47            nl_constants.CONNTRACK, nl_constants.NFNL_SUBSYS_CTNETLINK))48    def test_conntrack_list_entries(self):49        with nl_lib.ConntrackManager() as conntrack:50            nl_lib.nfct.nfct_open.assert_called_once_with(51                nl_constants.CONNTRACK, nl_constants.NFNL_SUBSYS_CTNETLINK)52            conntrack.list_entries()53            nl_lib.nfct.nfct_callback_register.assert_has_calls(54                [mock.call(nl_lib.nfct.nfct_open(), nl_constants.NFCT_T_ALL,55                 mock.ANY, None)])56            nl_lib.nfct.nfct_query.assert_called_once_with(57                nl_lib.nfct.nfct_open(58                    nl_constants.CONNTRACK,59                    nl_constants.NFNL_SUBSYS_CTNETLINK),60                nl_constants.NFCT_Q_DUMP,61                mock.ANY)62        nl_lib.nfct.nfct_close.assert_called_once_with(nl_lib.nfct.nfct_open(63            nl_constants.CONNTRACK, nl_constants.NFNL_SUBSYS_CTNETLINK))64    def test_conntrack_new_failed(self):65        nl_lib.nfct.nfct_new.return_value = None66        with nl_lib.ConntrackManager() as conntrack:67            nl_lib.nfct.nfct_open.assert_called_once_with(68                nl_constants.CONNTRACK,69                nl_constants.NFNL_SUBSYS_CTNETLINK)70            conntrack.delete_entries([FAKE_ICMP_ENTRY])71            nl_lib.nfct.nfct_new.assert_called_once_with()72        nl_lib.nfct.nfct_destroy.assert_called_once_with(None)73        nl_lib.nfct.nfct_close.assert_called_once_with(nl_lib.nfct.nfct_open(74            nl_constants.CONNTRACK,75            nl_constants.NFNL_SUBSYS_CTNETLINK))76    def test_conntrack_delete_icmp_entry(self):77        conntrack_filter = mock.Mock()78        nl_lib.nfct.nfct_new.return_value = conntrack_filter79        with nl_lib.ConntrackManager() as conntrack:80            nl_lib.nfct.nfct_open.assert_called_once_with(81                nl_constants.CONNTRACK,82                nl_constants.NFNL_SUBSYS_CTNETLINK)83            conntrack.delete_entries([FAKE_ICMP_ENTRY])84            calls = [85                mock.call(conntrack_filter,86                          nl_constants.ATTR_L3PROTO,87                          nl_constants.IPVERSION_SOCKET[4]),88                mock.call(conntrack_filter,89                          nl_constants.ATTR_L4PROTO,90                          constants.IP_PROTOCOL_MAP['icmp']),91                mock.call(conntrack_filter,92                          nl_constants.ATTR_ICMP_CODE,93                          int(FAKE_ICMP_ENTRY['code'])),94                mock.call(conntrack_filter,95                          nl_constants.ATTR_ICMP_TYPE,96                          int(FAKE_ICMP_ENTRY['type']))97            ]98            nl_lib.nfct.nfct_set_attr_u8.assert_has_calls(calls,99                                                          any_order=True)100            calls = [101                mock.call(conntrack_filter,102                          nl_constants.ATTR_ICMP_ID,103                          nl_lib.libc.htons(FAKE_ICMP_ENTRY['id'])),104                mock.call(conntrack_filter,105                          nl_constants.ATTR_ZONE,106                          int(FAKE_ICMP_ENTRY['zone']))107            ]108            nl_lib.nfct.nfct_set_attr_u16.assert_has_calls(calls,109                                                           any_order=True)110            calls = [111                mock.call(conntrack_filter,112                          nl_constants.ATTR_IPV4_SRC,113                          str(conntrack._convert_text_to_binary(114                              FAKE_ICMP_ENTRY['src'], 4))115                          ),116                mock.call(conntrack_filter,117                          nl_constants.ATTR_IPV4_DST,118                          str(conntrack._convert_text_to_binary(119                              FAKE_ICMP_ENTRY['dst'], 4))120                          ),121            ]122            nl_lib.nfct.nfct_set_attr.assert_has_calls(calls, any_order=True)123            nl_lib.nfct.nfct_destroy.assert_called_once_with(conntrack_filter)124        nl_lib.nfct.nfct_close.assert_called_once_with(nl_lib.nfct.nfct_open(125            nl_constants.CONNTRACK,126            nl_constants.NFNL_SUBSYS_CTNETLINK))127    def test_conntrack_delete_udp_entry(self):128        conntrack_filter = mock.Mock()129        nl_lib.nfct.nfct_new.return_value = conntrack_filter130        with nl_lib.ConntrackManager() as conntrack:131            nl_lib.nfct.nfct_open.assert_called_once_with(132                nl_constants.CONNTRACK,133                nl_constants.NFNL_SUBSYS_CTNETLINK)134            conntrack.delete_entries([FAKE_UDP_ENTRY])135            calls = [136                mock.call(conntrack_filter,137                          nl_constants.ATTR_L3PROTO,138                          nl_constants.IPVERSION_SOCKET[4]),139                mock.call(conntrack_filter,140                          nl_constants.ATTR_L4PROTO,141                          constants.IP_PROTOCOL_MAP['udp'])142            ]143            nl_lib.nfct.nfct_set_attr_u8.assert_has_calls(calls,144                                                          any_order=True)145            calls = [146                mock.call(conntrack_filter,147                          nl_constants.ATTR_PORT_SRC,148                          nl_lib.libc.htons(FAKE_UDP_ENTRY['sport'])),149                mock.call(conntrack_filter,150                          nl_constants.ATTR_PORT_DST,151                          nl_lib.libc.htons(FAKE_UDP_ENTRY['dport'])),152                mock.call(conntrack_filter,153                          nl_constants.ATTR_ZONE,154                          int(FAKE_ICMP_ENTRY['zone']))155            ]156            nl_lib.nfct.nfct_set_attr_u16.assert_has_calls(calls,157                                                           any_order=True)158            calls = [159                mock.call(conntrack_filter,160                          nl_constants.ATTR_IPV4_SRC,161                          str(conntrack._convert_text_to_binary(162                              FAKE_UDP_ENTRY['src'], 4))163                          ),164                mock.call(conntrack_filter,165                          nl_constants.ATTR_IPV4_DST,166                          str(conntrack._convert_text_to_binary(167                              FAKE_UDP_ENTRY['dst'], 4))168                          ),169            ]170            nl_lib.nfct.nfct_set_attr.assert_has_calls(calls, any_order=True)171            nl_lib.nfct.nfct_destroy.assert_called_once_with(conntrack_filter)172        nl_lib.nfct.nfct_close.assert_called_once_with(nl_lib.nfct.nfct_open(173            nl_constants.CONNTRACK,174            nl_constants.NFNL_SUBSYS_CTNETLINK))175    def test_conntrack_delete_tcp_entry(self):176        conntrack_filter = mock.Mock()177        nl_lib.nfct.nfct_new.return_value = conntrack_filter178        with nl_lib.ConntrackManager() as conntrack:179            nl_lib.nfct.nfct_open.assert_called_once_with(180                nl_constants.CONNTRACK,181                nl_constants.NFNL_SUBSYS_CTNETLINK)182            conntrack.delete_entries([FAKE_TCP_ENTRY])183            calls = [184                mock.call(conntrack_filter,185                          nl_constants.ATTR_L3PROTO,186                          nl_constants.IPVERSION_SOCKET[4]),187                mock.call(conntrack_filter,188                          nl_constants.ATTR_L4PROTO,189                          constants.IP_PROTOCOL_MAP['tcp'])190            ]191            nl_lib.nfct.nfct_set_attr_u8.assert_has_calls(calls,192                                                          any_order=True)193            calls = [194                mock.call(conntrack_filter,195                          nl_constants.ATTR_PORT_SRC,196                          nl_lib.libc.htons(FAKE_TCP_ENTRY['sport'])),197                mock.call(conntrack_filter,198                          nl_constants.ATTR_PORT_DST,199                          nl_lib.libc.htons(FAKE_TCP_ENTRY['dport'])),200                mock.call(conntrack_filter,201                          nl_constants.ATTR_ZONE,202                          int(FAKE_ICMP_ENTRY['zone']))203            ]204            nl_lib.nfct.nfct_set_attr_u16.assert_has_calls(calls,205                                                           any_order=True)206            calls = [207                mock.call(conntrack_filter,208                          nl_constants.ATTR_IPV4_SRC,209                          str(conntrack._convert_text_to_binary(210                              FAKE_TCP_ENTRY['src'], 4))211                          ),212                mock.call(conntrack_filter,213                          nl_constants.ATTR_IPV4_DST,214                          str(conntrack._convert_text_to_binary(215                              FAKE_TCP_ENTRY['dst'], 4))216                          ),217            ]218            nl_lib.nfct.nfct_set_attr.assert_has_calls(calls, any_order=True)219            nl_lib.nfct.nfct_destroy.assert_called_once_with(conntrack_filter)220        nl_lib.nfct.nfct_close.assert_called_once_with(nl_lib.nfct.nfct_open(221            nl_constants.CONNTRACK,222            nl_constants.NFNL_SUBSYS_CTNETLINK))223    def test_conntrack_delete_entries(self):224        conntrack_filter = mock.Mock()225        nl_lib.nfct.nfct_new.return_value = conntrack_filter226        with nl_lib.ConntrackManager() as conntrack:227            nl_lib.nfct.nfct_open.assert_called_once_with(228                nl_constants.CONNTRACK,229                nl_constants.NFNL_SUBSYS_CTNETLINK)230            conntrack.delete_entries([FAKE_ICMP_ENTRY,231                                      FAKE_TCP_ENTRY,232                                      FAKE_UDP_ENTRY])233            calls = [234                mock.call(conntrack_filter,235                          nl_constants.ATTR_L3PROTO,236                          nl_constants.IPVERSION_SOCKET[4]),237                mock.call(conntrack_filter,238                          nl_constants.ATTR_L4PROTO,239                          constants.IP_PROTOCOL_MAP['tcp']),240                mock.call(conntrack_filter,241                          nl_constants.ATTR_L3PROTO,242                          nl_constants.IPVERSION_SOCKET[4]),243                mock.call(conntrack_filter,244                          nl_constants.ATTR_L4PROTO,245                          constants.IP_PROTOCOL_MAP['udp']),246                mock.call(conntrack_filter,247                          nl_constants.ATTR_L3PROTO,248                          nl_constants.IPVERSION_SOCKET[4]),249                mock.call(conntrack_filter,250                          nl_constants.ATTR_L4PROTO,251                          constants.IP_PROTOCOL_MAP['icmp']),252                mock.call(conntrack_filter,253                          nl_constants.ATTR_ICMP_CODE,254                          int(FAKE_ICMP_ENTRY['code'])),255                mock.call(conntrack_filter,256                          nl_constants.ATTR_ICMP_TYPE,257                          int(FAKE_ICMP_ENTRY['type']))258            ]259            nl_lib.nfct.nfct_set_attr_u8.assert_has_calls(calls,260                                                          any_order=True)261            calls = [262                mock.call(conntrack_filter,263                          nl_constants.ATTR_PORT_SRC,264                          nl_lib.libc.htons(FAKE_TCP_ENTRY['sport'])),265                mock.call(conntrack_filter,266                          nl_constants.ATTR_PORT_DST,267                          nl_lib.libc.htons(FAKE_TCP_ENTRY['dport'])),268                mock.call(conntrack_filter,269                          nl_constants.ATTR_ZONE,270                          int(FAKE_TCP_ENTRY['zone'])),271                mock.call(conntrack_filter,272                          nl_constants.ATTR_PORT_SRC,273                          nl_lib.libc.htons(FAKE_UDP_ENTRY['sport'])),274                mock.call(conntrack_filter,275                          nl_constants.ATTR_PORT_DST,276                          nl_lib.libc.htons(FAKE_UDP_ENTRY['dport'])),277                mock.call(conntrack_filter,278                          nl_constants.ATTR_ZONE,279                          int(FAKE_UDP_ENTRY['zone'])),280                mock.call(conntrack_filter,281                          nl_constants.ATTR_ICMP_ID,282                          nl_lib.libc.htons(FAKE_ICMP_ENTRY['id'])),283                mock.call(conntrack_filter,284                          nl_constants.ATTR_ZONE,285                          int(FAKE_ICMP_ENTRY['zone']))286            ]287            nl_lib.nfct.nfct_set_attr_u16.assert_has_calls(calls,288                                                           any_order=True)289            calls = [290                mock.call(conntrack_filter,291                          nl_constants.ATTR_IPV4_SRC,292                          str(conntrack._convert_text_to_binary(293                              FAKE_TCP_ENTRY['src'], 4))294                          ),295                mock.call(conntrack_filter,296                          nl_constants.ATTR_IPV4_DST,297                          str(conntrack._convert_text_to_binary(298                              FAKE_TCP_ENTRY['dst'], 4))),299                mock.call(conntrack_filter,300                          nl_constants.ATTR_IPV4_SRC,301                          str(conntrack._convert_text_to_binary(302                              FAKE_UDP_ENTRY['src'], 4))303                          ),304                mock.call(conntrack_filter,305                          nl_constants.ATTR_IPV4_DST,306                          str(conntrack._convert_text_to_binary(307                              FAKE_UDP_ENTRY['dst'], 4))308                          ),309                mock.call(conntrack_filter,310                          nl_constants.ATTR_IPV4_SRC,311                          str(conntrack._convert_text_to_binary(312                              FAKE_ICMP_ENTRY['src'], 4))313                          ),314                mock.call(conntrack_filter,315                          nl_constants.ATTR_IPV4_DST,316                          str(conntrack._convert_text_to_binary(317                              FAKE_ICMP_ENTRY['dst'], 4))318                          ),319            ]320            nl_lib.nfct.nfct_set_attr.assert_has_calls(calls, any_order=True)321            nl_lib.nfct.nfct_destroy.assert_called_once_with(conntrack_filter)322        nl_lib.nfct.nfct_close.assert_called_once_with(nl_lib.nfct.nfct_open(323            nl_constants.CONNTRACK,...test_models.py
Source:test_models.py  
1import pytest2import six3from django.core.exceptions import ValidationError4from django.test import override_settings5from wagtail.admin.edit_handlers import get_form_for_model6from tests.factories.language import LanguageFactory7from tests.factories.pages import TranslatablePageFactory8from tests.factories.sites import SiteFactory, SiteLanguagesFactory, create_site_tree9from tests.factories.users import UserFactory10from wagtailtrans import models11@pytest.mark.django_db12class TestWagtailAdminLanguageForm:13    def setup(self):14        self.form_class = get_form_for_model(model=models.Language, form_class=models.WagtailAdminLanguageForm)15    def test_init(self):16        models.Language.objects.all().delete()17        assert 'is_default' in self.form_class().fields.keys()18    def test_clean_is_default(self):19        language = LanguageFactory(is_default=True)20        form = self.form_class(instance=language, data={21            'code': language.code,22            'position': language.position,23            'is_default': True,24        })25        assert form.is_valid()26    def test_remove_is_default(self):27        language = LanguageFactory(is_default=True)28        form = self.form_class(instance=language, data={29            'code': language.code,30            'position': language.position,31            'is_default': False,32        })33        assert not form.is_valid()34        assert 'is_default' in form.errors35    def test_switch_language(self):36        LanguageFactory(is_default=True)37        new_default = LanguageFactory(code='nl', is_default=False)38        form = self.form_class(instance=new_default, data={39            'code': new_default.code,40            'position': new_default.position,41            'is_default': True,42        })43        assert form.is_valid()44        new_default = form.save()45        assert new_default.is_default46@pytest.mark.django_db47class TestLanguage:48    def test_create(self):49        en, created = models.Language.objects.get_or_create(50            code='en', defaults={51                'is_default': True,52                'position': 1,53                'live': True54            })55        assert isinstance(en, models.Language)56    def test_create_many(self, languages):57        assert models.Language.objects.count() == 558    def test_str(self):59        language = LanguageFactory()60        assert six.text_type(language) == 'British English'61    def test_default(self, languages):62        assert models.Language.objects.default().code == 'en'63    def test_has_pages_in_site(self):64        language = LanguageFactory()65        site_one = SiteFactory(hostname='remotehost', site_name='RemoteSite', root_page__title='site_1')66        site_two = SiteFactory(hostname='losthost', site_name='LostSite', root_page__title='site_2')67        create_site_tree(language, site=site_one, subtitle='hophop flepflep')68        create_site_tree(language, site=site_two, subtitle='hophop flepflep')69        language.refresh_from_db()70        assert language.has_pages_in_site(site_one)71        assert language.has_pages_in_site(site_two)72@pytest.mark.django_db73class TestTranslatablePage:74    def setup(self):75        """Setup a Site root and add an english page.76        We'll use this page as canonical page throughout the tests.77        """78        en = models.Language.objects.get(code='en')79        self.site_tree = create_site_tree(en)80        self.canonical_page = self.site_tree[1]81    def test_create(self):82        assert self.canonical_page.language.code == 'en'83    def test_serve(self, rf):84        request = rf.get('/en/')85        response = self.canonical_page.serve(request)86        assert response.status_code == 20087    def test_get_admin_display_title(self):88        en_root = self.canonical_page89        assert en_root.get_admin_display_title() == 'en homepage (English)'90        en_root.draft_title = 'en draft example'91        en_root.save()92        assert en_root.get_admin_display_title() == 'en draft example (English)'93    def test_create_translation(self, languages):94        """Test `create_translation` without copying fields."""95        nl = languages.get(code='nl')96        with override_settings(WAGTAILTRANS_SYNC_TREE=False):97            with pytest.raises(ValidationError):98                # HomePage contains some required fields which in this99                # case won't be copied, so a translation can't be made100                self.canonical_page.create_translation(language=nl)101    def test_create_translation_copy_fields(self, languages):102        """Test `create_translation` with `copy_fields` set to True."""103        nl = languages.get(code='nl')104        nl_page = self.canonical_page.create_translation(language=nl, copy_fields=True)105        assert nl_page.title == self.canonical_page.title106        assert nl_page.slug == '{}-{}'.format(self.canonical_page.slug, 'nl')107        assert nl_page.canonical_page == self.canonical_page108        assert nl_page.get_parent() == self.canonical_page.get_parent()109        # Other HomePage field should have been copied110        assert nl_page.subtitle == self.canonical_page.subtitle111        assert nl_page.body == self.canonical_page.body112        assert nl_page.image == self.canonical_page.image113    def test_has_translation(self, languages):114        language_nl = languages.get(code='nl')115        assert not self.canonical_page.has_translation(language_nl)116        self.canonical_page.create_translation(language_nl, copy_fields=True)117        assert self.canonical_page.has_translation(language_nl)118    def test_get_translations(self, languages):119        """Test `get_translations()`."""120        nl = languages.get(code='nl')121        fr = languages.get(code='fr')122        nl_root = self.canonical_page.create_translation(language=nl, copy_fields=True)123        fr_root = self.canonical_page.create_translation(language=fr, copy_fields=True)124        # Change title125        fr_root.title = 'FR language'126        fr_root.save()127        # Let's only make nl_root live128        nl_root.title = 'NL language'129        nl_root.live = True130        nl_root.save()131        en_translations = self.canonical_page.get_translations(only_live=False).specific()132        assert nl_root in en_translations133        assert fr_root in en_translations134        assert self.canonical_page not in en_translations135        nl_translations = nl_root.get_translations(only_live=False).specific()136        assert self.canonical_page in nl_translations137        assert fr_root in nl_translations138        assert nl_root not in nl_translations139        fr_translations = fr_root.get_translations(only_live=False).specific()140        assert self.canonical_page in fr_translations141        assert nl_root in fr_translations142        assert fr_root not in fr_translations143        # Some variations144        en_translations = self.canonical_page.get_translations().specific()145        assert nl_root in en_translations146        assert fr_root not in en_translations147        assert self.canonical_page not in en_translations148        # Test include self149        translations_and_self = self.canonical_page.get_translations(include_self=True).specific()150        assert self.canonical_page in translations_and_self151        assert nl_root in translations_and_self152        assert fr_root not in translations_and_self153        translations_and_self = self.canonical_page.get_translations(only_live=False, include_self=True).specific()154        assert self.canonical_page in translations_and_self155        assert nl_root in translations_and_self156        assert fr_root in translations_and_self157    def test_move_translated_pages(self, languages):158        """Test `move_translated_pages()`."""159        en = languages.get(code='en')160        nl = languages.get(code='nl')161        # Let's first create the following structure162        #163        #    canonical_page164        #         |- subpage1165        #         |        |- leaf_page166        #         |- subpage2167        #    nl_root168        #         |- subpage1169        #         |        |- leaf_page170        #         |- subpage2171        nl_root = self.canonical_page.create_translation(language=nl, copy_fields=True)172        subpage1 = TranslatablePageFactory.build(language=en, title='subpage1 in EN tree')173        subpage2 = TranslatablePageFactory.build(language=en, title='subpage2 in EN tree')174        leaf_page = TranslatablePageFactory.build(language=en, title='leafpage in EN tree')175        self.canonical_page.add_child(instance=subpage1)176        self.canonical_page.add_child(instance=subpage2)177        subpage1.add_child(instance=leaf_page)178        nl_subpage1 = TranslatablePageFactory.build(language=nl, title='subpage1 in NL tree', canonical_page=subpage1)179        nl_subpage2 = TranslatablePageFactory.build(language=nl, title='subpage2 in NL tree', canonical_page=subpage2)180        nl_leaf_page = TranslatablePageFactory.build(181            language=nl, title='leafpage in NL tree', canonical_page=leaf_page)182        nl_root.add_child(instance=nl_subpage1)183        nl_root.add_child(instance=nl_subpage2)184        nl_subpage1.add_child(instance=nl_leaf_page)185        # Sanitiy checks186        assert len(subpage1.get_children()) == 1187        assert len(subpage2.get_children()) == 0188        assert len(nl_subpage1.get_children()) == 1189        assert len(nl_subpage2.get_children()) == 0190        def _refresh():191            subpage1.refresh_from_db()192            subpage2.refresh_from_db()193            leaf_page.refresh_from_db()194            nl_subpage1.refresh_from_db()195            nl_subpage2.refresh_from_db()196            nl_leaf_page.refresh_from_db()197        # Let's now move the leave page from subpage1 to subpage2198        # and see if the translated pages will follow199        with override_settings(WAGTAILTRANS_SYNC_TREE=False):200            leaf_page.move(subpage2, pos='last-child')201        _refresh()202        assert len(subpage1.get_children()) == 0203        assert len(subpage2.get_children()) == 1204        assert len(nl_subpage1.get_children()) == 1205        assert len(nl_subpage2.get_children()) == 0206        leaf_page.move_translated_pages(subpage2, pos='last-child')207        _refresh()208        assert len(subpage1.get_children()) == 0209        assert len(subpage2.get_children()) == 1210        assert len(nl_subpage1.get_children()) == 0211        assert len(nl_subpage2.get_children()) == 1212        # Test vice-versa, and now by just calling `move`.213        # That should trigger move_translated_pages for us214        nl_leaf_page.move(nl_subpage1, pos='last-child')215        _refresh()216        assert len(subpage1.get_children()) == 1217        assert len(subpage2.get_children()) == 0218        assert len(nl_subpage1.get_children()) == 1219        assert len(nl_subpage2.get_children()) == 0220@pytest.mark.django_db221class TestTranslatableSiteRootPage:222    def setup(self):223        self.site_root = models.TranslatableSiteRootPage(title='site root')224    def test_create(self):225        assert self.site_root226    def test_page_permission_for_user(self):227        user = UserFactory(is_superuser=True, username='admin')228        perms = self.site_root.permissions_for_user(user)229        assert perms.can_publish()230        another_user = UserFactory(username='editor')231        perms = self.site_root.permissions_for_user(another_user)232        assert not perms.can_publish()233    def test_serve(self,rf):234        site = SiteFactory()235        request = rf.get('/home/')236        response = site.root_page.serve(request)237        assert response.status_code == 200238    def test_get_user_language(self, rf):239        request = rf.get('/en/')240        sitelanguages = SiteLanguagesFactory(default_language__code='fr')241        lang = models.get_user_language(request)242        assert lang.code == 'en'243        with override_settings(WAGTAILTRANS_LANGUAGES_PER_SITE=True):244            lang = models.get_user_language(request)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
