示例#1
0
    def test_method_get_list(self):
        domain = DomainFactory()

        try:
            domain.get_list()
        except Exception:
            self.fail("Domain model `get_list` method failed unexpectedly!")
示例#2
0
 def setUpTestData(cls):
     cls.unavailable_status = DomainStatusFactory(domain_status="Unavailable")
     cls.domain = DomainFactory(expiration=date.today() + timedelta(days=360))
     cls.unavailable_domain = DomainFactory(
         domain_status=cls.unavailable_status,
         expiration=date.today() + timedelta(days=360),
     )
     cls.expired_domain = DomainFactory(expiration=date.today() - timedelta(days=30))
     cls.project = ProjectFactory()
示例#3
0
    def test_prop_count_status(self):
        status = DomainStatusFactory(domain_status="Available")
        DomainFactory(domain_status=status)

        try:
            count = status.count
            self.assertEqual(count, 1)
        except Exception:
            self.fail(
                "DomainStatus model `count` property failed unexpectedly!")
示例#4
0
    def test_prop_count_status(self):
        status = HealthStatusFactory(health_status="Healthy")
        DomainFactory(health_status=status)

        try:
            count = status.count
            self.assertEqual(count, 1)
        except Exception:
            self.fail(
                "HealthStatus model `count` property failed unexpectedly!")
示例#5
0
    def test_prop_count_status(self):
        status = WhoisStatusFactory(whois_status="Enabled")
        domain = DomainFactory(whois_status=status)

        try:
            count = status.count
            self.assertEqual(count, 1)
        except Exception:
            self.fail(
                "WhoisStatus model `count` property failed unexpectedly!")
示例#6
0
    def test_valid_data(self):
        start_date = date.today()
        end_date = date.today() + timedelta(days=360)
        domain = DomainFactory()
        domain_dict = domain.__dict__
        domain_dict["name"] = "soemthing.new"
        domain_dict["creation"] = start_date
        domain_dict["expiration"] = end_date

        form = self.form_data(**domain_dict)
        self.assertTrue(form.is_valid())
示例#7
0
    def test_invalid_dates(self):
        end_date = date.today()
        start_date = date.today() + timedelta(days=360)
        domain = DomainFactory()
        domain_dict = domain.__dict__
        domain_dict["name"] = "soemthing.new"
        domain_dict["creation"] = start_date
        domain_dict["expiration"] = end_date

        form = self.form_data(**domain.__dict__)
        errors = form.errors.as_data()
        self.assertEqual(len(errors), 1)
        self.assertEqual(errors["__all__"][0].code, "invalid_date")
示例#8
0
    def test_property_domain_name(self):
        entry = DomainServerConnectionFactory(domain=HistoryFactory(
            domain=DomainFactory(name="ghostwriter.wiki")))

        try:
            self.assertEqual(entry.domain_name, "ghostwriter.wiki")
            entry.domain.domain.name = "getghostwriter.io"
            entry.domain.domain.save()
            self.assertEqual(entry.domain_name, "getghostwriter.io")
        except Exception:
            self.fail(
                "DomainServerConnection model `domain_name` property failed unexpectedly!"
            )
示例#9
0
    def test_crud(self):
        # Create
        entry = HistoryFactory(domain=DomainFactory(name="ghostwriter.wiki"))

        # Read
        self.assertEqual(entry.domain.name, "ghostwriter.wiki")
        self.assertEqual(entry.pk, entry.id)
        self.assertQuerysetEqual(
            self.History.objects.all(),
            [f"<History: {entry.project} : {entry.domain.name}>"],
        )

        # Update
        entry.end_date = date.today()
        entry.save()
        self.assertEqual(entry.end_date, date.today())

        # Delete
        entry.delete()
        assert not self.History.objects.all().exists()
示例#10
0
    def test_crud(self):
        # Create
        domain = DomainFactory(name="ghostwriter.wiki")

        # Read
        self.assertEqual(domain.name, "ghostwriter.wiki")
        self.assertEqual(domain.pk, domain.id)
        self.assertQuerysetEqual(
            self.Domain.objects.all(),
            [f"<Domain: {domain.name} ({domain.health_status})>"],
        )

        # Update
        domain.name = "SpecterOps. io"
        domain.save()
        self.assertEqual(domain.name, "specterops.io")

        # Delete
        domain.delete()
        assert not self.Domain.objects.all().exists()
示例#11
0
    def test_method_get_domain_age(self):
        creation = date.today() - timedelta(days=360)
        renewed = date.today() + timedelta(days=359)
        domain = DomainFactory(creation=creation,
                               expiration=renewed,
                               expired=False)

        expired = date.today() - timedelta(days=1)
        expired_domain = DomainFactory(creation=creation,
                                       expiration=expired,
                                       expired=True,
                                       auto_renew=False)

        try:
            age = domain.get_domain_age()
            self.assertEqual(age, "360 days")

            age = expired_domain.get_domain_age()
            self.assertEqual(age, "359 days")
        except Exception:
            self.fail(
                "Domain model `get_domain_age` method failed unexpectedly!")
示例#12
0
    def test_delete_signal(self):
        domain = DomainFactory(domain_status=self.unavailable_status)

        today = date.today()
        tomorrow = today + timedelta(days=1)
        next_week = today + timedelta(days=7)
        two_weeks = today + timedelta(days=14)

        history_1 = HistoryFactory(start_date=today,
                                   end_date=tomorrow,
                                   domain=domain)
        history_2 = HistoryFactory(start_date=next_week,
                                   end_date=two_weeks,
                                   domain=domain)

        # Deleting this older checkout should not impact the domain's status
        history_1.delete()
        domain.refresh_from_db()
        self.assertTrue(domain.domain_status == self.unavailable_status)

        # Deleting this newer checkout should impact the domain's status
        history_2.delete()
        domain.refresh_from_db()
        self.assertTrue(domain.domain_status == self.available_status)
示例#13
0
 def setUpTestData(cls):
     cls.domain = DomainFactory()
     cls.domain_dict = cls.domain.__dict__
示例#14
0
    def test_method_is_expiring_soon(self):
        creation = date.today() - timedelta(days=345)
        expiration = date.today() + timedelta(days=15)
        domain = DomainFactory(creation=creation,
                               expiration=expiration,
                               auto_renew=False)

        try:
            self.assertEqual(True, domain.is_expiring_soon())

            domain.auto_renew = True
            domain.save()
            self.assertEqual(False, domain.is_expiring_soon())

            domain.expiration = date.today() + timedelta(days=31)
            domain.save()
            self.assertEqual(False, domain.is_expiring_soon())
        except Exception:
            self.fail(
                "Domain model `is_expiring_soon` method failed unexpectedly!")
示例#15
0
 def test_get_absolute_url(self):
     domain = DomainFactory()
     try:
         domain.get_absolute_url()
     except:
         self.fail("Domain.get_absolute_url() raised an exception")