def test_expired_domain(self): checkout = HistoryFactory(client=self.project.client, project=self.project, domain=self.expired_domain) form = self.form_data(**checkout.__dict__) errors = form["domain"].errors.as_data() self.assertEqual(len(errors), 1) self.assertEqual(errors[0].code, "expired")
def test_unavailable_domain(self): checkout = HistoryFactory( client=self.project.client, project=self.project, domain=self.unavailable_domain, ) form = self.form_data(**checkout.__dict__) errors = form["domain"].errors.as_data() self.assertEqual(len(errors), 1) self.assertEqual(errors[0].code, "unavailable")
def setUpTestData(cls): cls.project = ProjectFactory() cls.domain = HistoryFactory(project=cls.project) cls.server = ServerHistoryFactory(project=cls.project) cls.vps = TransientServerFactory(project=cls.project) cls.link = DomainServerConnectionFactory( project=cls.project, domain=cls.domain, static_server=cls.server, transient_server=None, ) cls.link_dict = cls.link.__dict__
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!" )
def test_invalid_dates(self): end_date = date.today() start_date = date.today() + timedelta(days=20) checkout = HistoryFactory( client=self.project.client, project=self.project, domain=self.domain, start_date=start_date, end_date=end_date, ) form = self.form_data(**checkout.__dict__) errors = form["end_date"].errors.as_data() self.assertEqual(len(errors), 1) self.assertEqual(errors[0].code, "invalid")
def test_method_will_be_released(self): start_date = date.today() - timedelta(days=20) end_date = date.today() + timedelta(days=7) domain = HistoryFactory(start_date=start_date, end_date=end_date) try: self.assertEqual(False, domain.will_be_released()) domain.end_date = date.today() domain.save() self.assertEqual(True, domain.will_be_released()) except Exception: self.fail( "History model `will_be_released` method failed unexpectedly!")
def test_checkout_adjustment_signal(self): yesterday = date.today() - timedelta(days=1) project = ProjectFactory( start_date=date.today() - timedelta(days=14), end_date=date.today() + timedelta(days=14), ) domain_checkout = HistoryFactory(start_date=project.start_date, end_date=project.end_date, project=project) exp_domain_checkout = HistoryFactory(start_date=project.start_date, end_date=yesterday, project=project) server_checkout = ServerHistoryFactory(start_date=project.start_date, end_date=project.end_date, project=project) exp_server_checkout = ServerHistoryFactory( start_date=project.start_date, end_date=yesterday, project=project) new_start = project.start_date - timedelta(days=7) new_end = project.end_date + timedelta(days=7) project.start_date = new_start project.end_date = new_end project.save() domain_checkout.refresh_from_db() exp_domain_checkout.refresh_from_db() server_checkout.refresh_from_db() exp_server_checkout.refresh_from_db() self.assertEqual(domain_checkout.start_date, new_start) self.assertEqual(server_checkout.start_date, new_start) self.assertEqual(domain_checkout.end_date, new_end) self.assertEqual(server_checkout.end_date, new_end) self.assertEqual(exp_domain_checkout.end_date, yesterday) self.assertEqual(exp_server_checkout.end_date, yesterday)
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()
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)
def test_valid_data(self): checkout = HistoryFactory(client=self.project.client, project=self.project, domain=self.domain) form = self.form_data(**checkout.__dict__) self.assertTrue(form.is_valid())
def test_get_absolute_url(self): checkout = HistoryFactory() try: checkout.get_absolute_url() except: self.fail("History.get_absolute_url() raised an exception")