def setUp(self): testuser = User.objects.get(username='******') token = Token.objects.get(user=testuser) self.client = APIClient() self.client.credentials(HTTP_AUTHORIZATION='Token ' + token.key) self.url = reverse(self.viewname + '-list') self.current_findings = self.client.get(self.url, format='json').data["results"] finding = Finding.objects.get(id=self.current_findings[0]['id']) self.base_url = f"{self.url}{self.current_findings[0]['id']}/metadata/" metadata = DojoMeta(finding=finding, name="test_meta", value="20") metadata.save()
def handle(self, *args, **options): ctp = ContentType.objects.get_for_model(Product.objects.all()[0]) cte = ContentType.objects.get_for_model(Endpoint.objects.all()[0]) legacy_meta_prod = CustomField.objects.filter(content_type=ctp) legacy_meta_ep = CustomField.objects.filter(content_type=cte) for cf in legacy_meta_prod: cfv = CustomFieldValue.objects.filter(field=cf, ) dm = DojoMeta(name=cf.name, value=cfv.first().value, model_name='Product', model_id=cfv.first().object_id) dm.save() for cf in legacy_meta_ep: cfv = CustomFieldValue.objects.filter(field=cf, ) dm = DojoMeta(name=cf.name, value=cfv.first().value, model_name='Endpoint', model_id=cfv.first().object_id) dm.save()