Commit 35f34642 authored by Mathieu Courcelles's avatar Mathieu Courcelles

-Test now use Factory instead of fixture.

-Created test for views
parent 84bf7f4a
......@@ -21,3 +21,4 @@ build
site_media
site_media/FastaDB
site_media/RawDataset
site_media/FastaDB
......@@ -51,7 +51,7 @@ class CLPeptideAdmin(admin.ModelAdmin):
list_filter = ('dataset__project', 'dataset', 'precursor_charge',
'link_type', 'cross_link', 'autovalidated',
'not_decoy', 'rejected' )
'not_decoy', 'rejected', )
search_fields = ('run_name', 'display_protein1',
'peptide1', 'peptide_wo_mod1',
......
......@@ -200,6 +200,7 @@ def dataset_stats_csv(self, request, queryset, tableName):
('Autovalidated', 0),
('Decoy', 0),
('False positive ratio', '-'),
('z1', 0),
('z2', 0),
('z3', 0),
('z4', 0),
......
......@@ -365,7 +365,9 @@ def save_file(sender, instance, created, **kwargs):
instance.file = getattr(instance, _UNSAVED_FILEFIELD)
if created and hasattr(instance, _UNSAVED_FILEFIELD_EXTRA):
instance.extra_file = getattr(instance, _UNSAVED_FILEFIELD_EXTRA)
instance.save()
if instance.file != '':
instance.save()
@receiver(pre_delete, sender=RawDataset)
......
......@@ -4,12 +4,14 @@
# Import standard librariesdjang
# Import standard libraries
# Import Django related libraries
# Import project libraries
from test_forms import *
from test_models import *
from test_parser import *
from test_views import *
from test_parser import *
\ No newline at end of file
# # Copyright 2013 Mathieu Courcelles
# # Mike Tyers's lab / IRIC / Universite de Montreal
# Import standard libraries
import random
# Import Django related libraries
# Import project libraries
from ..models import (FastaDB,
FastaDb_Sequence,
Project,
)
from models_factories import (CLPeptideFactory,
FastaDBFactory,
FastaDb_SequenceFactory,
ProjectFactory,
RawDatasetFactory,
)
def setUp():
"""
Mock up database objects for test. It uses factory_boy to replace
slow fixtures.
"""
# Fake some projects
for _ in xrange(0, 2):
ProjectFactory()
projects = Project.objects.all()
# Fake some FastaDB
for _ in xrange(0, 2):
FastaDBFactory()
fastadb = FastaDB.objects.all()
# Fake some FastaDb_Sequence
for _ in xrange(0, 10):
FastaDb_SequenceFactory(fastadb=random.choice(fastadb))
sequences = FastaDb_Sequence.objects.all()
# Fake some RawDatasets
for _ in xrange(0, 5):
RawDatasetFactory(project=random.choice(projects),
fasta_db=random.choice(fastadb))
# Fake some CLPeptide
for _ in xrange(0, 25):
CLPeptideFactory(fs_prot1_id=random.choice(sequences),
fs_prot2_id=random.choice(sequences))
This diff is collapsed.
......@@ -8,30 +8,41 @@
from django.test import TestCase
# Import project libraries
from ..models import CLPeptide, FastaDB, FastaDb_Sequence
from ..models import RawDataset
from ..models import upload_path_handler
from ..models import remove_CLPeptideRD
class SimpleTest(TestCase):
def test_basic_addition(self):
"""
Tests that 1 + 1 always equals 2.
"""
self.assertEqual(1 + 1, 2)
import mock_up
from ..models import (CLPeptide,
FastaDB,
FastaDb_Sequence,
RawDataset,
remove_CLPeptideRD,
upload_path_handler,
)
def setUpModule():
"""
Mock up database objects for test.
"""
mock_up.setUp()
class ModelTestCase(TestCase):
"""
Tests for Models.
"""
fixtures = ['testdata.json']
def setUp(self):
pass
def tearDown(self):
pass
def test_CLPeptide(self):
"""
Tests for CLPeptide methods
"""
# fixAutovalidated() test
clpep = CLPeptide.objects.all()[0]
......@@ -42,40 +53,41 @@ class ModelTestCase(TestCase):
clpep.fixAutovalidated()
self.assertEqual(clpep.autovalidated, False)
# guessLinkType() test
clpep.peptide_wo_mod1 = 'A'
clpep.peptide_wo_mod2 = 'A'
clpep.guessLinkType()
self.assertEqual(clpep.link_type, 'Inter-protein')
self.assertEqual(clpep.cross_link, True)
clpep.peptide_wo_mod2 = 'B'
clpep.display_protein1 = 'A'
clpep.display_protein2 = 'B'
clpep.guessLinkType()
self.assertEqual(clpep.link_type, 'Inter-protein')
self.assertEqual(clpep.cross_link, True)
clpep.peptide_wo_mod2 = 'B'
clpep.display_protein1 = 'A'
clpep.display_protein2 = 'A'
clpep.guessLinkType()
self.assertEqual(clpep.link_type, 'Intra-protein')
self.assertEqual(clpep.cross_link, True)
clpep.pep2_link_pos = -1
clpep.display_protein2 = ''
clpep.guessLinkType()
self.assertEqual(clpep.link_type, 'Dead-end')
self.assertEqual(clpep.cross_link, False)
clpep.pep2_link_pos = 1
clpep.peptide_wo_mod2 = '-'
clpep.guessLinkType()
self.assertEqual(clpep.link_type, 'Intra-peptide')
self.assertEqual(clpep.cross_link, False)
# isDecoy() test
clpep.display_protein1 = 'DECOY'
clpep.isDecoy()
......@@ -89,12 +101,12 @@ class ModelTestCase(TestCase):
clpep.display_protein2 = ''
clpep.isDecoy()
self.assertEqual(clpep.not_decoy, True)
# uniqueKey test
clpep.peptide_wo_mod1 = 'A'
clpep.peptide_wo_mod2 = 'B'
separator = '~~'
params = dict()
params['sequence'] = 1
......@@ -107,12 +119,15 @@ class ModelTestCase(TestCase):
self.assertEqual(len(clpep.uniqueKey(params).split(separator)), 12)
params['charge'] = 1
self.assertEqual(len(clpep.uniqueKey(params).split(separator)), 13)
def test_RawDataset(self):
"""
Tests for RawDataset methods
"""
d1 = RawDataset.objects.all()[0]
self.assertEqual(upload_path_handler(d1, d1.file),
'RawDataset/%s-%s' % (d1.pk, d1.file))
self.assertEqual(d1.get_admin_url(),
......@@ -124,6 +139,7 @@ class ModelTestCase(TestCase):
'<a href="/admin/CLMSpipeline_app/rawdataset/%s/">[%s]</a><br />'
% (d1.pk, d1.pk))
# Check removal of cross-linked peptides
v1 = len(d1.clpeptide_set.all())
v2 = 0
......@@ -132,19 +148,21 @@ class ModelTestCase(TestCase):
v2 += 1
remove_CLPeptideRD(None, d1)
v3 = len(d1.clpeptide_set.all())
self.assertEqual(v3, v1 - v2)
def test_FastaDb_Sequence(self):
"""
Tests for FastaDb_Sequence methods
"""
# Test extractFeatures(self, fastadb_instance)
o1 = FastaDb_Sequence.objects.all()[0]
fastadb_instance = FastaDB.objects.all()[0]
self.assertEqual(o1.extractFeatures(fastadb_instance),'')
fastadb_instance.identifier_regexp = 'BAD'
self.assertEqual(o1.extractFeatures(fastadb_instance),'identifier')
\ No newline at end of file
......@@ -8,17 +8,38 @@
from django.test import TestCase
# Import project libraries
import mock_up
from ..models import FastaDB
from ..parser.pLinkParser import pLinkParser
from ..parser.xQuestParser import xQuestParser
from ..parser.sequences import sequencesMatcher
def setUpModule():
"""
Mock up database objects for test.
"""
mock_up.setUp()
class PaserTestCase(TestCase):
"""
Tests for Parsers.
"""
def setUp(self):
pass
def tearDown(self):
pass
fixtures = ['testdata.json']
def test_pLink(self):
"""
Test pLink methods.
"""
# formatPeptideSequence(peptide) test
self.assertEqual(pLinkParser.formatPeptideSequence('TTTXTTT'),
......@@ -27,9 +48,12 @@ class PaserTestCase(TestCase):
'TTTCmTTT')
self.assertEqual(pLinkParser.formatPeptideSequence('TTTCTTCT'),
'TTTCmTTCmT')
def test_xQuest(self):
"""
Test xQuest methods.
"""
# formatPeptideSequence(peptide) test
self.assertEqual(xQuestParser.formatPeptideSequence('ZTTTTT'),
......@@ -40,15 +64,20 @@ class PaserTestCase(TestCase):
'TTTCmTTCmT')
self.assertEqual(xQuestParser.formatPeptideSequence('TTTXTTCT'),
'TTTMoxTTCmT')
def test_sequencesMatcher(self):
"""
Test sequencesMatcher methods.
"""
seq_set = FastaDB.objects.get(pk=2).fastadb_sequence_set.all()
# Prepare sequenceMatcher
sM = sequencesMatcher(2)
# Match protein sequences
self.assertEqual(sM.sequencePk('Ub').pk, 2)
self.assertEqual(sM.sequencePk('Cdc34').pk, 3)
self.assertEqual(sM.sequencePk(seq_set[0].raw_description[0:4]).pk,
seq_set[0].pk)
self.assertEqual(sM.sequencePk('BAD'), None)
\ No newline at end of file
......@@ -2,11 +2,80 @@
# # Mike Tyers's lab / IRIC / Universite de Montreal
# Import standard librariesdjang
# Import standard libraries
from mock import patch
# Import Django related libraries
from django.test import TestCase
# Import project libraries
from django.test import TestCase
\ No newline at end of file
import mock_up
from ..models import CLPeptide
from models_factories import (FakeRequestFactory,
UserFactory
)
from ..views import xiNET_view
def setUpModule():
"""
Mock up database objects for test.
"""
mock_up.setUp()
class ViewUserTestCase(TestCase):