示例#1
0
    def test_registrars_group_unknown(self):
        # Test filter using the unknown group
        WHOIS.get_registrars.return_value = [make_registrar()]
        WHOIS.get_registrar_groups.return_value = []
        WHOIS.get_registrar_certification_list.return_value = []

        response = self.client.get(reverse('registrars_red_dwarf'))

        self.assertContains(response, "Not Found", status_code=404)
        self.assertEqual(WHOIS.mock_calls,
                         [call.get_registrars(),
                          call.get_registrar_groups()])
示例#2
0
    def test_registrars_group(self):
        WHOIS.get_registrars.return_value = [
            make_registrar(handle='HOLLY'),
            make_registrar(handle='GORDON')
        ]
        WHOIS.get_registrar_groups.return_value = [
            RegistrarGroup(name='red_dwarf', members=['HOLLY'])
        ]
        WHOIS.get_registrar_certification_list.return_value = []

        response = self.client.get(reverse('registrars_red_dwarf'))

        self.assertContains(response, "List of registrars")
        self.assertIsNone(response.context['is_retail'])
        self.assertEqual(len(response.context['registrars']), 1)
        self.assertEqual(response.context['registrars'][0]['registrar'].handle,
                         'HOLLY')
        self.assertEqual(WHOIS.mock_calls, [
            call.get_registrars(),
            call.get_registrar_groups(),
            call.get_registrar_certification_list()
        ])
示例#3
0
    def test_registrars_sorting(self):
        holly = make_registrar(handle='HOLLY')
        queeg = make_registrar(handle='QUEEG')
        gordon = make_registrar(handle='GORDON')
        WHOIS.get_registrars.return_value = [holly, queeg, gordon]
        WHOIS.get_registrar_groups.return_value = []
        WHOIS.get_registrar_certification_list.return_value = [
            RegistrarCertification('HOLLY', 1, None),
            RegistrarCertification('QUEEG', 2, None),
            RegistrarCertification('GORDON', 5, None)
        ]

        response = self.client.get(reverse('webwhois:registrars'))

        self.assertContains(response, "List of registrars")
        self.assertEqual(
            [r['registrar'] for r in response.context['registrars']],
            [gordon, queeg, holly])
        self.assertEqual(WHOIS.mock_calls, [
            call.get_registrars(),
            call.get_registrar_certification_list(),
            call.get_registrar_groups()
        ])
示例#4
0
    def test_registrars_shuffle(self):
        holly = make_registrar(handle='HOLLY')
        queeg = make_registrar(handle='QUEEG')
        gordon = make_registrar(handle='GORDON')
        WHOIS.get_registrars.return_value = [holly, queeg, gordon]
        WHOIS.get_registrar_groups.return_value = []
        WHOIS.get_registrar_certification_list.return_value = []

        def _test_shuffle(registrars):
            registrars.sort(key=lambda row: row['registrar'].handle)

        with patch("webwhois.views.registrar.random.SystemRandom.shuffle",
                   side_effect=_test_shuffle):
            response = self.client.get(reverse('webwhois:registrars'))

        self.assertContains(response, "List of registrars")
        self.assertEqual(
            [r['registrar'] for r in response.context['registrars']],
            [gordon, holly, queeg])
        self.assertEqual(WHOIS.mock_calls, [
            call.get_registrars(),
            call.get_registrar_certification_list(),
            call.get_registrar_groups()
        ])
示例#5
0
    def test_registrars(self):
        registrar = make_registrar()
        WHOIS.get_registrars.return_value = [registrar]
        WHOIS.get_registrar_groups.return_value = []
        WHOIS.get_registrar_certification_list.return_value = []

        response = self.client.get(reverse('webwhois:registrars'))

        self.assertContains(response, "List of registrars")
        self.assertIsNone(response.context['is_retail'])
        self.assertEqual(len(response.context['registrars']), 1)
        self.assertEqual(response.context['registrars'][0]['registrar'],
                         registrar)
        self.assertEqual(WHOIS.mock_calls, [
            call.get_registrars(),
            call.get_registrar_certification_list(),
            call.get_registrar_groups()
        ])
示例#6
0
    def test_registrars_certification_context(self):
        WHOIS.get_registrars.return_value = [make_registrar('HOLLY')]
        WHOIS.get_registrar_groups.return_value = []
        certification = RegistrarCertification('HOLLY', 3, None)
        WHOIS.get_registrar_certification_list.return_value = [certification]

        response = self.client.get(reverse('webwhois:registrars'))

        self.assertContains(response, "List of registrars")
        self.assertEqual(len(response.context['registrars']), 1)
        self.assertEqual(response.context['registrars'][0]['cert'],
                         certification)
        self.assertEqual(response.context['registrars'][0]['score'], 3)
        self.assertEqual(response.context['registrars'][0]['stars'], range(3))
        self.assertEqual(WHOIS.mock_calls, [
            call.get_registrars(),
            call.get_registrar_certification_list(),
            call.get_registrar_groups()
        ])
示例#7
0
    def test_registrars_old_context(self):
        # Test deprecated `_registrar_row` works correctly
        registrar = make_registrar()
        WHOIS.get_registrars.return_value = [registrar]
        WHOIS.get_registrar_groups.return_value = []
        WHOIS.get_registrar_certification_list.return_value = []

        warn_msg = (
            "Method 'RegistrarListView._registrar_row' is deprecated in favor of "
            "'RegistrarListView.get_registrar_context'.")
        with ShouldWarn(DeprecationWarning(warn_msg)):
            warnings.simplefilter('always')
            response = self.client.get(reverse('registrars_custom'))

        self.assertContains(response, "List of registrars")
        self.assertEqual(len(response.context['registrars']), 1)
        self.assertTrue(response.context['registrars'][0]['custom'])
        self.assertEqual(WHOIS.mock_calls, [
            call.get_registrars(),
            call.get_registrar_certification_list(),
            call.get_registrar_groups()
        ])