Skip to content

Commit

Permalink
Add migration file
Browse files Browse the repository at this point in the history
Fix docs
Add a test for Reputation model

Signed-off-by: ziadhany <[email protected]>
  • Loading branch information
ziadhany committed Jan 30, 2024
1 parent 833a91f commit 4fe2bb8
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 55 deletions.
12 changes: 8 additions & 4 deletions docs/source/contribute/vocabulary.rst
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
.. _vocabulary:

FederatedCode Vocabulary
============
=========================
FederatedCode Vocabulary’s intended to be an extension of
`Activity Vocabulary <https://www.w3.org/TR/activitystreams-vocabulary/>`__.

Expand Down Expand Up @@ -57,6 +57,7 @@ Service
"type": "Service",
"name": "vcio"
}
Activity
********

Expand Down Expand Up @@ -88,6 +89,7 @@ Create
"url": "https://github.com/nexB/vulnerablecode-data",
},
}
Update
-------
.. code-block:: JSON
Expand All @@ -102,6 +104,7 @@ Update
"content": "Hello World!",
},
}
Delete
-------
.. code-block:: JSON
Expand Down Expand Up @@ -144,6 +147,7 @@ Sync
"id": "https://127.0.0.1:8000/repository/3701d4b6-a7cf-41ee-9144-35f9d70afe0b/",
},
}
Objects
********

Expand Down Expand Up @@ -201,7 +205,7 @@ Review
"updated": "2015-02-10T15:04:55Z",
}
Repository
-----------
------------
.. code-block:: JSON
{
Expand All @@ -211,7 +215,7 @@ Repository
}
Vulnerability
-------------
---------------
.. code-block:: JSON
{
Expand All @@ -238,7 +242,7 @@ Like
}
Dislike
------
--------
.. code-block:: JSON
{
Expand Down
82 changes: 41 additions & 41 deletions fedcode/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.0.1 on 2024-01-30 02:51
# Generated by Django 5.0.1 on 2024-01-30 13:50

import django.db.models.deletion
import uuid
Expand Down Expand Up @@ -146,28 +146,35 @@ class Migration(migrations.Migration):
},
),
migrations.CreateModel(
name="Person",
name="Package",
fields=[
("summary", models.CharField(help_text="profile summary", max_length=100)),
("public_key", models.TextField()),
("local", models.BooleanField(default=True)),
(
"id",
models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
models.UUIDField(
default=uuid.uuid4,
editable=False,
help_text="The object's unique global identifier",
primary_key=True,
serialize=False,
),
),
("summary", models.CharField(help_text="profile summary", max_length=100)),
("public_key", models.TextField()),
("local", models.BooleanField(default=True)),
(
"avatar",
models.ImageField(default="favicon-16x16.png", null=True, upload_to="uploads/"),
"purl",
models.CharField(
help_text="PURL (no version) ex: @pkg:maven/org.apache.logging",
max_length=300,
unique=True,
),
),
("notes", models.ManyToManyField(blank=True, to="fedcode.note")),
(
"user",
models.OneToOneField(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
"notes",
models.ManyToManyField(
blank=True,
help_text="the notes that this purl created ex:\n purl: pkg:.../.../\n affected_by_vulnerabilities: []\n fixing_vulnerabilities: []\n ",
to="fedcode.note",
),
),
(
Expand All @@ -185,35 +192,28 @@ class Migration(migrations.Migration):
},
),
migrations.CreateModel(
name="Purl",
name="Person",
fields=[
("summary", models.CharField(help_text="profile summary", max_length=100)),
("public_key", models.TextField()),
("local", models.BooleanField(default=True)),
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
help_text="The object's unique global identifier",
primary_key=True,
serialize=False,
models.BigAutoField(
auto_created=True, primary_key=True, serialize=False, verbose_name="ID"
),
),
("summary", models.CharField(help_text="profile summary", max_length=100)),
("public_key", models.TextField()),
("local", models.BooleanField(default=True)),
(
"string",
models.CharField(
help_text="PURL (no version) ex: @pkg:maven/org.apache.logging",
max_length=300,
unique=True,
),
"avatar",
models.ImageField(default="favicon-16x16.png", null=True, upload_to="uploads/"),
),
("notes", models.ManyToManyField(blank=True, to="fedcode.note")),
(
"notes",
models.ManyToManyField(
blank=True,
help_text="the notes that this purl created ex:\n purl: pkg:.../.../\n affected_by_vulnerabilities: []\n fixing_vulnerabilities: []\n ",
to="fedcode.note",
"user",
models.OneToOneField(
null=True,
on_delete=django.db.models.deletion.CASCADE,
to=settings.AUTH_USER_MODEL,
),
),
(
Expand Down Expand Up @@ -242,15 +242,15 @@ class Migration(migrations.Migration):
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"person",
"package",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="fedcode.person"
on_delete=django.db.models.deletion.CASCADE, to="fedcode.package"
),
),
(
"purl",
"person",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="fedcode.purl"
on_delete=django.db.models.deletion.CASCADE, to="fedcode.person"
),
),
],
Expand Down Expand Up @@ -371,7 +371,7 @@ class Migration(migrations.Migration):
),
),
migrations.AddField(
model_name="purl",
model_name="package",
name="service",
field=models.ForeignKey(
blank=True,
Expand Down
18 changes: 9 additions & 9 deletions federatedcode/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ def sync_task():
sync_r.save()



def send_fed_req_task():
"""
send_fed_req_task is a task to send the http signed request to the target and save the status of the request
"""
for rq in FederateRequest.objects.all().order_by('created_at'):
try:
HttpSignature.signed_request(rq.target, rq.body, FEDERATED_CODE_PRIVATE_KEY, rq.key_id)
rq.done = True
rq.save()
except Exception as e:
rq.error_message = e
finally:
rq.save()
if not rq.done:
try:
HttpSignature.signed_request(rq.target, rq.body, FEDERATED_CODE_PRIVATE_KEY, rq.key_id)
rq.done = True
rq.save()
except Exception as e:
rq.error_message = e
finally:
rq.save()
16 changes: 16 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from fedcode.models import Person
from fedcode.models import RemoteActor
from fedcode.models import Repository
from fedcode.models import Reputation
from fedcode.models import Review
from fedcode.models import Service
from fedcode.models import Vulnerability
Expand Down Expand Up @@ -125,6 +126,15 @@ def follow(db, package, person):
return Follow.objects.create(package=package, person=person)


@pytest.fixture
def rep(db, note):
return Reputation.objects.create(
voter="ziad@vcio",
positive=True,
content_object=note,
)


def test_follow(follow, package, person):
assert follow.package.purl == package.purl
assert follow.person.user == person.user
Expand All @@ -140,6 +150,12 @@ def test_review(review, person, repo):
assert review.commit == "49d8c5fd4bea9488186a832b13ebdc83484f1b6a"


def test_reputation(rep, note):
assert rep.voter == "ziad@vcio"
assert rep.positive is True
assert rep.content_object == note


def test_vulnerability(vulnerability, repo):
assert vulnerability.repo == repo
assert vulnerability.filename == "VCID-rf6e-vjeu-aaae"
Expand Down
14 changes: 13 additions & 1 deletion tests/test_vocabulary_toap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .test_models import note
from .test_models import package
from .test_models import person
from .test_models import rep
from .test_models import repo
from .test_models import review
from .test_models import service
Expand Down Expand Up @@ -48,7 +49,7 @@ def test_actors_to_ap(person, package, service):


@pytest.mark.django_db
def test_objects_to_ap(repo, review, vulnerability, note, mute_post_save_signal):
def test_objects_to_ap(repo, review, vulnerability, note, rep, mute_post_save_signal):
assert repo.to_ap == {
"id": f"https://127.0.0.1:8000/repository/{repo.id}/",
"type": "Repository",
Expand Down Expand Up @@ -81,3 +82,14 @@ def test_objects_to_ap(repo, review, vulnerability, note, mute_post_save_signal)
"author": note.acct,
"content": note.content,
}

assert rep.to_ap == {
"type": "Like",
"actor": "ziad@vcio",
"object": {
"type": "Note",
"id": f"https://127.0.0.1:8000/notes/{note.id}",
"author": note.acct,
"content": note.content,
},
}

0 comments on commit 4fe2bb8

Please sign in to comment.