def setUpTestData(cls):
        cls.Oplog = OplogFactory._meta.model
        cls.OplogEntry = OplogEntryFactory._meta.model

        cls.oplog = OplogFactory()
        OplogEntryFactory.create_batch(5, oplog_id=cls.oplog)

        cls.user = UserFactory(password=PASSWORD)
        cls.uri = reverse("oplog:oplog_entries", kwargs={"pk": cls.oplog.id})
    def setUpTestData(cls):
        cls.Oplog = OplogFactory._meta.model
        cls.OplogEntry = OplogEntryFactory._meta.model

        cls.oplog = OplogFactory()
        cls.num_of_entries = 5
        for x in range(cls.num_of_entries):
            OplogEntryFactory(oplog_id=cls.oplog)

        cls.user = UserFactory(password=PASSWORD)
        cls.uri = reverse("oplog:oplog_import")
        cls.redirect_uri = reverse("oplog:oplog_entries",
                                   kwargs={"pk": cls.oplog.pk})
        cls.failure_redirect_uri = reverse("oplog:oplog_import")
    def test_crud_finding(self):
        # Create
        entry = OplogEntryFactory(tool="Rubeus.exe")

        # Read
        self.assertEqual(entry.tool, "Rubeus.exe")
        self.assertEqual(entry.pk, entry.id)

        # Update
        entry.tool = "Seatbelt.exe"
        entry.save()
        self.assertEqual(entry.tool, "Seatbelt.exe")

        # Delete
        entry.delete()
        assert not self.OplogEntry.objects.all().exists()
    def test_invalid_dates(self):
        valid_start_date = datetime.now(pytz.UTC)
        valid_end_date = datetime.now(pytz.UTC)
        invalid_start_date = "2021-09-14 14:09"
        invalid_end_date = "Totally a Date"

        # Create new entry with valid dates
        entry = OplogEntryFactory(start_date=valid_start_date,
                                  end_date=valid_end_date)

        # Try invalid start date
        entry.start_date = invalid_start_date
        entry.save()
        entry.refresh_from_db()
        self.assertEqual(entry.start_date, valid_start_date)

        # Try invalid end date
        entry.end_date = invalid_end_date
        entry.save()
        entry.refresh_from_db()
        self.assertEqual(entry.end_date, valid_end_date)
 def test_pre_save_signal(self):
     entry = OplogEntryFactory(start_date=None, end_date=None)
     entry.tool = "Rubeus.exe"
     entry.save()
     self.assertIsInstance(entry.start_date, datetime)
     self.assertIsInstance(entry.end_date, datetime)
 def test_valid_data(self):
     entry = OplogEntryFactory.build()
     form = self.form_data(**entry.__dict__, oplog_id=self.oplog.id)
     self.assertTrue(form.is_valid())