Moved tests to paramecio root
This commit is contained in:
parent
c50629e2c7
commit
a04a9e1e86
14 changed files with 2 additions and 0 deletions
|
|
@ -2,6 +2,8 @@ from hashlib import sha512, sha256
|
|||
from base64 import b64encode
|
||||
from os import urandom
|
||||
|
||||
# Functions for create random strings usando urandom
|
||||
|
||||
def create_key_encrypt(n=10):
|
||||
|
||||
return sha512(urandom(n)).hexdigest()
|
||||
|
|
|
|||
|
|
@ -1,32 +0,0 @@
|
|||
from settings import config
|
||||
from paramecio.cromosoma import corefields
|
||||
from paramecio.cromosoma.extrafields.arrayfield import ArrayField
|
||||
import unittest
|
||||
import json
|
||||
|
||||
class TestFieldMethods(unittest.TestCase):
|
||||
|
||||
def test_i18nfield(self):
|
||||
|
||||
type_field=corefields.IntegerField('value')
|
||||
|
||||
field=ArrayField('field', type_field)
|
||||
|
||||
value=[1,2,5,'trick\'']
|
||||
|
||||
json_encoded=field.check(value)
|
||||
|
||||
self.assertEqual(json_encoded, '["1", "2", "5", "0"]')
|
||||
|
||||
type_field=corefields.CharField('value')
|
||||
|
||||
field=ArrayField('field', type_field)
|
||||
|
||||
value=['trick', 'mytuquito', 25]
|
||||
|
||||
json_encoded=field.check(value)
|
||||
|
||||
self.assertEqual(json_encoded, '["trick", "mytuquito", "25"]')
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
from settings import config
|
||||
from paramecio.citoplasma import datetime
|
||||
import unittest
|
||||
|
||||
class TestFieldMethods(unittest.TestCase):
|
||||
|
||||
def test_timenow(self):
|
||||
|
||||
time='20121023401223'
|
||||
|
||||
time_set=datetime.format_timedata(time)
|
||||
|
||||
self.assertFalse(datetime.checkdatetime(time_set[0], time_set[1], time_set[2], time_set[3], time_set[4], time_set[5]))
|
||||
|
||||
time='20121026231248'
|
||||
|
||||
time_set=datetime.format_timedata(time)
|
||||
|
||||
self.assertTrue(datetime.checkdatetime(time_set[0], time_set[1], time_set[2], time_set[3], time_set[4], time_set[5]))
|
||||
|
||||
timestamp=datetime.obtain_timestamp(time)
|
||||
|
||||
self.assertTrue(timestamp)
|
||||
|
||||
datetime.timezone='Europe/Madrid'
|
||||
|
||||
datetime.set_timezone()
|
||||
|
||||
gmtstamp=datetime.local_to_gmt(time)
|
||||
|
||||
self.assertEqual(gmtstamp, '20121026221248')
|
||||
|
||||
time_from_utc=datetime.format_time(time)
|
||||
|
||||
self.assertEqual(time_from_utc, '00:12:48')
|
||||
|
||||
date_from_utc=datetime.format_date(time)
|
||||
|
||||
self.assertEqual(date_from_utc, '2012/10/27')
|
||||
|
||||
#today=datetime.now()
|
||||
|
||||
#print(today)
|
||||
|
||||
"""
|
||||
tz=datetime.obtain_timezone('Europe/Madrid')
|
||||
|
||||
time=datetime.normalize_time(2012, 12, 21, 23, 24, 21)
|
||||
|
||||
self.assertEqual(time, '20121221232421')
|
||||
|
||||
value=datetime.format_tztime(time)
|
||||
|
||||
self.assertEqual(value, '23:24:21')
|
||||
|
||||
value=datetime.format_tzdate(time)
|
||||
|
||||
self.assertEqual(value, '2012/12/21')
|
||||
|
||||
value=datetime.format_tzdate(time, tz)
|
||||
|
||||
self.assertEqual(value, '2012/12/22')
|
||||
|
||||
value=datetime.format_tztime(time, tz)
|
||||
|
||||
self.assertEqual(value, '00:24:21')
|
||||
|
||||
print(datetime.local_to_utc('20121221232421', tz))
|
||||
"""
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
@ -1,58 +0,0 @@
|
|||
from settings import config
|
||||
from paramecio.cromosoma import corefields
|
||||
from paramecio.cromosoma.extrafields.dictfield import DictField
|
||||
import unittest
|
||||
import json
|
||||
|
||||
class TestFieldMethods(unittest.TestCase):
|
||||
|
||||
def test_i18nfield(self):
|
||||
|
||||
type_field=corefields.IntegerField('value')
|
||||
|
||||
field=DictField('field', type_field)
|
||||
|
||||
value={'one': 1, 'two': 2, 'three': 5, 'raw': 'trick\''}
|
||||
|
||||
json_encoded=field.check(value)
|
||||
|
||||
value_real={'one': '1', 'two': '2', 'three': '5', 'raw': '0'}
|
||||
|
||||
value_two=json.loads(json_encoded)
|
||||
|
||||
self.assertEqual(value_two, value_real)
|
||||
|
||||
# Check charfield dictfield
|
||||
|
||||
type_field=corefields.CharField('value')
|
||||
|
||||
field=DictField('field', type_field)
|
||||
|
||||
value={'one': 'pepito', 'raw': 'trick\''}
|
||||
|
||||
json_encoded=field.check(value)
|
||||
|
||||
value_two=json.loads(json_encoded)
|
||||
|
||||
value_real={'one': 'pepito', 'raw': 'trick\''}
|
||||
|
||||
self.assertEqual(value_two, value_real)
|
||||
|
||||
# Check charfield dictfield with quot
|
||||
|
||||
type_field=corefields.CharField('value')
|
||||
|
||||
field=DictField('field', type_field)
|
||||
|
||||
value={'one': 'pepito', 'raw': 'trick"'}
|
||||
|
||||
json_encoded=field.check(value)
|
||||
|
||||
value_two=json.loads(json_encoded)
|
||||
|
||||
value_real={'one': 'pepito', 'raw': 'trick"'}
|
||||
|
||||
self.assertEqual(value_two, value_real)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
@ -1,61 +0,0 @@
|
|||
from settings import config
|
||||
from paramecio.cromosoma.webmodel import WebModel
|
||||
from paramecio.cromosoma import corefields
|
||||
from paramecio.cromosoma.extrafields.emailfield import EmailField
|
||||
import unittest
|
||||
|
||||
class TestFieldMethods(unittest.TestCase):
|
||||
|
||||
def test_phangofield(self):
|
||||
|
||||
field=corefields.PhangoField('example', 255)
|
||||
|
||||
field.required=True
|
||||
|
||||
field.check('')
|
||||
|
||||
self.assertTrue(field.error)
|
||||
|
||||
field.check('content')
|
||||
|
||||
self.assertFalse(field.error)
|
||||
|
||||
value=field.check("injection_'")
|
||||
|
||||
self.assertEqual(value, "injection_'")
|
||||
|
||||
def test_integerfield(self):
|
||||
|
||||
integerfield=corefields.IntegerField('example', 11)
|
||||
|
||||
integerfield.required=True
|
||||
|
||||
integerfield.check(0)
|
||||
|
||||
self.assertTrue(integerfield.error)
|
||||
|
||||
integerfield.check('25')
|
||||
|
||||
self.assertFalse(integerfield.error)
|
||||
|
||||
value=integerfield.check("25'")
|
||||
|
||||
self.assertEqual(value, "0")
|
||||
|
||||
def test_emailfield(self):
|
||||
|
||||
emailfield=EmailField('email')
|
||||
|
||||
emailfield.required=True
|
||||
|
||||
emailfield.check('exampleweb-t-sys.com')
|
||||
|
||||
self.assertTrue(emailfield.error)
|
||||
|
||||
emailfield.check('example@web-t-sys.com')
|
||||
|
||||
self.assertFalse(emailfield.error)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
@ -1,5 +0,0 @@
|
|||
from settings import config
|
||||
from paramecio.cromosoma.webmodel import WebModel
|
||||
from paramecio.cromosoma import corefields
|
||||
import unittest
|
||||
|
||||
|
|
@ -1,41 +0,0 @@
|
|||
from settings import config
|
||||
from paramecio.cromosoma.extrafields.i18nfield import I18nField
|
||||
from paramecio.citoplasma.httputils import GetPostFiles
|
||||
from paramecio.citoplasma.i18n import I18n
|
||||
import unittest
|
||||
|
||||
class TestFieldMethods(unittest.TestCase):
|
||||
|
||||
def test_i18nfield(self):
|
||||
|
||||
field=I18nField('i18n')
|
||||
|
||||
value=field.check({})
|
||||
|
||||
self.assertTrue(field.error)
|
||||
|
||||
value=field.check({'i18n_es-ES': 'Mi text', 'i18n_en-US': 'My Text'})
|
||||
|
||||
self.assertFalse(field.error)
|
||||
|
||||
GetPostFiles.post={'i18n_es-ES': 'Mi text', 'i18n_en-US': 'My Text'}
|
||||
|
||||
value=field.check('')
|
||||
|
||||
self.assertFalse(field.error)
|
||||
|
||||
I18n.default_lang='en-US'
|
||||
|
||||
GetPostFiles.post={'i18n_es-ES': 'My Text'}
|
||||
|
||||
value=field.check('')
|
||||
|
||||
self.assertTrue(field.error)
|
||||
|
||||
#phrase=slugify.slugify('this!()is a crap phrase o}çÇf oh yeah¡\'')
|
||||
|
||||
#self.assertEqual(phrase, 'this---is-a-crap-phrase-o---f-oh-yeah--')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
@ -1,68 +0,0 @@
|
|||
from bottle import FileUpload
|
||||
from paramecio.cromosoma.webmodel import WebModel
|
||||
from paramecio.cromosoma.extrafields.imagefield import ImageField
|
||||
from paramecio.citoplasma.httputils import GetPostFiles
|
||||
from settings import config
|
||||
import unittest
|
||||
|
||||
class TestFieldMethods(unittest.TestCase):
|
||||
|
||||
def test_imagefield(self):
|
||||
|
||||
f=open('tests/images/image.jpg', 'rb')
|
||||
|
||||
GetPostFiles.files={}
|
||||
|
||||
GetPostFiles.files['image_file']=FileUpload(f, 'image_file', 'image.jpg')
|
||||
|
||||
field=ImageField('image', 'tests/images/uploads', module=None, size=255, required=False)
|
||||
|
||||
field.yes_thumbnail=True
|
||||
|
||||
field.check('')
|
||||
|
||||
print(field.txt_error)
|
||||
|
||||
self.assertFalse(field.error)
|
||||
|
||||
pass
|
||||
|
||||
|
||||
"""from settings import config
|
||||
from bottle import FileUpload
|
||||
from paramecio.cromosoma.webmodel import WebModel
|
||||
from paramecio.cromosoma.imagefield import ImageField
|
||||
from paramecio.citoplasma.httputils import GetPostFiles
|
||||
import unittest
|
||||
|
||||
class TestImageFieldMethods(unittest.TestCase):
|
||||
|
||||
def test_image(self):
|
||||
#name, save_folder, module=None, size=255, required=False)
|
||||
|
||||
#FileUpload(fileobj, name, filename
|
||||
x=0
|
||||
pass
|
||||
|
||||
GetPostFiles.files=
|
||||
|
||||
field=ImageField(, 'test/image', module=None, size=255, required=False)
|
||||
|
||||
field.required=True
|
||||
|
||||
field.check('')
|
||||
|
||||
self.assertTrue(field.error)
|
||||
|
||||
field.check('content')
|
||||
|
||||
self.assertFalse(field.error)
|
||||
|
||||
value=field.check("injection_'")
|
||||
|
||||
self.assertEqual(value, "injection_\\'")"""
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 546 KiB |
|
|
@ -1,25 +0,0 @@
|
|||
from settings import config
|
||||
from paramecio.citoplasma import sendmail
|
||||
import time
|
||||
import unittest
|
||||
|
||||
class TestFieldMethods(unittest.TestCase):
|
||||
|
||||
def test_sendmail(self):
|
||||
|
||||
s=sendmail.SendMail()
|
||||
|
||||
self.assertTrue( s.send(config.portal_email, [config.email_test], 'This is a test', 'A message for test a simple email method', content_type='plain', attachments=[]) )
|
||||
|
||||
s=sendmail.SendMail()
|
||||
|
||||
self.assertTrue( s.send(config.portal_email, [config.email_test], 'This is a test', 'A message for test a simple email method in <b>html</b>', content_type='html', attachments=[]) )
|
||||
|
||||
s=sendmail.SendMail()
|
||||
|
||||
self.assertTrue( s.send(config.portal_email, [config.email_test], 'This is a test', 'A message for test a simple email method in <b>html</b> and attachments', content_type='html', attachments=['tests/images/image.jpg']) )
|
||||
|
||||
#s.quit()
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
@ -1,15 +0,0 @@
|
|||
from settings import config
|
||||
from paramecio.citoplasma import slugify
|
||||
import unittest
|
||||
|
||||
class TestFieldMethods(unittest.TestCase):
|
||||
|
||||
def test_slugify(self):
|
||||
|
||||
phrase=slugify.slugify('this!()is a crap phrase o}çÇf oh yeah¡\'')
|
||||
|
||||
self.assertEqual(phrase, 'this---is-a-crap-phrase-o---f-oh-yeah--')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
@ -1,179 +0,0 @@
|
|||
from settings import config
|
||||
from paramecio.cromosoma.webmodel import WebModel
|
||||
from paramecio.cromosoma import corefields
|
||||
import unittest
|
||||
# Create TestWebModelMethods
|
||||
|
||||
class ExampleModel(WebModel):
|
||||
|
||||
def __init__(self, connection):
|
||||
|
||||
super().__init__(connection)
|
||||
|
||||
# I can change other fields here, how the name.
|
||||
|
||||
self.register(corefields.CharField('title'))
|
||||
self.register(corefields.CharField('content'))
|
||||
|
||||
class ExampleModel2(WebModel):
|
||||
|
||||
def __init__(self, connection):
|
||||
|
||||
super().__init__(connection)
|
||||
|
||||
# I can change other fields here, how the name.
|
||||
|
||||
self.register(corefields.CharField('title'))
|
||||
self.register(corefields.CharField('content'))
|
||||
|
||||
class TestWebModelMethods(unittest.TestCase):
|
||||
|
||||
def test_test_table(self):
|
||||
|
||||
connection=WebModel.connection()
|
||||
model=ExampleModel(connection)
|
||||
|
||||
|
||||
sql=model.create_table()
|
||||
|
||||
print('Creating table')
|
||||
|
||||
self.assertTrue(model.query(sql))
|
||||
|
||||
|
||||
post={'title': 'Example title', 'content': 'New content'}
|
||||
|
||||
model.set_valid_fields()
|
||||
|
||||
print('Insert row')
|
||||
|
||||
self.assertTrue(model.insert(post))
|
||||
|
||||
print('Check new id')
|
||||
|
||||
self.assertEqual(model.insert_id(), 1)
|
||||
|
||||
post={'title': 'Example title Updated', 'content': 'New content Updated'}
|
||||
|
||||
model.conditions=['WHERE id=%s', [1]]
|
||||
|
||||
print('Updating row')
|
||||
|
||||
self.assertTrue(model.update(post))
|
||||
|
||||
model.yes_reset_conditions=False
|
||||
|
||||
model.conditions=['WHERE id=%s', [1]]
|
||||
|
||||
print('Count rows')
|
||||
|
||||
self.assertEqual(model.select_count(), 1)
|
||||
|
||||
print('Select a row')
|
||||
|
||||
self.assertEqual(model.select_a_row(1, ['title']), {'title': 'Example title Updated'})
|
||||
|
||||
print('Select a row with different conditions to search id')
|
||||
|
||||
self.assertEqual(model.select_a_row_where(['title']), {'title': 'Example title Updated'})
|
||||
|
||||
print('Select and save in an array')
|
||||
|
||||
self.assertEqual(model.select_to_array(['title', 'content']), [{'id': 1, 'title': 'Example title Updated', 'content': 'New content Updated'}])
|
||||
|
||||
model.yes_reset_conditions=True
|
||||
|
||||
model.reset_conditions()
|
||||
|
||||
print('Reset conditions')
|
||||
|
||||
self.assertEqual(model.conditions, ['WHERE 1=1', []])
|
||||
|
||||
print('Simple base select')
|
||||
|
||||
cur=model.select()
|
||||
|
||||
row=model.fetch(cur)
|
||||
|
||||
self.assertEqual(row, {'id': 1, 'title': 'Example title Updated', 'content': 'New content Updated'})
|
||||
|
||||
print('Check element exists')
|
||||
|
||||
self.assertTrue(model.element_exists(1))
|
||||
|
||||
model.conditions=['WHERE id=%s', [2]]
|
||||
|
||||
print('Check delete row')
|
||||
|
||||
self.assertFalse(model.delete())
|
||||
|
||||
self.assertTrue(model.delete())
|
||||
|
||||
print('Check delete table')
|
||||
|
||||
self.assertTrue(model.drop())
|
||||
|
||||
connection.close()
|
||||
|
||||
|
||||
def test_update_table(self):
|
||||
|
||||
connection=WebModel.connection()
|
||||
model=ExampleModel(connection)
|
||||
|
||||
|
||||
print('Check modifications in table')
|
||||
|
||||
sql=model.create_table()
|
||||
|
||||
self.assertTrue(model.query(sql))
|
||||
|
||||
fields_to_modify=[]
|
||||
fields_to_add_index=[]
|
||||
fields_to_add_constraint=[]
|
||||
fields_to_add_unique=[]
|
||||
fields_to_delete_index=[]
|
||||
fields_to_delete_unique=[]
|
||||
fields_to_delete_constraint=[]
|
||||
fields_to_delete=[]
|
||||
|
||||
model.register(corefields.CharField('description'))
|
||||
|
||||
model.update_table(['description'], fields_to_modify, fields_to_add_index, fields_to_add_constraint, fields_to_add_unique, fields_to_delete_index, fields_to_delete_unique, fields_to_delete_constraint, fields_to_delete)
|
||||
|
||||
model.register(corefields.IntegerField('description'))
|
||||
|
||||
model.update_table([], ['description'], ['description'], [], ['description'], fields_to_delete_index, fields_to_delete_unique, fields_to_delete_constraint, fields_to_delete)
|
||||
|
||||
model.update_table([], fields_to_modify, fields_to_add_index, fields_to_add_constraint, fields_to_add_unique, ['description'], ['description'], fields_to_delete_constraint, ['description'])
|
||||
|
||||
self.assertTrue(model.drop())
|
||||
|
||||
connection.close()
|
||||
|
||||
def test_zcheck_connections(self):
|
||||
|
||||
print('Check connection of models...')
|
||||
|
||||
connection=WebModel.connection()
|
||||
model=ExampleModel(connection)
|
||||
|
||||
model2=ExampleModel2(connection)
|
||||
|
||||
sql=model.create_table()
|
||||
sql2=model2.create_table()
|
||||
#print(sql)
|
||||
|
||||
self.assertTrue(model.query(sql))
|
||||
self.assertTrue(model2.query(sql2))
|
||||
|
||||
self.assertTrue(model.drop())
|
||||
self.assertTrue(model2.drop())
|
||||
|
||||
connection.close()
|
||||
|
||||
pass
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue