Skip to content

Commit abac643

Browse files
authored
Merge pull request #10 from TomaszKolek/fixed-prints
Adjust to python3
2 parents 87eeffa + f8013fa commit abac643

File tree

7 files changed

+97
-97
lines changed

7 files changed

+97
-97
lines changed

demo/tests/test_api_client.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ def get_unifi_client():
88
class TestAPI(TestCase):
99

1010
def test_can_instantiate_instance_of_unificlient(self):
11-
print "test_can_instantiate_instance_of_unificlient"
12-
ufc = get_unifi_client();
11+
print("test_can_instantiate_instance_of_unificlient")
12+
ufc = get_unifi_client()
1313
assert isinstance(ufc, UnifiClient)
1414

1515
def test_login_as_admin(self):
16-
print "test_login_as_admin"
17-
ufc = get_unifi_client();
16+
print("test_login_as_admin")
17+
ufc = get_unifi_client()
1818
status_code = ufc.login_on_unifi_server()
1919
assert status_code == 200
2020

2121
def test_authorize_guest(self):
22-
print "test_authorize_guest"
23-
ufc = get_unifi_client();
22+
print("test_authorize_guest")
23+
ufc = get_unifi_client()
2424
ufc.login_on_unifi_server()
2525
status_code = ufc.authorize_guest(guest_mac='04:4b:ed:25:c6:b3',
2626
minutes='10',
@@ -29,23 +29,23 @@ def test_authorize_guest(self):
2929
assert status_code == 200
3030

3131
def test_unauthorize_guest(self):
32-
print "test_unauthorize_guest"
33-
ufc = get_unifi_client();
32+
print("test_unauthorize_guest")
33+
ufc = get_unifi_client()
3434
ufc.login_on_unifi_server()
3535
status_code = ufc.unauthorize_guest(guest_mac='04:4b:ed:25:c6:b3')
3636

3737
assert status_code == 200
3838

3939
def test_logout_admin(self):
40-
print "test_logout_admin"
41-
ufc = get_unifi_client();
40+
print("test_logout_admin")
41+
ufc = get_unifi_client()
4242
ufc.login_on_unifi_server()
4343
status_code = ufc.logout_from_unifi_server()
4444
assert status_code == 200
4545

4646
def test_send_authorization(self):
47-
print "test_send_authorization"
48-
ufc = get_unifi_client();
47+
print("test_send_authorization")
48+
ufc = get_unifi_client()
4949
ufc.login_on_unifi_server()
5050
status_code = ufc.send_authorization(guest_mac='04:4b:ed:25:c6:b3',
5151
minutes='10',

demo/tests/test_login.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,40 +17,40 @@ def setUp(self):
1717
try:
1818
self.user = User.objects.get(username='lennon@thebeatles.com')
1919
except User.DoesNotExist:
20-
self.user = User();
21-
self.user.set_password('johnpassword');
22-
self.user.username = 'lennon@thebeatles.com';
23-
self.user.email = 'lennon@thebeatles.com';
24-
self.user.is_active = True;
25-
self.user.save();
26-
27-
fbuserprofile = UnifiUser();
28-
fbuserprofile.user = self.user;
29-
fbuserprofile.save();
20+
self.user = User()
21+
self.user.set_password('johnpassword')
22+
self.user.username = 'lennon@thebeatles.com'
23+
self.user.email = 'lennon@thebeatles.com'
24+
self.user.is_active = True
25+
self.user.save()
26+
27+
fbuserprofile = UnifiUser()
28+
fbuserprofile.user = self.user
29+
fbuserprofile.save()
3030
except Exception as exp:
31-
print "EXCEPTION:LoginTestCase-->", str(exp)
32-
pass;
31+
print("EXCEPTION:LoginTestCase-->", str(exp))
32+
pass
3333

3434

3535
def testIndexView(self):
36-
print ">> testIndexView"
36+
print(">> testIndexView")
3737
self.setUp()
3838
self.client.login(username='lennon@thebeatles.com', password='johnpassword')
3939

4040
test_url_ihone = '/guest/s/default/?id=04:4b:ed:25:c6:b3&ap=f0:9f:c2:39:86:f2&t=1496998102&url=http://captive.apple.com%2fhotspot-detect.html&ssid=ClubLaVela'
4141
test_url_samsung='/guest/s/default/?id=88:ad:d2:e4:cf:f4&ap=f0:9f:c2:39:86:f2&t=1496848672&url=http://connectivitycheck.gstatic.com%2fgenerate_204&ssid=ClubLaVela'
4242
response = self.client.get(test_url_samsung)
4343

44-
self.assertEqual(response.status_code, 200);
44+
self.assertEqual(response.status_code, 200)
4545

4646

4747
def testIndexViewWrongUrl(self):
48-
print ">> testIndexView"
48+
print(">> testIndexView")
4949
self.setUp()
5050
self.client.login(username='lennon@thebeatles.com', password='johnpassword')
5151

5252
test_url_ihone = '/guest/s/default/?id=04:4b:ed:25:c6:b3&ap=f0:9f:c2:39:86:f2&t=1496998102&url=http://captive.apple.com%2fhotspot-detect.html&ssid=ClubLaVela'
5353
test_url_samsung='/guest/?id=88:ad:d2:e4:cf:f4&ap=f0:9f:c2:39:86:f2&t=1496848672&url=http://connectivitycheck.gstatic.com%2fgenerate_204&ssid=ClubLaVela'
5454
response = self.client.get(test_url_samsung)
5555

56-
self.assertEqual(response.status_code, 404);
56+
self.assertEqual(response.status_code, 404)

demo/unifi/views.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ class ListGuestView(AjaxResponseMixin, ListView):
88
template_name = "user_list.html"
99

1010
def get_queryset(self):
11-
return UnifiUser.objects.all();
11+
return UnifiUser.objects.all()
1212

1313
#@method_decorator(login_required)
1414
def dispatch(self, request, *args, **kwargs):

django_unifi_portal/models.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ class UnifiUser(models.Model):
99

1010
user = models.ForeignKey(User)
1111
picture = models.ImageField(upload_to='profile_images', default='profile_images/user_no_image.png',null=True)
12-
language = models.CharField(max_length=8, default='it-IT');# aggiunto il 22/11/2016
13-
gender = models.CharField(max_length=10, null=True);
14-
city = models.CharField(max_length=200, null = True);
15-
about = models.CharField(max_length=255, null=True);
16-
dob = models.DateField(null=True);
17-
18-
phone = models.CharField(max_length=255, null=True);
19-
guest_mac = models.CharField(max_length=255, null=True);
20-
last_backend_login = models.CharField(max_length=30, null=True);
12+
language = models.CharField(max_length=8, default='it-IT') # aggiunto il 22/11/2016
13+
gender = models.CharField(max_length=10, null=True)
14+
city = models.CharField(max_length=200, null = True)
15+
about = models.CharField(max_length=255, null=True)
16+
dob = models.DateField(null=True)
17+
18+
phone = models.CharField(max_length=255, null=True)
19+
guest_mac = models.CharField(max_length=255, null=True)
20+
last_backend_login = models.CharField(max_length=30, null=True)
2121

2222
def __unicode__(self):
2323
return self.user.username

django_unifi_portal/pipeline.py

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def user_details(strategy, details, user=None, *args, **kwargs):
2828
"""Update user details using data from provider."""
2929
if user:
3030
if not UnifiUser.objects.filter(user=user).exists():
31-
print "user_details:UserProfile NOT exist, creating.."
31+
print("user_details:UserProfile NOT exist, creating..")
3232
changed = False # flag to track changes
3333
protected = ('username', 'id', 'pk', 'email') + \
3434
tuple(strategy.setting('PROTECTED_USER_FIELDS', []))
@@ -43,9 +43,9 @@ def user_details(strategy, details, user=None, *args, **kwargs):
4343
current_value = getattr(user, name, None)
4444
if not current_value or name not in protected:
4545
changed |= current_value != value
46-
# print "user_details::name", name
47-
value = value.replace("'", " ")[0:29];
48-
# print "user_details::value", value; #FIX - crash con nomi superiori ai 30 caratteri
46+
# print("user_details::name", name)
47+
value = value.replace("'", " ")[0:29]
48+
# print("user_details::value", value) #FIX - crash con nomi superiori ai 30 caratteri
4949

5050
setattr(user, name, value)
5151

@@ -60,28 +60,28 @@ def save_profile(backend, user, response, *args, **kwargs):
6060

6161
if backend.name == 'facebook':
6262
try:
63-
profile = UnifiUser.objects.get(user=user);
63+
profile = UnifiUser.objects.get(user=user)
6464
except UnifiUser.DoesNotExist:
6565
profile = UnifiUser()
66-
profile.user = user;
67-
profile.save();
66+
profile.user = user
67+
profile.save()
6868

69-
profile.gender = response.get('gender');
69+
profile.gender = response.get('gender')
7070
profile.about = response.get('about')
7171
profile.city = response.get('hometown')
7272
profile.user.email = response.get('email')
7373

74-
birthday_date = None;
74+
birthday_date = None
7575
try:
7676
birthday = response.get('birthday')
7777
birthday_date = datetime.strptime(birthday, '%m/%d/%Y')
7878
except Exception as eb:
79-
pass;
79+
pass
8080
profile.dob = birthday_date
8181

8282
fbuid = response.get('id')
8383
profile.user.username = fbuid # la mail e' troppo grande
84-
profile.user.save();
84+
profile.user.save()
8585

8686
try:
8787
image_name = 'fb_avatar_%s.jpg' % fbuid
@@ -93,48 +93,48 @@ def save_profile(backend, user, response, *args, **kwargs):
9393
ContentFile(image_stream.read()),
9494
)
9595
except Exception as e:
96-
pass;
96+
pass
9797

9898
# INIT - 14-12-2016
99-
print "FACEBOOK:seleziono lingua"
99+
print("FACEBOOK:seleziono lingua")
100100
try:
101-
fb_access_token = response.get('access_token');
102-
fb_locale_url = "https://graph.facebook.com/v2.9/" + "/me?fields=locale,location" + "&access_token=" + fb_access_token;
103-
print fb_locale_url
101+
fb_access_token = response.get('access_token')
102+
fb_locale_url = "https://graph.facebook.com/v2.9/" + "/me?fields=locale,location" + "&access_token=" + fb_access_token
103+
print(fb_locale_url)
104104
r = requests.get(fb_locale_url)
105105

106106
if r.status_code == 200:
107107
fb_response = json.loads(str(r.text.encode("utf-8")))
108-
print "fb response :", fb_response
108+
print("fb response :", fb_response)
109109

110110
# language
111111
try:
112-
print "***LANG :", fb_response.get('locale')[0:2]
112+
print("***LANG :", fb_response.get('locale')[0:2])
113113
profile.language = fb_response.get('locale')[0:2]
114114
except:
115-
pass;
115+
pass
116116

117117
# city
118118
try:
119-
print "***LOCATION :", fb_response.get('location')
119+
print("***LOCATION :", fb_response.get('location'))
120120
profile.city = fb_response.get('location')['name']
121121
except:
122-
pass;
122+
pass
123123

124124
except Exception as e:
125-
print "FB Exception with locale " + str(e)
125+
print("FB Exception with locale " + str(e))
126126
pass;
127127
profile.last_backend_login = backend.name;
128-
profile.save();
128+
profile.save()
129129
else:
130130
# in questo caso sto solo richiedendo una nuova associazione social
131-
print "UserProfile already exist..nothing..."
131+
print("UserProfile already exist..nothing...")
132132

133133
# questo e' il caso di un utente che ha cancellato l'account
134134
# e' poi ritornato successivamente
135-
profile = UnifiUser.objects.get(user=user);
136-
profile.user.is_active = True;
137-
profile.user.save();
135+
profile = UnifiUser.objects.get(user=user)
136+
profile.user.is_active = True
137+
profile.user.save()
138138

139139

140140
def manage_auth_already_associated(backend, uid, user=None, *args, **kwargs):

django_unifi_portal/unifi_client.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def _get_resource_url(self, path_name=None):
5151
return url
5252
else:
5353
url = str.format('{0}{1}:{2}/', 'https://', self.__unifiServer, '8443')
54-
return url;
54+
return url
5555

5656
def _is_authorized(self, guest_mac):
5757
"""Return true if the guest is already authorized."""
@@ -108,10 +108,10 @@ def authorize_guest(self, guest_mac, ap_mac, minutes):
108108
api_url = self._get_resource_url(api_version + 'cmd/stamgr')
109109
auth_response = self.__session.post(api_url, data=json.dumps(auth))
110110

111-
print "***** UNIFI AUTH RESPONSE *****"
112-
print api_url
113-
print auth_response
114-
print "*******************************"
111+
print("***** UNIFI AUTH RESPONSE *****")
112+
print(api_url)
113+
print(auth_response)
114+
print("*******************************")
115115

116116
return auth_response.status_code
117117

@@ -142,9 +142,9 @@ def logout_from_unifi_server(self):
142142

143143
def send_authorization(self, guest_mac, ap_mac, minutes):
144144
""" Login on Unifi Server and authorize a guest based on his MAC address"""
145-
self.login_on_unifi_server();
145+
self.login_on_unifi_server()
146146

147-
status_code = -1;
147+
status_code = -1
148148
if not self._is_authorized(guest_mac):
149149
status_code = self.authorize_guest(guest_mac=guest_mac,
150150
minutes=minutes,

0 commit comments

Comments
 (0)