Bugfix: handle users that has never logged into

Regression introduced by 669600f4da
This commit is contained in:
Santiago Lamora 2020-01-14 13:50:17 +01:00
parent 34faf13dc6
commit 160e0b059f
3 changed files with 30 additions and 0 deletions

View File

@ -107,6 +107,7 @@ class UserAccount(OrchestraModel):
@classmethod
def new_from_json(cls, data, **kwargs):
billing = None
last_login = None
if 'billcontact' in data:
billing = BillingContact.new_from_json(data['billcontact'])

View File

@ -4,7 +4,11 @@
{% block content %}
<h2>{% trans "Welcome back" %} <strong>{{ profile.username }}</strong></h2>
{% if profile.last_login %}
<p>{% blocktrans with last_login=profile.last_login|date:"SHORT_DATE_FORMAT" %}Last time you logged in was: {{ last_login }}{% endblocktrans %}</p>
{% else %}
<p>{% trans "It's the first time you log into the system, welcome on board!" %}</p>
{% endif %}
<div class="card-deck">
{% for resource, usage in resource_usage.items %}

View File

@ -1,5 +1,7 @@
from django.test import TestCase
from .models import UserAccount
class DomainsTestCase(TestCase):
def test_domain_not_found(self):
@ -12,3 +14,26 @@ class DomainsTestCase(TestCase):
response = self.client.get('/domains/3/')
self.assertEqual(404, response.status_code)
class UserAccountTest(TestCase):
def test_user_never_logged(self):
data = {
'billcontact': {'address': 'foo',
'city': 'Barcelona',
'country': 'ES',
'name': '',
'vat': '12345678Z',
'zipcode': '08080'},
'date_joined': '2020-01-14T12:38:31.684495Z',
'full_name': 'Pep',
'id': 2,
'is_active': True,
'language': 'EN',
'short_name': '',
'type': 'INDIVIDUAL',
'url': 'http://example.org/api/accounts/2/',
'username': 'pepe'
}
account = UserAccount.new_from_json(data)
self.assertIsNone(account.last_login)