Im benim Django projede bazı birim test yapıyor ve ben bu testi çalıştırdığınızda hatayı
"AttributeError: 'SignUp' object has no attribute 'email'"
alıyorum vardır.AttributeError: 'AcceptInvite' nesne hiçbir özellik 'e'
def test_signup(self):
response = self.c.post('/accounts/signup/', {'email': '[email protected]', 'password': 'test123', 'password_conf': 'test123',
'org_name': 'test org', 'org_username': 'test org username', 'invite': '4013'})
code = response.status_code
self.assertTrue(code == 200)
Bu sınama görüntüleniyor, sadece kayıt formunu alıyor ve onunla yeni bir hesap oluşturur.
def signup(request):
# """Register a new account with a new org."""
if request.method == "POST":
form = SignUp(request.POST)
if not form.email or not form.password:
raise Exception("Email and Password are required")
if form.password != form.password_conf:
raise Exception("Password does not match confirmation")
if not form.org_name or not form.org_username:
raise Exception('Organization name and username are required')
if not form.invite:
raise Exception('Invitation code is required')
if form.is_valid():
cleaned_data = form.cleaned_data
email = cleaned_data['email']
password = cleaned_data['password']
org_name = cleaned_data['org_name']
org_username = cleaned_data['org_username']
invite_token = cleaned_data['invite']
invitation = OrgInvite.objects.get(token=invite_token)
if invitation.used:
raise Exception("invitation code is invalid")
account = Account(email=email, password=password)
account.save()
org = Org(org_name=org_name, org_username=org_username)
org.save()
invitation.used = False
invitation.save()
login(request)
# Send Email
md = mandrill.Mandrill(settings.MANDRILL_API_KEY)
t = invite_token.replace(' ', '+')
url = "https://www.humanlink.co/verify/{}".format(t)
message = {
'global_merge_vars': [
{'name': 'VERIFICATION_URL', 'content': url},
],
'to': [
{'email': account.email},
],
}
message['from_name'] = message.get('from_name', 'Humanlink')
message['from_email'] = message.get('from_email', '[email protected]')
try:
md.messages.send_template(
template_name='humanlink-welcome', message=message,
template_content=[], async=True)
except mandrill.Error as e:
logging.exception(e)
raise Exception('Unknown service exception')
Kayıt formu email alanı vardır ve request.POST veriler benim Müşterinin sonrası yöntemi benim birim sınama kullanılmakta olan gönderiyorum e sahip olmalıdır, bu yüzden gerçekten neden bunu emin değilim hala bir 'e-posta' özelliği olmazdı.
Form:
class SignUp(forms.Form):
email = forms.EmailField()
password = forms.CharField()
password_conf = forms.CharField()
org_name = forms.CharField()
org_username = forms.CharField()
invite = forms.CharField()
Çözümünüz sorunu çözdü. Teşekkür ederim Shang. – JBT