Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,16 @@ _____
This code has been copied over so it is easier to review the Python API
implementation in development.
* Make code into an installable package.

[1.2.0] - 2021-01-25
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Added
_____

* Adds API unit tests to improve test coverage.

Changed
_______

* Updates the Python API to use the models directly.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ static: ## Collect static files
${VENV_BIN}/python manage.py collectstatic --noinput

test: clean ## Run tests and generate coverage report
${VENV_BIN}/coverage run ./manage.py test blockstore --settings=blockstore.settings.test
${VENV_BIN}/coverage run ${VENV_BIN}/pytest blockstore --ds=blockstore.settings.test
${VENV_BIN}/coverage html
${VENV_BIN}/coverage xml
${VENV_BIN}/diff-cover coverage.xml --html-report diff-cover.html --compare-branch origin/master
${VENV_BIN}/diff-cover coverage.xml --html-report diff-cover.html --compare-branch=origin/master

easyserver: dev.up dev.provision # Start and provision a Blockstore container and run the server until CTRL-C, then stop it
# Now run blockstore until the user hits CTRL-C:
Expand Down
2 changes: 1 addition & 1 deletion blockstore/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
Blockstore is a system for storing educational content.
"""

__version__ = '1.1.0'
__version__ = '1.2.0'
21 changes: 12 additions & 9 deletions blockstore/apps/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@
openedx.core.djangolib.blockstore_cache) together with these API methods for
improved performance.
"""
from .models import (
Collection,
Bundle,
Draft,
BundleFile,
DraftFile,
LinkReference,
LinkDetails,
DraftLinkDetails,
from .data import (
CollectionData,
BundleData,
BundleVersionData,
DraftData,
BundleFileData,
DraftFileData,
Dependency,
BundleLinkData,
DraftLinkData,
)
from .methods import (
# Collections:
Expand Down Expand Up @@ -51,7 +52,9 @@
BlockstoreException,
CollectionNotFound,
BundleNotFound,
BundleVersionNotFound,
DraftNotFound,
DraftHasNoChangesToCommit,
BundleFileNotFound,
BundleStorageError,
)
56 changes: 28 additions & 28 deletions blockstore/apps/api/models.py → blockstore/apps/api/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,24 @@

import attr


def _convert_to_uuid(value):
if not isinstance(value, UUID):
return UUID(value)
return value
from blockstore.apps.bundles.links import convert_to_uuid, Dependency


@attr.s(frozen=True)
class Collection:
class CollectionData:
"""
Metadata about a blockstore collection
"""
uuid = attr.ib(type=UUID, converter=_convert_to_uuid)
uuid = attr.ib(type=UUID, converter=convert_to_uuid)
title = attr.ib(type=str)


@attr.s(frozen=True)
class Bundle:
class BundleData:
"""
Metadata about a blockstore bundle
"""
uuid = attr.ib(type=UUID, converter=_convert_to_uuid)
uuid = attr.ib(type=UUID, converter=convert_to_uuid)
title = attr.ib(type=str)
description = attr.ib(type=str)
slug = attr.ib(type=str)
Expand All @@ -38,20 +34,34 @@ class Bundle:


@attr.s(frozen=True)
class Draft:
class DraftData:
"""
Metadata about a blockstore draft
"""
uuid = attr.ib(type=UUID, converter=_convert_to_uuid)
bundle_uuid = attr.ib(type=UUID, converter=_convert_to_uuid)
uuid = attr.ib(type=UUID, converter=convert_to_uuid)
bundle_uuid = attr.ib(type=UUID, converter=convert_to_uuid)
name = attr.ib(type=str)
created_at = attr.ib(type=datetime, validator=attr.validators.instance_of(datetime))
updated_at = attr.ib(type=datetime, validator=attr.validators.instance_of(datetime))
files = attr.ib(type=dict)
links = attr.ib(type=dict)


@attr.s(frozen=True)
class BundleFile:
class BundleVersionData:
"""
Metadata about a blockstore bundle version.
"""
bundle_uuid = attr.ib(type=UUID, converter=convert_to_uuid)
version = attr.ib(type=int, validator=attr.validators.instance_of(int))
change_description = attr.ib(type=str)
created_at = attr.ib(type=datetime, validator=attr.validators.instance_of(datetime))
files = attr.ib(type=dict)
links = attr.ib(type=dict)


@attr.s(frozen=True)
class BundleFileData:
"""
Metadata about a file in a blockstore bundle or draft.
"""
Expand All @@ -62,35 +72,25 @@ class BundleFile:


@attr.s(frozen=True)
class DraftFile(BundleFile):
class DraftFileData(BundleFileData):
"""
Metadata about a file in a blockstore draft.
"""
modified = attr.ib(type=bool) # Was this file modified in the draft?


@attr.s(frozen=True)
class LinkReference:
"""
A pointer to a specific BundleVersion
"""
bundle_uuid = attr.ib(type=UUID, converter=_convert_to_uuid)
version = attr.ib(type=int)
snapshot_digest = attr.ib(type=str)


@attr.s(frozen=True)
class LinkDetails:
class BundleLinkData:
"""
Details about a specific link in a BundleVersion or Draft
"""
name = attr.ib(type=str)
direct = attr.ib(type=LinkReference)
indirect = attr.ib(type=list) # List of LinkReference objects
direct = attr.ib(type=Dependency)
indirect = attr.ib(type=list) # List of Dependency objects


@attr.s(frozen=True)
class DraftLinkDetails(LinkDetails):
class DraftLinkData(BundleLinkData):
"""
Details about a specific link in a Draft
"""
Expand Down
8 changes: 8 additions & 0 deletions blockstore/apps/api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,18 @@ class BundleNotFound(NotFound):
pass


class BundleVersionNotFound(NotFound):
pass


class DraftNotFound(NotFound):
pass


class DraftHasNoChangesToCommit(BlockstoreException):
pass


class BundleFileNotFound(NotFound):
pass

Expand Down
Loading