Esempio n. 1
0
 def test_download_eval_file(self):
     WHOIS.get_registrar_certification_list.return_value = self._get_registrar_certs(
     )
     FILE_MANAGER.info.return_value = FileInfo(
         id=2,
         name='test.html',
         path='2015/12/9/1',
         mimetype='text/html',
         filetype=6,
         crdate='2015-12-09 16:16:28.598757',
         size=5)
     content = "<html><body>The content.</body></html>"
     FILE_MANAGER.load.return_value.download.return_value = content
     response = self.client.get(
         reverse("webwhois:download_evaluation_file",
                 kwargs={"handle": "REG-MOJEID"}))
     self.assertEqual(response.content, content.encode())
     self.assertEqual(response['Content-Type'], 'text/html')
     self.assertEqual(response['Content-Disposition'],
                      'attachment; filename="test.html"')
     self.assertEqual(WHOIS.mock_calls,
                      [call.get_registrar_certification_list()])
     self.assertEqual(FILE_MANAGER.mock_calls, [
         call.info(2),
         call.load(2),
         call.load().download(5),
         call.load().finalize_download()
     ])
Esempio n. 2
0
 def test_download_not_found(self):
     WHOIS.get_registrar_certification_list.return_value = self._get_registrar_certs(
     )
     response = self.client.get(
         reverse("webwhois:download_evaluation_file",
                 kwargs={"handle": "REG-MISSING"}))
     self.assertIsInstance(response, HttpResponseNotFound)
     self.assertEqual(WHOIS.mock_calls,
                      [call.get_registrar_certification_list()])
     self.assertEqual(FILE_MANAGER.mock_calls, [])
Esempio n. 3
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()
        ])
Esempio n. 4
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()
        ])
Esempio n. 5
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()
        ])
Esempio n. 6
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()
        ])
Esempio n. 7
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()
        ])
Esempio n. 8
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()
        ])