コード例 #1
0
ファイル: test_admin.py プロジェクト: netsec-ethz/scionlab
    def test_edit_link(self):
        ases = AS.objects.iterator()
        as_a = next(ases)
        as_b = next(ases)
        link = Link.objects.create_from_ases(Link.PROVIDER, as_a, as_b)

        form_data = dict(
            type=Link.PROVIDER,
            active=True,
            mtu=2345,
            from_host=as_a.hosts.first().pk,
            to_host=as_b.hosts.first().pk,
            from_public_ip='192.0.2.1',
            from_public_port=50000,
            to_public_ip='192.0.2.2',
            to_public_port=50001,
        )
        form = LinkAdminForm(instance=link, data=form_data)
        self.assertTrue(form.is_valid(), form.errors.as_data())
        link = form.save()
        self.assertIsNotNone(link)
        self.assertEqual(link.type, Link.PROVIDER)
        self.assertEqual(link.active, True)
        self.assertEqual(link.mtu, 2345)
        self.assertEqual(link.interfaceA.public_ip, '192.0.2.1')
        self.assertEqual(link.interfaceA.public_port, 50000)
        self.assertEqual(link.interfaceB.public_ip, '192.0.2.2')
        self.assertEqual(link.interfaceB.public_port, 50001)

        # Re-creating form with same data should result in no changes:
        edit_form = LinkAdminForm(instance=link, data=form_data)
        self.assertTrue(edit_form.is_valid(), edit_form.errors)
        self.assertFalse(edit_form.has_changed(), edit_form.changed_data)
コード例 #2
0
ファイル: test_admin.py プロジェクト: netsec-ethz/scionlab
    def test_create_link(self):
        ases = AS.objects.iterator()
        as_a = next(ases)
        as_b = next(ases)
        form_data = dict(
            type=Link.PROVIDER,
            active=True,
            mtu=2345,
            from_host=as_a.hosts.first().pk,
            from_public_port=50000,
            to_host=as_b.hosts.first().pk,
            to_public_port=50000,
        )
        form = LinkAdminForm(data=form_data)
        self.assertTrue(form.is_valid(), form.errors.as_data())
        link = form.save()
        self.assertIsNotNone(link)

        # Re-creating form with same data should result in no changes:
        edit_form = LinkAdminForm(instance=link, data=form_data)
        self.assertTrue(edit_form.is_valid(), edit_form.errors)
        self.assertFalse(edit_form.has_changed(), edit_form.changed_data)