-
-
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 pull request #221 from Ilhasoft/develop
Version 1.16.0
- Loading branch information
Showing
15 changed files
with
649 additions
and
42 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
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', | ||
] | ||
|
||
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,78 @@ | ||
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.models import RepositoryExample | ||
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) | ||
current_update = self.repository.current_update() | ||
RepositoryExample.objects.create( | ||
repository_update=current_update, | ||
text='my name is Douglas', | ||
intent='greet') | ||
RepositoryExample.objects.create( | ||
repository_update=current_update, | ||
text='my name is John', | ||
intent='greet') | ||
current_update.start_training(self.owner) | ||
|
||
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_400_BAD_REQUEST) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Generated by Django 2.0.6 on 2018-09-21 12:59 | ||
|
||
import django.core.validators | ||
from django.db import migrations, models | ||
import re | ||
|
||
|
||
def populate_empty_intent(apps, *args): | ||
RepositoryExample = apps.get_model('common', 'RepositoryExample') | ||
RepositoryExample.objects.filter(intent='').update(intent='no_intent') | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('common', '0020_auto_20180813_1320'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='repositoryexample', | ||
name='intent', | ||
field=models.CharField(default='no_intent', help_text='Example intent reference', max_length=64, validators=[django.core.validators.RegexValidator(re.compile('^[-a-z0-9_]+\\Z'), 'Enter a valid value consisting of lowercase letters, numbers, underscores or hyphens.', 'invalid')], verbose_name='intent'), | ||
), | ||
migrations.RunPython(populate_empty_intent), | ||
] |
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'), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
bothub/common/migrations/0023_repository_use_language_model_featurizer.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-10-02 17:47 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('common', '0022_repositoryupdate_training_log'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='repository', | ||
name='use_language_model_featurizer', | ||
field=models.BooleanField(default=True, help_text='You can use language featurizer to get words similarity. You need less examples to create a great bot.', verbose_name='Use language model featurizer'), | ||
), | ||
] |
18 changes: 18 additions & 0 deletions
18
bothub/common/migrations/0024_repositoryupdate_use_language_model_featurizer.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-10-02 17:54 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('common', '0023_repository_use_language_model_featurizer'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='repositoryupdate', | ||
name='use_language_model_featurizer', | ||
field=models.BooleanField(default=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,23 @@ | ||
# Generated by Django 2.0.6 on 2018-10-03 19:11 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('common', '0024_repositoryupdate_use_language_model_featurizer'), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name='repository', | ||
name='use_competing_intents', | ||
field=models.BooleanField(default=False, help_text='When using competing intents the confidence of the prediction is distributed in all the intents.', verbose_name='Use competing intents'), | ||
), | ||
migrations.AddField( | ||
model_name='repositoryupdate', | ||
name='use_competing_intents', | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
Oops, something went wrong.