New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Models #11

Merged
merged 6 commits into from Jun 19, 2017

feat(models): Add unit tests for models

  • Loading branch information...
uttu357 committed Jun 13, 2017
commit a2348492f95a9be60e3d55c9c0c8c4b3252224dc
Copy path View file
@@ -26,9 +26,11 @@ install:
- pip install -r requirements/dev.txt
- cd frontend && yarn install
- cd ../
- cp settings/dev/settings.sample.py settings/dev/settings.py

This comment has been minimized.

@deshraj

deshraj Jun 19, 2017

Member

Can we have a different settings file for tests?

script:
- flake8 ./
- python manage.py test --settings=settings.dev.settings
- cd frontend && npm run lint:build
- npm run test
- npm run build:alias
Copy path View file
@@ -3,6 +3,7 @@
from django.db import models
from base.models import (TimeStampedModel, )
from base.utils import RandomFileName
from demos.models import (Demo, )
@@ -29,7 +30,7 @@ def __unicode__(self):
return '{0}: {1}: {2}'.format(self.log_type, self.demo.title, self.created_at)
class LogImages(TimeStampedModel):
class LogImage(TimeStampedModel):
"""Models representing the images associated with demo logs"""
# Image type options
@@ -42,18 +43,18 @@ class LogImages(TimeStampedModel):
)
demo_log = models.ForeignKey(DemoLog)
image = models.ImageField(upload_to="demo_log_images", default=False)
image = models.ImageField(upload_to=RandomFileName("demo_log_images"), default=False)
image_type = models.CharField(max_length=10, choices=IMAGE_TYPE_OPTIONS)
class Meta:
app_label = 'logs'
db_table = 'log_images'
def __unicode__(self):
return '{0} : {1}'.format(self.image.url, self.image_type)
return '{0}: {1}'.format(self.image.url, self.image_type)
class LogTexts(TimeStampedModel):
class LogText(TimeStampedModel):
"""Models representing the texts associated with demo logs"""
# Text type options
Copy path View file
@@ -39,9 +39,9 @@ class Team(models.Model):
description = models.TextField(null=True)
image = models.ImageField(upload_to="team", null=True, blank=True)
visible = models.BooleanField(default=False)
github_url = models.CharField(max_length=200, null=True, blank=True)
linkedin_url = models.CharField(max_length=200, null=True, blank=True)
personal_website = models.CharField(max_length=200, null=True, blank=True)
github_url = models.URLField(max_length=200, null=True, blank=True)
linkedin_url = models.URLField(max_length=200, null=True, blank=True)
personal_website = models.URLField(max_length=200, null=True, blank=True)
team_type = models.CharField(choices=TEAM_TYPE_OPTIONS, max_length=50)
def __unicode__(self):
Copy path View file
@@ -1,3 +1,4 @@
Django==1.11.1
psycopg2==2.7.1
Pillow==4.1.1
python-memcached==1.58
Copy path View file
No changes.
Copy path View file
No changes.
Copy path View file
@@ -0,0 +1,27 @@
from django.test import TestCase
from demos.models import Demo
class DemoTestCase(TestCase):
def setUp(self):
super(DemoTestCase, self).setUp()
self.demo = Demo.objects.create(
title='CloudCV Classification',
demo_url='http://cloudcv.org/classify/',
tag_line='Use CloudCV to automatically find which objects are present in an image',
description='Click on one of these images to send it to our servers (Or upload your own images below)',
sample=True,
text_inputs=0,
image_inputs=1,
text_outputs=1,
image_outputs=0,
)
def test__str__(self):
title = self.demo.title
demo_url = self.demo.demo_url
final_str = '{0}: {1}'.format(title, demo_url)
self.assertEqual(final_str, self.demo.__str__())
Copy path View file
No changes.
Copy path View file
@@ -0,0 +1,69 @@
import os
from django.core.files.uploadedfile import SimpleUploadedFile
from tests.unit.demos.test_models import DemoTestCase
from logs.models import DemoLog, LogImage, LogText
class LogTestCase(DemoTestCase):
def setUp(self):
super(LogTestCase, self).setUp()
try:
os.makedirs('/tmp/cloudcv')
except OSError:
pass
self.demo_log = DemoLog.objects.create(
demo=self.demo,
log_type='Submission'
)
def test__str__(self):
log_type = self.demo_log.log_type
demo_title = self.demo.title
created_at = self.demo_log.created_at
final_str = '{0}: {1}: {2}'.format(log_type, demo_title, created_at)
self.assertEqual(final_str, self.demo_log.__str__())
class LogImageTestCase(LogTestCase):
def setUp(self):
super(LogImageTestCase, self).setUp()
with self.settings(MEDIA_ROOT='/tmp/cloudcv'):
self.demo_log_image = LogImage.objects.create(
demo_log=self.demo_log,
image=SimpleUploadedFile(
name='test_input.jpg',
content=open('frontend/src/images/cloudcv_logo.png', 'rb').read(),
content_type='image/png'
),
image_type='Input'
)
def test__str__(self):
image_url = self.demo_log_image.image.url
image_type = self.demo_log_image.image_type
final_str = '{0}: {1}'.format(image_url, image_type)
self.assertEqual(final_str, self.demo_log_image.__str__())
class LogTextTestCase(LogTestCase):
def setUp(self):
super(LogTextTestCase, self).setUp()
self.demo_log_text = LogText.objects.create(
demo_log=self.demo_log,
text='What is the color of logo?',
text_type='Output'
)
def test__str__(self):

This comment has been minimized.

@deshraj

deshraj Jun 16, 2017

Member

We are using python 2.X right? Let's rename the method to test__unicode__()

This comment has been minimized.

@uttu357

uttu357 Jun 16, 2017

Member

Ohk sure! 👍

text = self.demo_log_text.text
text_type = self.demo_log_text.text_type
final_str = '{0}: {1}'.format(text, text_type)
self.assertEqual(final_str, self.demo_log_text.__str__())
Copy path View file
No changes.
Copy path View file
@@ -0,0 +1,67 @@
import os
from django.test import TestCase
from django.core.files.uploadedfile import SimpleUploadedFile
from web.models import Contact, Team
class ContactTestCase(TestCase):
def setUp(self):
super(ContactTestCase, self).setUp()
try:
os.makedirs('/tmp/cloudcv')
except OSError:
pass
with self.settings(MEDIA_ROOT='/tmp/cloudcv'):
self.contact = Contact.objects.create(
name='user',
email='user@domain.com',
message='test message',
image=SimpleUploadedFile(
name='test_screnshot.jpg',
content=open('frontend/src/images/cloudcv_logo.png', 'rb').read(),
content_type='image/png'
)
)
def test__str__(self):
name = self.contact.name
email = self.contact.email
message = self.contact.message
final_string = '{0}: {1}: {2}'.format(name, email, message)
self.assertEqual(final_string, self.contact.__str__())
class TeamTestCase(TestCase):
def setUp(self):
super(TeamTestCase, self).setUp()
try:
os.makedirs('/tmp/cloudcv')
except OSError:
pass
with self.settings(MEDIA_ROOT='/tmp/cloudcv'):
self.team = Team.objects.create(
name='user',
email='test@user.com',
description='Description for Test User',
image=SimpleUploadedFile(
name='test_image.jpg',
content=open('frontend/src/images/cloudcv_logo.png', 'rb').read(),
content_type='image/png'
),
github_url='www.github.com/Cloud-CV',
linkedin_url='www.linkedin.com/testuser',
personal_website='CloudCV.org',
team_type=Team.TEAM,
visible=True,
)
def test__str__(self):
self.assertEqual(self.team.name, self.team.__str__())
ProTip! Use n and p to navigate between commits in a pull request.