-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' of https://github.com/Ilhasoft/bothub-engine i…
…nto api-v2
- Loading branch information
Showing
9 changed files
with
183 additions
and
12 deletions.
There are no files selected for viewing
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,25 @@ | ||
from rest_framework import serializers | ||
|
||
from bothub.common.models import RepositoryUpdate | ||
|
||
|
||
class RepositoryUpdateSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = RepositoryUpdate | ||
fields = [ | ||
'id', | ||
'repository', | ||
'language', | ||
'created_at', | ||
'by', | ||
'by__nickname', | ||
'training_started_at', | ||
'trained_at', | ||
'failed_at', | ||
'training_log', | ||
] | ||
|
||
by__nickname = serializers.SlugRelatedField( | ||
source='by', | ||
slug_field='nickname', | ||
read_only=True) |
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,71 @@ | ||
import json | ||
|
||
from django.test import TestCase | ||
from django.test import RequestFactory | ||
from rest_framework import status | ||
from bothub.common.models import Repository | ||
from bothub.common import languages | ||
|
||
from ..views import RepositoryUpdatesViewSet | ||
from .utils import create_user_and_token | ||
|
||
|
||
class UpdatesTestCase(TestCase): | ||
def setUp(self): | ||
self.factory = RequestFactory() | ||
|
||
self.owner, self.owner_token = create_user_and_token('owner') | ||
|
||
self.repository = Repository.objects.create( | ||
owner=self.owner, | ||
name='Testing', | ||
slug='test', | ||
language=languages.LANGUAGE_EN) | ||
self.repository.current_update() | ||
|
||
def request(self, data, token=None): | ||
authorization_header = { | ||
'HTTP_AUTHORIZATION': 'Token {}'.format(token.key), | ||
} if token else {} | ||
request = self.factory.get( | ||
'/api/updates/', | ||
data, | ||
**authorization_header) | ||
response = RepositoryUpdatesViewSet.as_view( | ||
{'get': 'list'})(request) | ||
response.render() | ||
content_data = json.loads(response.content) | ||
return (response, content_data,) | ||
|
||
def test_okay(self): | ||
response, content_data = self.request( | ||
{ | ||
'repository_uuid': str(self.repository.uuid), | ||
}, | ||
self.owner_token) | ||
self.assertEqual( | ||
response.status_code, | ||
status.HTTP_200_OK) | ||
self.assertEqual( | ||
content_data.get('count'), | ||
1) | ||
|
||
def test_not_authenticated(self): | ||
response, content_data = self.request( | ||
{ | ||
'repository_uuid': str(self.repository.uuid), | ||
}) | ||
self.assertEqual( | ||
response.status_code, | ||
status.HTTP_401_UNAUTHORIZED) | ||
|
||
def test_without_repository(self): | ||
response, content_data = self.request( | ||
{}, | ||
self.owner_token) | ||
self.assertEqual( | ||
response.status_code, | ||
status.HTTP_200_OK) | ||
self.assertEqual( | ||
content_data.get('count'), | ||
0) |
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
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
18 changes: 18 additions & 0 deletions
18
bothub/common/migrations/0022_repositoryupdate_training_log.py
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,18 @@ | ||
# Generated by Django 2.0.6 on 2018-09-26 17:43 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('common', '0021_auto_20180921_1259'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='repositoryupdate', | ||
name='training_log', | ||
field=models.TextField(blank=True, editable=False, verbose_name='training log'), | ||
), | ||
] |
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