-
-
Notifications
You must be signed in to change notification settings - Fork 775
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
121 additions
and
7 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import factory | ||
import pytest | ||
from git.models import GitCache | ||
|
||
|
||
@pytest.mark.django_db | ||
class GitCacheFactory(factory.django.DjangoModelFactory): | ||
class Meta: | ||
model = GitCache | ||
|
||
# Unique user handle | ||
handle = factory.Sequence(lambda n: f"user_handle_{n}") | ||
|
||
# Cycle through the choices and select one | ||
category = factory.Sequence(lambda n: GitCache.CATEGORY_CHOICES[n % len(GitCache.CATEGORY_CHOICES)][0]) | ||
|
||
# Generate binary data depending on n | ||
data = factory.Sequence(lambda n: ("{n}" * 100).encode("utf-8")) | ||
|
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from git.tests.factories.git_cache_factory import GitCacheFactory | ||
import pytest | ||
from git.models import GitCache | ||
|
||
|
||
@pytest.mark.django_db | ||
class TestGitCache: | ||
"""Test CLRMatch model.""" | ||
|
||
def test_creation(self): | ||
"""Test GitCache returned by factory is valid.""" | ||
|
||
git_cache = GitCacheFactory() | ||
|
||
assert isinstance(git_cache, GitCache) | ||
|
||
def test_get_user(self): | ||
"""Test get_user helper function.""" | ||
|
||
git_cache = GitCacheFactory() | ||
git_cache.category = GitCache.Category.USER | ||
handle = git_cache.handle | ||
git_cache.save() | ||
|
||
saved = GitCache.get_user(handle) | ||
assert git_cache.id == saved.id | ||
|
||
def test_update_data(self): | ||
"""Test update_data helper function.""" | ||
|
||
git_cache = GitCacheFactory() | ||
git_cache.category = GitCache.Category.USER | ||
handle = git_cache.handle | ||
git_cache.save() | ||
|
||
new_data = "This is updated data".encode("utf-8") | ||
git_cache.update_data(new_data) | ||
|
||
saved = GitCache.get_user(handle) | ||
assert new_data == saved.data.tobytes() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters