本文整理汇总了Python中treeio.identities.models.ContactType.set_default_user方法的典型用法代码示例。如果您正苦于以下问题:Python ContactType.set_default_user方法的具体用法?Python ContactType.set_default_user怎么用?Python ContactType.set_default_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treeio.identities.models.ContactType
的用法示例。
在下文中一共展示了ContactType.set_default_user方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FinanceAPITest
# 需要导入模块: from treeio.identities.models import ContactType [as 别名]
# 或者: from treeio.identities.models.ContactType import set_default_user [as 别名]
class FinanceAPITest(TestCase):
"Finance api tests"
username = "api_test"
password = "api_password"
prepared = False
authentication_headers = {"CONTENT_TYPE": "application/json",
"HTTP_AUTHORIZATION": "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk"}
content_type = 'application/json'
def setUp(self):
"Initial Setup"
if not self.prepared:
# Clean up first
Object.objects.all().delete()
User.objects.all().delete()
# Create objects
try:
self.group = Group.objects.get(name='test')
except Group.DoesNotExist:
Group.objects.all().delete()
self.group = Group(name='test')
self.group.save()
try:
self.user = DjangoUser.objects.get(username=self.username)
self.user.set_password(self.password)
try:
self.profile = self.user.get_profile()
except Exception:
User.objects.all().delete()
self.user = DjangoUser(username=self.username, password='')
self.user.set_password(self.password)
self.user.save()
except DjangoUser.DoesNotExist:
User.objects.all().delete()
self.user = DjangoUser(username=self.username, password='')
self.user.set_password(self.password)
self.user.save()
try:
perspective = Perspective.objects.get(name='default')
except Perspective.DoesNotExist:
Perspective.objects.all().delete()
perspective = Perspective(name='default')
perspective.set_default_user()
perspective.save()
ModuleSetting.set('default_perspective', perspective.id)
self.contact_type = ContactType(name='test')
self.contact_type.set_default_user()
self.contact_type.save()
self.contact = Contact(name='test', contact_type=self.contact_type)
self.contact.set_default_user()
self.contact.save()
self.category = Category(name='test')
self.category.set_default_user()
self.category.save()
self.equity = Equity(
issue_price=10, sell_price=10, issuer=self.contact, owner=self.contact)
self.equity.set_default_user()
self.equity.save()
self.asset = Asset(name='test', owner=self.contact)
self.asset.set_default_user()
self.asset.save()
self.tax = Tax(name='test', rate=10)
self.tax.set_default_user()
self.tax.save()
self.currency = Currency(code="GBP",
name="Pounds",
symbol="L",
is_default=True)
self.currency.set_default_user()
self.currency.save()
self.account = Account(
name='test', owner=self.contact, balance_currency=self.currency)
self.account.set_default_user()
self.account.save()
self.liability = Liability(name='test',
source=self.contact,
target=self.contact,
account=self.account,
value=10,
value_currency=self.currency)
self.liability.set_default_user()
self.liability.save()
self.transaction = Transaction(name='test', account=self.account, source=self.contact,
target=self.contact, value=10, value_currency=self.currency)
self.transaction.set_default_user()
self.transaction.save()
#.........这里部分代码省略.........
示例2: FinanceViewsTest
# 需要导入模块: from treeio.identities.models import ContactType [as 别名]
# 或者: from treeio.identities.models.ContactType import set_default_user [as 别名]
class FinanceViewsTest(TestCase):
"Finance functional tests for views"
username = "test"
password = "password"
prepared = False
def setUp(self):
"Initial Setup"
if not self.prepared:
# Clean up first
Object.objects.all().delete()
User.objects.all().delete()
# Create objects
self.group, created = Group.objects.get_or_create(name='test')
duser, created = DjangoUser.objects.get_or_create(
username=self.username)
duser.set_password(self.password)
duser.save()
self.user, created = User.objects.get_or_create(user=duser)
self.user.save()
perspective, created = Perspective.objects.get_or_create(
name='default')
perspective.set_default_user()
perspective.save()
ModuleSetting.set('default_perspective', perspective.id)
self.contact_type = ContactType(name='test')
self.contact_type.set_default_user()
self.contact_type.save()
self.contact = Contact(name='test', contact_type=self.contact_type)
self.contact.set_default_user()
self.contact.save()
self.category = Category(name='test')
self.category.set_default_user()
self.category.save()
self.equity = Equity(
issue_price=10, sell_price=10, issuer=self.contact, owner=self.contact)
self.equity.set_default_user()
self.equity.save()
self.asset = Asset(name='test', owner=self.contact)
self.asset.set_default_user()
self.asset.save()
self.tax = Tax(name='test', rate=10)
self.tax.set_default_user()
self.tax.save()
self.currency = Currency(code="GBP",
name="Pounds",
symbol="L",
is_default=True)
self.currency.set_default_user()
self.currency.save()
self.account = Account(
name='test', owner=self.contact, balance_currency=self.currency)
self.account.set_default_user()
self.account.save()
self.liability = Liability(name='test',
source=self.contact,
target=self.contact,
account=self.account,
value=10,
value_currency=self.currency)
self.liability.set_default_user()
self.liability.save()
self.transaction = Transaction(name='test', account=self.account, source=self.contact,
target=self.contact, value=10, value_currency=self.currency)
self.transaction.set_default_user()
self.transaction.save()
self.client = Client()
self.prepared = True
######################################
# Testing views when user is logged in
######################################
def test_finance_login(self):
"Test index page with login at /finance/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('finance'))
self.assertEquals(response.status_code, 200)
def test_finance_index_login(self):
"Test index page with login at /finance/index/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
#.........这里部分代码省略.........
示例3: ProjectsAPITest
# 需要导入模块: from treeio.identities.models import ContactType [as 别名]
# 或者: from treeio.identities.models.ContactType import set_default_user [as 别名]
class ProjectsAPITest(TestCase):
"Projects functional tests for api"
username = "api_test"
password = "api_password"
prepared = False
authentication_headers = {"CONTENT_TYPE": "application/json",
"HTTP_AUTHORIZATION": "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk"}
content_type = 'application/json'
def setUp(self):
"Initial Setup"
if not self.prepared:
# Clean up first
Object.objects.all().delete()
User.objects.all().delete()
# Create objects
try:
self.group = Group.objects.get(name='api_test')
except Group.DoesNotExist:
Group.objects.all().delete()
self.group = Group(name='api_test')
self.group.save()
try:
self.user = DjangoUser.objects.get(username=self.username)
self.user.set_password(self.password)
try:
self.profile = self.user.get_profile()
except Exception:
User.objects.all().delete()
self.user = DjangoUser(username=self.username, password='')
self.user.set_password(self.password)
self.user.save()
except DjangoUser.DoesNotExist:
User.objects.all().delete()
self.user = DjangoUser(username=self.username, password='')
self.user.set_password(self.password)
self.user.save()
try:
perspective = Perspective.objects.get(name='default')
except Perspective.DoesNotExist:
Perspective.objects.all().delete()
perspective = Perspective(name='default')
perspective.set_default_user()
perspective.save()
ModuleSetting.set('default_perspective', perspective.id)
self.contact_type = ContactType(name='api_test')
self.contact_type.set_default_user()
self.contact_type.save()
self.contact = Contact(
name='api_test', contact_type=self.contact_type)
self.contact.set_default_user()
self.contact.save()
self.project = Project(
name='api_test', manager=self.contact, client=self.contact)
self.project.set_default_user()
self.project.save()
self.status = TaskStatus(name='api_test')
self.status.set_default_user()
self.status.save()
self.milestone = Milestone(
name='api_test', project=self.project, status=self.status)
self.milestone.set_default_user()
self.milestone.save()
self.task = Task(
name='api_test', project=self.project, status=self.status, priority=3)
self.task.set_default_user()
self.task.save()
self.time_slot = TaskTimeSlot(
task=self.task, details='api_test', time_from=datetime.now(), user=self.user.get_profile())
self.time_slot.set_default_user()
self.time_slot.save()
self.parent = Project(name='api_test')
self.parent.set_default_user()
self.parent.save()
self.parent_task = Task(
name='api_test', project=self.project, status=self.status, priority=3)
self.parent_task.set_default_user()
self.parent_task.save()
self.client = Client()
self.prepared = True
def test_unauthenticated_access(self):
#.........这里部分代码省略.........
示例4: MessagingApiTest
# 需要导入模块: from treeio.identities.models import ContactType [as 别名]
# 或者: from treeio.identities.models.ContactType import set_default_user [as 别名]
class MessagingApiTest(TestCase):
"Messaging functional tests for api"
username = "api_test"
password = "api_password"
prepared = False
authentication_headers ={"CONTENT_TYPE": "application/json",
"HTTP_AUTHORIZATION" : "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk" }
content_type ='application/json'
def setUp(self):
"Initial Setup"
if not self.prepared:
# Clean up first
Object.objects.all().delete()
# Create objects
try:
self.group = Group.objects.get(name='test')
except Group.DoesNotExist:
Group.objects.all().delete()
self.group = Group(name='test')
self.group.save()
try:
self.user = DjangoUser.objects.get(username=self.username)
self.user.set_password(self.password)
try:
self.profile = self.user.get_profile()
except Exception:
User.objects.all().delete()
self.user = DjangoUser(username=self.username, password='')
self.user.set_password(self.password)
self.user.save()
except DjangoUser.DoesNotExist:
User.objects.all().delete()
self.user = DjangoUser(username=self.username, password='')
self.user.set_password(self.password)
self.user.save()
try:
perspective = Perspective.objects.get(name='default')
except Perspective.DoesNotExist:
Perspective.objects.all().delete()
perspective = Perspective(name='default')
perspective.set_default_user()
perspective.save()
ModuleSetting.set('default_perspective', perspective.id)
self.contact_type = ContactType(name='test')
self.contact_type.set_default_user()
self.contact_type.save()
self.contact = Contact(name='test', contact_type=self.contact_type)
self.contact.set_default_user()
self.contact.save()
self.user_contact = Contact(name='test', related_user=self.user.get_profile(), contact_type=self.contact_type)
self.user_contact.set_user(self.user)
self.user_contact.save()
self.stream = MessageStream(name='test')
self.stream.set_default_user()
self.stream.save()
self.mlist = MailingList(name='test', from_contact=self.contact)
self.mlist.set_default_user()
self.mlist.save()
self.message = Message(title='test', body='test', author=self.contact, stream=self.stream)
self.message.set_default_user()
self.message.save()
self.client = Client()
self.prepared = True
def test_unauthenticated_access(self):
"Test index page at /api/messaging/mlist"
response = self.client.get('/api/messaging/mlist')
# Redirects as unauthenticated
self.assertEquals(response.status_code, 401)
def test_get_mlist(self):
""" Test index page api/messaging/mlist """
response = self.client.get(path=reverse('api_messaging_mlist'), **self.authentication_headers)
self.assertEquals(response.status_code, 200)
def test_get_one_mlist(self):
response = self.client.get(path=reverse('api_messaging_mlist', kwargs={'object_ptr': self.mlist.id}), **self.authentication_headers)
self.assertEquals(response.status_code, 200)
def test_update_mlist(self):
updates = {"name": "API mailing list", "description": "API description update", "from_contact": self.contact.id,
"members": [self.contact.id,]}
response = self.client.put(path=reverse('api_messaging_mlist', kwargs={'object_ptr': self.mlist.id}),
content_type=self.content_type, data=json.dumps(updates), **self.authentication_headers)
self.assertEquals(response.status_code, 200)
#.........这里部分代码省略.........
示例5: ServicesViewsTest
# 需要导入模块: from treeio.identities.models import ContactType [as 别名]
# 或者: from treeio.identities.models.ContactType import set_default_user [as 别名]
class ServicesViewsTest(TestCase):
"Services functional tests for api"
username = "api_test"
password = "api_password"
prepared = False
authentication_headers = {
"CONTENT_TYPE": "application/json",
"HTTP_AUTHORIZATION": "Basic YXBpX3Rlc3Q6YXBpX3Bhc3N3b3Jk",
}
content_type = "application/json"
prepared = False
def setUp(self):
"Initial Setup"
if not self.prepared:
# Clean up first
Object.objects.all().delete()
User.objects.all().delete()
# Create objects
try:
self.group = Group.objects.get(name="test")
except Group.DoesNotExist:
Group.objects.all().delete()
self.group = Group(name="test")
self.group.save()
try:
self.user = DjangoUser.objects.get(username=self.username)
self.user.set_password(self.password)
try:
self.profile = self.user.get_profile()
except Exception:
User.objects.all().delete()
self.user = DjangoUser(username=self.username, password="")
self.user.set_password(self.password)
self.user.save()
except DjangoUser.DoesNotExist:
User.objects.all().delete()
self.user = DjangoUser(username=self.username, password="")
self.user.set_password(self.password)
self.user.save()
try:
perspective = Perspective.objects.get(name="default")
except Perspective.DoesNotExist:
Perspective.objects.all().delete()
perspective = Perspective(name="default")
perspective.set_user(self.user.get_profile())
perspective.save()
ModuleSetting.set("default_perspective", perspective.id)
self.contact_type = ContactType(name="test")
self.contact_type.set_default_user()
self.contact_type.save()
self.contact = Contact(name="test", contact_type=self.contact_type)
self.contact.set_default_user()
self.contact.save()
self.status = TicketStatus(name="TestStatus")
self.status.set_default_user()
self.status.save()
self.queue = TicketQueue(name="TestQueue", default_ticket_status=self.status)
self.queue.set_default_user()
self.queue.save()
self.ticket = Ticket(name="TestTicket", status=self.status, queue=self.queue)
self.ticket.set_default_user()
self.ticket.save()
self.agent = ServiceAgent(
related_user=self.user.get_profile(), available_from=datetime.time(9), available_to=datetime.time(17)
)
self.agent.set_default_user()
self.agent.save()
self.service = Service(name="test")
self.service.set_default_user()
self.service.save()
self.sla = ServiceLevelAgreement(
name="test", service=self.service, client=self.contact, provider=self.contact
)
self.sla.set_default_user()
self.sla.save()
self.client = Client()
self.prepared = True
def test_unauthenticated_access(self):
"Test index page at /api/services/services"
response = self.client.get("/api/services/services")
# Redirects as unauthenticated
#.........这里部分代码省略.........
示例6: IdentitiesViewsTest
# 需要导入模块: from treeio.identities.models import ContactType [as 别名]
# 或者: from treeio.identities.models.ContactType import set_default_user [as 别名]
class IdentitiesViewsTest(TestCase):
"Identities View tests"
username = "test"
password = "password"
prepared = False
def setUp(self):
"Initial Setup"
if not self.prepared:
# Clean up first
Object.objects.all().delete()
# Create objects
self.group, created = Group.objects.get_or_create(name='test')
duser, created = DjangoUser.objects.get_or_create(username=self.username)
duser.set_password(self.password)
duser.save()
self.user, created = User.objects.get_or_create(user=duser)
self.user.save()
perspective, created = Perspective.objects.get_or_create(name='default')
perspective.set_default_user()
perspective.save()
ModuleSetting.set('default_perspective', perspective.id)
self.contact_type = ContactType(name='Person')
self.contact_type.set_default_user()
self.contact_type.save()
self.contact = Contact(name='Test', contact_type=self.contact_type)
self.contact.set_default_user()
self.contact.save()
self.field = ContactField(name='Test', label='test', field_type='text')
self.field.set_default_user()
self.field.save()
self.client = Client()
self.prepared = True
######################################
# Testing views when user is logged in
######################################
def test_index_login(self):
"Test index page with login at /contacts/"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_index'))
self.assertEquals(response.status_code, 200)
def test_contact_users_login(self):
"Test page with login at /contacts/users/"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_index_users'))
self.assertEquals(response.status_code, 200)
def test_contact_groups_login(self):
"Test page with login at /contacts/groups/"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_index_groups'))
self.assertEquals(response.status_code, 200)
# Contact types
def test_contact_type_add(self):
"Test page with login at /contacts/types/add/"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_type_add'))
self.assertEquals(response.status_code, 200)
def test_contact_type_view(self):
"Test page with login at /contacts/type/view/(?P<type_id>\d+)"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_type_view', args=[self.contact_type.id]))
self.assertEquals(response.status_code, 200)
def test_contact_type_edit(self):
"Test page with login at /contacts/type/edit/(?P<type_id>\d+)"
response = self.client.post('/accounts/login', {'username': self.username,
'password': self.password })
self.assertRedirects(response, '/')
response = self.client.get(reverse('identities_type_edit', args=[self.contact_type.id]))
self.assertEquals(response.status_code, 200)
#.........这里部分代码省略.........
示例7: MessagingViewsTest
# 需要导入模块: from treeio.identities.models import ContactType [as 别名]
# 或者: from treeio.identities.models.ContactType import set_default_user [as 别名]
class MessagingViewsTest(TestCase):
"Messaging functional tests for views"
username = "test"
password = "password"
prepared = False
def setUp(self):
"Initial Setup"
if not self.prepared:
self.group, created = Group.objects.get_or_create(name='test')
duser, created = DjangoUser.objects.get_or_create(
username=self.username)
duser.set_password(self.password)
duser.save()
self.user, created = User.objects.get_or_create(user=duser)
self.user.save()
perspective, created = Perspective.objects.get_or_create(
name='default')
perspective.set_default_user()
perspective.save()
ModuleSetting.set('default_perspective', perspective.id)
self.contact_type = ContactType(name='test')
self.contact_type.set_default_user()
self.contact_type.save()
self.contact = Contact(name='test', contact_type=self.contact_type)
self.contact.set_default_user()
self.contact.save()
self.stream = MessageStream(name='test')
self.stream.set_default_user()
self.stream.save()
self.message = Message(
title='test', body='test', author=self.contact, stream=self.stream)
self.message.set_default_user()
self.message.save()
self.client = Client()
self.prepared = True
######################################
# Testing views when user is logged in
######################################
def test_message_index_login(self):
"Test index page with login at /messaging/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('messaging'))
self.assertEquals(response.status_code, 200)
def test_message_index_sent(self):
"Test index page with login at /messaging/sent/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('messaging_sent'))
self.assertEquals(response.status_code, 200)
def test_message_index_inbox(self):
"Test index page with login at /messaging/inbox/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('messaging_inbox'))
self.assertEquals(response.status_code, 200)
def test_message_index_unread(self):
"Test index page with login at /messaging/unread/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('messaging_unread'))
self.assertEquals(response.status_code, 200)
# Messages
def test_message_compose_login(self):
"Test index page with login at /message/compose/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('messaging_message_compose'))
self.assertEquals(response.status_code, 200)
def test_message_view_login(self):
"Test index page with login at /message/view/<message_id>"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(
reverse('messaging_message_view', args=[self.message.id]))
self.assertEquals(response.status_code, 200)
def test_message_delete_login(self):
#.........这里部分代码省略.........
示例8: ServicesViewsTest
# 需要导入模块: from treeio.identities.models import ContactType [as 别名]
# 或者: from treeio.identities.models.ContactType import set_default_user [as 别名]
class ServicesViewsTest(TestCase):
"Services functional tests for views"
username = "test"
password = "password"
prepared = False
def setUp(self):
"Initial Setup"
if not self.prepared:
# Clean up first
Object.objects.all().delete()
User.objects.all().delete()
# Create objects
self.group, created = Group.objects.get_or_create(name='test')
duser, created = DjangoUser.objects.get_or_create(
username=self.username)
duser.set_password(self.password)
duser.save()
self.user, created = User.objects.get_or_create(user=duser)
self.user.save()
perspective, created = Perspective.objects.get_or_create(
name='default')
perspective.set_default_user()
perspective.save()
ModuleSetting.set('default_perspective', perspective.id)
self.contact_type = ContactType(name='test')
self.contact_type.set_default_user()
self.contact_type.save()
self.contact = Contact(name='test', contact_type=self.contact_type)
self.contact.set_default_user()
self.contact.save()
self.status = TicketStatus(name='TestStatus')
self.status.set_default_user()
self.status.save()
self.queue = TicketQueue(
name='TestQueue', default_ticket_status=self.status)
self.queue.set_default_user()
self.queue.save()
self.ticket = Ticket(
name='TestTicket', status=self.status, queue=self.queue)
self.ticket.set_default_user()
self.ticket.save()
self.agent = ServiceAgent(related_user=self.user, available_from=datetime.time(9),
available_to=datetime.time(17))
self.agent.set_default_user()
self.agent.save()
self.service = Service(name='test')
self.service.set_default_user()
self.service.save()
self.sla = ServiceLevelAgreement(name='test', service=self.service,
client=self.contact, provider=self.contact)
self.sla.set_default_user()
self.sla.save()
self.client = Client()
self.prepared = True
######################################
# Testing views when user is logged in
######################################
def test_index_login(self):
"Test index page with login at /services/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('services'))
self.assertEquals(response.status_code, 200)
def test_index_owned(self):
"Test index page with login at /services/owned"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('services_index_owned'))
self.assertEquals(response.status_code, 200)
def test_index_assigned(self):
"Test index page with login at /services/assigned"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password})
self.assertRedirects(response, '/')
response = self.client.get(reverse('services_index_assigned'))
self.assertEquals(response.status_code, 200)
# Queues
#.........这里部分代码省略.........
示例9: ProjectsViewsTest
# 需要导入模块: from treeio.identities.models import ContactType [as 别名]
# 或者: from treeio.identities.models.ContactType import set_default_user [as 别名]
class ProjectsViewsTest(TestCase):
"Projects functional tests for views"
username = "test"
password = "password"
prepared = False
def setUp(self):
"Initial Setup"
if not self.prepared:
# Clean up first
Object.objects.all().delete()
User.objects.all().delete()
# Create objects
try:
self.group = Group.objects.get(name='test')
except Group.DoesNotExist:
Group.objects.all().delete()
self.group = Group(name='test')
self.group.save()
try:
self.user = DjangoUser.objects.get(username=self.username)
self.user.set_password(self.password)
try:
self.profile = self.user.get_profile()
except Exception:
User.objects.all().delete()
self.user = DjangoUser(username=self.username, password='')
self.user.set_password(self.password)
self.user.save()
except DjangoUser.DoesNotExist:
User.objects.all().delete()
self.user = DjangoUser(username=self.username, password='')
self.user.set_password(self.password)
self.user.save()
try:
perspective = Perspective.objects.get(name='default')
except Perspective.DoesNotExist:
Perspective.objects.all().delete()
perspective = Perspective(name='default')
perspective.set_default_user()
perspective.save()
ModuleSetting.set('default_perspective', perspective.id)
self.contact_type = ContactType(name='test')
self.contact_type.set_default_user()
self.contact_type.save()
self.contact = Contact(name='test', contact_type=self.contact_type)
self.contact.set_default_user()
self.contact.save()
self.project = Project(name='test', manager=self.contact, client=self.contact)
self.project.set_default_user()
self.project.save()
self.status = TaskStatus(name='test')
self.status.set_default_user()
self.status.save()
self.milestone = Milestone(name='test', project=self.project, status=self.status)
self.milestone.set_default_user()
self.milestone.save()
self.task = Task(name='test', project=self.project, status=self.status, priority=3)
self.task.set_default_user()
self.task.save()
self.time_slot = TaskTimeSlot(task=self.task, details='test', time_from=datetime.now(), user=self.user.get_profile())
self.time_slot.set_default_user()
self.time_slot.save()
self.parent = Project(name='test')
self.parent.set_default_user()
self.parent.save()
self.parent_task = Task(name='test', project=self.project, status=self.status, priority=3)
self.parent_task.set_default_user()
self.parent_task.save()
self.client = Client()
self.prepared = True
######################################
# Testing views when user is logged in
######################################
def test_index_login(self):
"Test index page with login at /projects/"
response = self.client.post('/accounts/login',
{'username': self.username, 'password': self.password })
self.assertRedirects(response, '/')
#.........这里部分代码省略.........
示例10: ProjectsViewsTest
# 需要导入模块: from treeio.identities.models import ContactType [as 别名]
# 或者: from treeio.identities.models.ContactType import set_default_user [as 别名]
class ProjectsViewsTest(TestCase):
"Projects functional tests for views"
username = "test"
password = "password"
prepared = False
def setUp(self):
"Initial Setup"
if not self.prepared:
# Clean up first
Object.objects.all().delete()
User.objects.all().delete()
# Create objects
self.group, created = Group.objects.get_or_create(name="test")
duser, created = DjangoUser.objects.get_or_create(username=self.username)
duser.set_password(self.password)
duser.save()
self.user, created = User.objects.get_or_create(user=duser)
self.user.save()
perspective, created = Perspective.objects.get_or_create(name="default")
perspective.set_default_user()
perspective.save()
ModuleSetting.set("default_perspective", perspective.id)
self.contact_type = ContactType(name="test")
self.contact_type.set_default_user()
self.contact_type.save()
self.contact = Contact(name="test", contact_type=self.contact_type)
self.contact.set_default_user()
self.contact.save()
self.project = Project(name="test", manager=self.contact, client=self.contact)
self.project.set_default_user()
self.project.save()
self.status = TaskStatus(name="test")
self.status.set_default_user()
self.status.save()
self.milestone = Milestone(name="test", project=self.project, status=self.status)
self.milestone.set_default_user()
self.milestone.save()
self.task = Task(name="test", project=self.project, status=self.status, priority=3)
self.task.set_default_user()
self.task.save()
self.time_slot = TaskTimeSlot(task=self.task, details="test", time_from=datetime.now(), user=self.user)
self.time_slot.set_default_user()
self.time_slot.save()
self.parent = Project(name="test")
self.parent.set_default_user()
self.parent.save()
self.parent_task = Task(name="test", project=self.project, status=self.status, priority=3)
self.parent_task.set_default_user()
self.parent_task.save()
self.client = Client()
self.prepared = True
######################################
# Testing views when user is logged in
######################################
def test_index_login(self):
"Test index page with login at /projects/"
response = self.client.post("/accounts/login", {"username": self.username, "password": self.password})
self.assertRedirects(response, "/")
response = self.client.get(reverse("projects"))
self.assertEquals(response.status_code, 200)
# Projects
def test_project_add(self):
"Test index page with login at /projects/add/"
response = self.client.post("/accounts/login", {"username": self.username, "password": self.password})
self.assertRedirects(response, "/")
response = self.client.get(reverse("project_add"))
self.assertEquals(response.status_code, 200)
def test_project_add_typed(self):
"Test index page with login at /projects/add/<project_id>/"
response = self.client.post("/accounts/login", {"username": self.username, "password": self.password})
self.assertRedirects(response, "/")
response = self.client.get(reverse("projects_project_add_typed", args=[self.parent.id]))
self.assertEquals(response.status_code, 200)
def test_project_view_login(self):
"Test index page with login at /projects/view/<project_id>"
response = self.client.post("/accounts/login", {"username": self.username, "password": self.password})
self.assertRedirects(response, "/")
response = self.client.get(reverse("projects_project_view", args=[self.project.id]))
#.........这里部分代码省略.........