本文整理汇总了Python中core.Core.set_test_user方法的典型用法代码示例。如果您正苦于以下问题:Python Core.set_test_user方法的具体用法?Python Core.set_test_user怎么用?Python Core.set_test_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类core.Core
的用法示例。
在下文中一共展示了Core.set_test_user方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import set_test_user [as 别名]
def handle(self, *args, **kwargs):
randomCompanyIdentifier = str(int(random.random() * 99999))
company, user = createNewCustomer(
"Ledere",
"Bjarte Hatlenes",
"superadmin" + randomCompanyIdentifier,
"superadmin" + randomCompanyIdentifier,
"Ansatte",
"Focus Security AS" + randomCompanyIdentifier,
)
self.company = company
self.user = user
Core.set_test_user(user)
password = generate_new_password_for_user(user)
print "Company: %s " % company
print "Current user is: %s " % Core.current_user()
print "Current user is: %s " % Core.current_user().username
print "Current users password: %s " % password
self.customers = []
self.projects = []
self.seed_customers()
self.seed_contacts()
self.seed_projects()
self.seed_orders()
self.seed_offers()
self.seed_tickets()
self.seed_suppliers()
self.seed_products()
示例2: setUp
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import set_test_user [as 别名]
def setUp(self):
self.group1 = Group.objects.get_or_create(name="group1")[0]
company = Company.objects.get_or_create(name="TestFirma", admin_group = self.group1)[0]
self.user1 = User.objects.get_or_create(username="testbruker", company=company)[0]
self.user2 = User.objects.get_or_create(username="testbruker2", company=company)[0]
self.user3 = User.objects.get_or_create(username="testbruker3", company=company)[0]
Core.set_test_user(self.user1)
self.contact1 = Contact.objects.get_or_create(name="Customer1")[0]
self.group1.add_member(self.user2)
示例3: setUp
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import set_test_user [as 别名]
def setUp(self):
self.user1 = User.objects.get_or_create(username="test")[0]
self.user2 = User.objects.get_or_create(username="test2", company=self.user1.get_company())[0]
self.user3 = User.objects.get_or_create(username="test3", company=self.user1.get_company())[0]
Core.set_test_user(self.user3)
self.customer1 = Customer.objects.get_or_create(name="Customer1", cid=1)[0]
self.customer2 = Customer.objects.get_or_create(name="Customer2", cid=2)[0]
self.group1 = Group.objects.get_or_create(name="group1")[0]
self.group2 = Group.objects.get_or_create(name="group2")[0]
self.role_admin = Role.objects.get_or_create(name="Admin")[0]
self.role_member = Role.objects.get_or_create(name="Member")[0]
cache.clear()
示例4: handle
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import set_test_user [as 别名]
def handle(self, *apps, **options):
print "======================================================="
print "Connecting to database..."
cursor = self.connect_database()
print "Connection established!"
randomCompanyIdentifier = str(int(random.random() * 99999))
company, user = createNewCustomer("Ledere", "Bjarte Hatlenes", "superadmin",
"superadmin" + randomCompanyIdentifier, "Ansatte",
"Focus Security AS")
Core.set_test_user(user)
password = generate_new_password_for_user(user)
print "Company: %s " % company
print "Current user is: %s " % Core.current_user()
print "Current user is: %s " % Core.current_user().username
print "Current users password: %s " % password
users = self.migrate_users(company, cursor, randomCompanyIdentifier)
contacts = self.migrate_contacts(cursor)
self.migrate_customers(cursor, contacts)
#SKIP
#self.migrate_projects(company, cursor, users, contacts)
#orders = self.migrate_orders(company, cursor, users)
#self.migrate_timetracking(cursor, users, orders)
#Set test user again
Core.set_test_user(user)
suppliers = self.migrate_suppliers(cursor)
productcategories = self.migrate_product_categories(cursor)
productgroups = self.migrate_product_groups(cursor, productcategories)
self.migrate_products(cursor, productgroups, suppliers)
print "Done!"
示例5: migrate_timetracking
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import set_test_user [as 别名]
def migrate_timetracking(self, cursor, users, orders):
print "Migrating timetracking"
cursor.execute("SELECT * FROM timereg")
timetrackings = []
for cu in cursor.fetchall():
user = findElementByOldID(users, str(cu['brukerid']))
Core.set_test_user(user)
if(len(timetrackings) % 150 == 0):
print len(timetrackings)
o = HourRegistration()
o.order = findElementByOldID(orders, str(cu['ordrenr']))
if(cu['date']):
o.date = cu['date']
o.time_start = "08:00"
end_time = datetime.strptime("2010-10-10 08:00:00", "%Y-%m-%d %H:%M:%S") + timedelta(
hours=(float((cu['antalltimer_totalt'].decode("latin1")))))
o.time_end = end_time.strftime("%H:%M")
try:
o.description = cu['beskrivelse_time'].decode("latin1")
except:
pass
try:
o.save()
timetrackings.append(o)
except:
pass
print "Done migrating timetracking"
return timetrackings
示例6: get_new_emails
# 需要导入模块: from core import Core [as 别名]
# 或者: from core.Core import set_test_user [as 别名]
def get_new_emails(self):
import poplib
import string
import email
for company in Company.objects.all():
if company.admin_group and company.email_host and company.email_password and company.email_username:
print company.email_host
Core.set_test_user(company.admin_group.members.all()[0])
M = poplib.POP3(company.email_host)
M.user(company.email_username)
M.pass_(company.email_password)
numMessages = len(M.list()[1])
print numMessages
for i in range(numMessages):
print "=" * 40
msg = M.retr(i + 1)
M.dele(i + 1)
str = string.join(msg[1], "\n")
str = re.sub(r"\r(?!=\n)", "\r\n", str)
mail = email.message_from_string((str))
email_address = ""
for text, encoding in decode_header(mail["From"]):
if encoding:
email_address += text.decode(encoding)
else:
email_address += text
address_start = email_address.find("<") + 1
address_end = email_address.find(">")
email_address = email_address[address_start:address_end]
subject = mail["Subject"]
k = 3
for index in [m.start() for m in re.finditer("\_" + "\?=", subject)]:
subject = subject[: index + k] + " " + subject[index + k :]
k += 1
decoded = decode_header(subject)
s = ""
for text, encoding in decoded:
if encoding:
s += text.decode(encoding)
else:
s += text
subject = s
if mail.is_multipart():
content = mail.get_payload(0).get_payload()
else:
content = mail.get_payload()
ticketClient, created = ClientUser.objects.get_or_create(email=email_address)
if created:
password = ticketClient.generate_password()
ticketClient.set_password(password)
message = """Hei. Takk for din henvendelse. \n Vi har opprettet en sak hos oss.
Du kan følge progresjon og komme med kommenterer ved å logge inn på %s
Bruk din epostadresse og passordet: %s
""" % (
settings.CLIENT_LOGIN_SITE,
password,
)
else:
message = """Hei. Takk for din henvendelse. \n Vi har opprettet en sak hos oss.
Du kan følge progresjon og komme med kommenterer ved å logge inn på %s
""" % (
settings.CLIENT_LOGIN_SITE
)
send_mail("Din henvendelse er registrert", message, settings.NO_REPLY_EMAIL, [email_address])
ticket = Ticket()
ticket.title = subject
encoding = "utf-8"
if "text/plain" in mail["Content-Type"]:
encoding = "latin1"
ticket.description = content.decode(encoding).strip()
ticket.description = ticket.description.replace("=F8", u"ø")
#.........这里部分代码省略.........