Skip to content

Commit

Permalink
clean test #105
Browse files Browse the repository at this point in the history
  • Loading branch information
uralbash committed Oct 23, 2015
1 parent ddb2697 commit dfe2e26
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 186 deletions.
14 changes: 2 additions & 12 deletions sacrud/tests/__init__.py
Expand Up @@ -3,7 +3,6 @@
action.py tests
"""

import glob
import os
import unittest

Expand All @@ -18,13 +17,11 @@
from zope.sqlalchemy import ZopeTransactionExtension

from sacrud.common import TableProperty
from sacrud.exttype import FileStore

Base = declarative_base()

DIRNAME = os.path.dirname(__file__)
PHOTO_PATH = os.path.join(DIRNAME)
DB_FILE = os.path.join(os.path.dirname(__file__), 'test.sqlite')
DB_FILE = os.path.join(DIRNAME, 'test.sqlite')
TEST_DATABASE_CONNECTION_STRING = 'sqlite:///%s' % DB_FILE


Expand All @@ -41,13 +38,7 @@ def setUp(self):
self.session2.configure(bind=self.engine)

def tearDown(self):

def clear_files():
files = glob.glob("%s/*.html" % PHOTO_PATH)
files += glob.glob("%s/*.txt" % PHOTO_PATH)
for filename in files:
os.remove(os.path.join(PHOTO_PATH, filename))
clear_files()
pass


class BaseZopeTest(BaseTest):
Expand Down Expand Up @@ -184,4 +175,3 @@ class Profile(Base):
cv = Column(Text)
married = Column(Boolean)
salary = Column(Float)
photo = Column(FileStore(path="/assets/photo", abspath=PHOTO_PATH))
35 changes: 0 additions & 35 deletions sacrud/tests/test_action.py
Expand Up @@ -5,20 +5,15 @@
# Copyright © 2014 uralbash <root@uralbash.ru>
#
# Distributed under terms of the MIT license.
import glob
import json
from io import StringIO

import transaction
from sacrud.action import CRUD
from sacrud.common import delete_fileobj
from sacrud.tests import (
BaseSQLAlchemyTest,
BaseZopeTest,
Groups,
Groups2User,
MockCGIFieldStorage,
PHOTO_PATH,
Profile,
User
)
Expand Down Expand Up @@ -218,11 +213,6 @@ def test_create_user(self):
request["salary"] = ["23.0", ]
request["user_id"] = ["1", ]

upload = MockCGIFieldStorage()
upload.file = StringIO(u'foo')
upload.filename = 'foo.html'
request["photo"] = [upload, ]

CRUD(self.session, Profile).create(request)

profile = self.session.query(Profile).get(1)
Expand All @@ -233,18 +223,6 @@ def test_create_user(self):
self.assertEqual(float(profile.salary), float(23))
self.assertEqual(profile.user.id, 1)

delete_fileobj(Profile, profile, "photo")

self.session.delete(profile)
user = self.session.query(User).get(1)
self.session.delete(user)
if self.zope:
transaction.commit()
else:
self.session.commit()

self.assertEqual(delete_fileobj(Profile, profile, "photo"), None)

def test_create_with_relation(self):
# Create groups (M2M example)
request = {}
Expand Down Expand Up @@ -366,11 +344,6 @@ def test_update_profile(self):
request["salary"] = ["23.0", ]
request["user_id"] = ["2", ]

upload = MockCGIFieldStorage()
upload.file = StringIO(u'foo')
upload.filename = 'foo.html'
request["photo"] = [upload, ]

CRUD(self.session, Profile).update(pk={'id': profile.id}, data=request)
profile = self.session.query(Profile).get(profile.id)

Expand Down Expand Up @@ -444,20 +417,12 @@ def test_delete_user(self):
request["salary"] = ["23.0", ]
request["user_id"] = ["1", ]

upload = MockCGIFieldStorage()
upload.file = StringIO(u'foo')
upload.filename = 'foo.html'
request["photo"] = [upload, ]

user = CRUD(self.session, Profile).create(request)
profile = CRUD(self.session, Profile).delete({'id': user.id})

profile = self.session.query(Profile).get(profile['pk']['id'])
self.assertEqual(profile, None)

# check file also deleted
self.assertEqual(glob.glob("%s/*.html" % (PHOTO_PATH, )), [])

def test_delete_no_commit(self):
user = self._add_item(User, 'Vasya', 'Pupkin', "123")
user = self.session.query(User).get(user.id)
Expand Down
139 changes: 0 additions & 139 deletions sacrud/tests/test_exttype.py

This file was deleted.

0 comments on commit dfe2e26

Please sign in to comment.