def test_changing_email(self): # new user, email unknown (not in any invite) email = '*****@*****.**' register(self.c, email) (api_key, username) = login(self.c, email) auth = '?username=%s&api_key=%s'%(username, api_key) self.assertEqual(Link.objects.count(), 0) self.assertEqual(Contact.objects.count(), 10) # change email into something known res = self.c.post('/api/v1/userprofile/setprofile/%s'%auth, data = json.dumps({'email':'*****@*****.**'}), content_type='application/json') self.assertEqual(res.status_code, 200) # must NOT throw any error: self.assertEqual(Link.objects.count(), 1) Link.objects.get(sender__user__email='*****@*****.**', receiver__user__email='*****@*****.**') # change email into something known, but still the same user res = self.c.post('/api/v1/userprofile/setprofile/%s'%auth, data = json.dumps({'email':'*****@*****.**'}), content_type='application/json') self.assertEqual(res.status_code, 200) # must NOT throw any error: self.assertEqual(Link.objects.count(), 1) # not change, same user Link.objects.get(sender__user__email='*****@*****.**', receiver__user__email='*****@*****.**')
def test_changing_number(self): self.assertEqual(Link.objects.count(), 0) self.assertEqual(Contact.objects.count(), 10) # new user, email unknown (not in any invite) email = '*****@*****.**' register(self.c, email) (api_key, username) = login(self.c, email) auth = '?username=%s&api_key=%s'%(username, api_key) # change number into something known res = self.c.post('/api/v1/userprofile/setprofile/%s'%auth, data = json.dumps({'number':'+33610077009'}), content_type='application/json') self.assertEqual(res.status_code, 200) # must NOT throw any error: self.assertEqual(Link.objects.count(), 1) Link.objects.get(sender__user__email='*****@*****.**', receiver__phone_number='+33610077009') # new user, email unknown (not in any invite) email = '*****@*****.**' register(self.c, email) (api_key, username) = login(self.c, email) auth = '?username=%s&api_key=%s'%(username, api_key) # change number into something known res = self.c.post('/api/v1/userprofile/setprofile/%s'%auth, data = json.dumps({'number':'0675894632'}), content_type='application/json') self.assertEqual(res.status_code, 200) # must NOT throw any error: self.assertEqual(Link.objects.count(), 2) Link.objects.get(sender__user__email='*****@*****.**', receiver__phone_number='+33675894632')
def test_creating_user(self): self.assertEqual(Link.objects.count(), 0) self.assertEqual(Contact.objects.count(), 10) # new user whom email is in an invite register(self.c, '*****@*****.**') # must NOT throw any error: self.assertEqual(Link.objects.count(), 1) Link.objects.get(sender__user__email='*****@*****.**', receiver__user__email='*****@*****.**')
def test_error_cases(self): email = '*****@*****.**' (api_key, username) = login(c, email) auth = '?username=%s&api_key=%s' % (username, api_key) # user1 creates an event etype = EventType.objects.first().id start = timezone.now().replace(microsecond=0) strstart = start.strftime("%Y-%m-%dT%H:%M:%SZ%Z") data = { 'event_type': '/api/v1/event_type/%d/' % etype, 'start': strstart, 'location_coords': '{ "type": "Point", "coordinates": [100.0, 0.0] }' } res = c.post('/api/v1/events/mine/%s' % auth, data=json.dumps(data), content_type='application/json') self.assertEqual(res.status_code, 201) ide = Event.objects.get(owner__user__username=username, event_type=etype, start=start).id # try to join it res = c.post('/api/v1/events/friends/join/%s/%s' % (ide, auth), data=json.dumps(data), content_type='application/json') self.assertEqual(res.status_code, 403) # wrong id res = c.post('/api/v1/events/friends/join/%s/%s' % (543, auth), data=json.dumps(data), content_type='application/json') self.assertEqual(res.status_code, 400) # join two times email = '*****@*****.**' u02 = register(c, '*****@*****.**') (api_key, username) = login(c, email) auth2 = '?username=%s&api_key=%s' % (username, api_key) res = c.post('/api/v1/events/friends/join/%s/%s' % (ide, auth2), data=json.dumps(data), content_type='application/json') self.assertEqual(res.status_code, 200) res = c.post('/api/v1/events/friends/join/%s/%s' % (ide, auth2), data=json.dumps(data), content_type='application/json') self.assertEqual(res.status_code, 403) # leave but not participant email = '*****@*****.**' u03 = register(c, '*****@*****.**') (api_key, username) = login(c, email) auth3 = '?username=%s&api_key=%s' % (username, api_key) res = c.post('/api/v1/events/friends/leave/%s/%s' % (ide, auth3), data=json.dumps(data), content_type='application/json') self.assertEqual(res.status_code, 403)
def test_join_leave(self): email = '*****@*****.**' (api_key, username) = login(c, email) auth = '?username=%s&api_key=%s' % (username, api_key) # user1 creates an event etype = EventType.objects.first().id start = timezone.now().replace(microsecond=0) strstart = start.strftime("%Y-%m-%dT%H:%M:%SZ%Z") data = { 'event_type': '/api/v1/event_type/%d/' % etype, 'start': strstart, 'location_coords': '{ "type": "Point", "coordinates": [100.0, 0.0] }' } res = c.post('/api/v1/events/mine/%s' % auth, data=json.dumps(data), content_type='application/json') self.assertEqual(res.status_code, 201) ide = Event.objects.get(owner__user__username=username, event_type=etype, start=start).id # user2 & user3 join email = '*****@*****.**' u02 = register(c, '*****@*****.**') (api_key, username) = login(c, email) auth2 = '?username=%s&api_key=%s' % (username, api_key) res = c.post('/api/v1/events/friends/join/%s/%s' % (ide, auth2), data=json.dumps(data), content_type='application/json') self.assertEqual(res.status_code, 200) email = '*****@*****.**' u03 = register(c, '*****@*****.**') (api_key, username) = login(c, email) auth3 = '?username=%s&api_key=%s' % (username, api_key) res = c.post('/api/v1/events/friends/join/%s/%s' % (ide, auth3), data=json.dumps(data), content_type='application/json') self.assertEqual(res.status_code, 200) e = Event.objects.get(id=ide) participants = [i['user_id'] for i in e.participants.values()] self.assertEqual(len(participants), 2) self.assertEqual(participants.sort(), [u02.id, u03.id].sort()) # user3 leaves res = c.post('/api/v1/events/friends/leave/%s/%s' % (ide, auth3), data=json.dumps(data), content_type='application/json') self.assertEqual(res.status_code, 200) e = Event.objects.get(id=ide) participants = [i['user_id'] for i in e.participants.values()] self.assertEqual(len(participants), 1) self.assertEqual(participants.sort(), [u03.id].sort())
def setUp(self): super(EventTestCase, self).setUp() call_command('create_initial_data') self.u01 = register(c, '*****@*****.**') cat = EventCategory.objects.create(name="meal") e = EventType.objects.create(name="meal") e.category.add(cat)
def setUp(self): super(TransformTestCase, self).setUp() call_command('create_initial_data') email = '*****@*****.**' self.u01 = register(self.c, email) (api_key, username) = login(self.c, email) auth = '?username=%s&api_key=%s'%(username, api_key) sort_contact(self.c, username, user1_contacts)
def setUp(self): super(PositionTestCase, self).setUp() call_command('create_initial_data') email = '*****@*****.**' self.u01 = register(c, email) (api_key, self.username) = login(c, email) self.authParam = '?username=%s&api_key=%s'%(self.username, api_key)
def setUp(self): super(RelationshipTestCase, self).setUp() call_command('create_initial_data') email = '*****@*****.**' self.u1 = register(c, email) (api_key, username) = login(c, email) self.auth1 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u2 = register(c, email) (api_key, username) = login(c, email) self.auth2 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u3 = register(c, email) (api_key, username) = login(c, email) self.auth3 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u4 = register(c, email) (api_key, username) = login(c, email) self.auth4 = '?username=%s&api_key=%s'%(username, api_key)
def setUp(self): super(ResourcesTestCase, self).setUp() call_command('create_initial_data') # create some users email = '*****@*****.**' self.u1 = register(c, email) (api_key, username) = login(c, email) self.auth1 = '?username=%s&api_key=%s' % (username, api_key) email = '*****@*****.**' self.u2 = register(c, email) (api_key, username) = login(c, email) self.auth2 = '?username=%s&api_key=%s' % (username, api_key) email = '*****@*****.**' self.u3 = register(c, email) (api_key, username) = login(c, email) self.auth3 = '?username=%s&api_key=%s' % (username, api_key) email = '*****@*****.**' self.u4 = register(c, email) (api_key, username) = login(c, email) self.auth4 = '?username=%s&api_key=%s' % (username, api_key) email = '*****@*****.**' self.u5 = register(c, email) (api_key, username) = login(c, email) self.auth5 = '?username=%s&api_key=%s' % (username, api_key) # create relations Link.objects.create(sender=self.u1, sender_status='ACC', receiver=self.u2, receiver_status='ACC') Link.objects.create(sender=self.u1, sender_status='ACC', receiver=self.u3, receiver_status='ACC') Link.objects.create(sender=self.u2, sender_status='ACC', receiver=self.u4, receiver_status='ACC') # create categorie & type cat = EventCategory.objects.create(name="meal") etype = EventType.objects.create(name="meal") etype.category.add(cat) # create some events for u1 e1 = Event.objects.create( owner=self.u1, event_type=etype, start=timezone.now(), name="u1 breakfast", location_coords='{ "type": "Point", "coordinates": [50.0, 50.0] }') e2 = Event.objects.create( owner=self.u1, event_type=etype, start=timezone.now(), name="u1 lunch", location_coords='{ "type": "Point", "coordinates": [50.0, 50.0] }') e2.participants.add(self.u2) e3 = Event.objects.create( owner=self.u1, event_type=etype, start=timezone.now(), name="u1 diner", location_coords='{ "type": "Point", "coordinates": [50.0, 50.0] }') e3.participants.add(self.u2) e3.participants.add(self.u3) # create some events for u2 e1 = Event.objects.create( owner=self.u2, event_type=etype, start=timezone.now(), name="u2 breakfast", location_coords='{ "type": "Point", "coordinates": [50.0, 50.0] }') e2 = Event.objects.create( owner=self.u2, event_type=etype, start=timezone.now(), name="u2 lunch", location_coords='{ "type": "Point", "coordinates": [50.0, 50.0] }') e2.invitees.add(self.u1) e2.participants.add(self.u1) e3 = Event.objects.create( owner=self.u2, event_type=etype, start=timezone.now(), name="u2 diner", location_coords='{ "type": "Point", "coordinates": [50.0, 50.0] }') e3.invitees.add(self.u4) e3.participants.add(self.u4) # create some events for u3 e1 = Event.objects.create( owner=self.u3, event_type=etype, start=timezone.now(), name="u3 breakfast", location_coords='{ "type": "Point", "coordinates": [50.0, 50.0] }') e2 = Event.objects.create( owner=self.u3, event_type=etype, start=timezone.now(), name="u3 lunch", location_coords='{ "type": "Point", "coordinates": [50.0, 50.0] }') e2.participants.add(self.u1) # create some events for u4 e1 = Event.objects.create( owner=self.u4, event_type=etype, start=timezone.now(), name="u4 breakfast", location_coords='{ "type": "Point", "coordinates": [50.0, 50.0] }') e2 = Event.objects.create( owner=self.u4, event_type=etype, start=timezone.now(), name="u4 lunch", location_coords='{ "type": "Point", "coordinates": [50.0, 50.0] }') e2.participants.add(self.u2)
def test_invitees(self): email = '*****@*****.**' (api_key, username) = login(c, email) auth = '?username=%s&api_key=%s' % (username, api_key) # create some friends emails_list = ['*****@*****.**', '*****@*****.**', '*****@*****.**'] friends_list = [] for i in emails_list: u = register(c, i) friends_list.append(u) Link.objects.create(sender=self.u01, receiver=u, sender_status="ACC", receiver_status="ACC") # create an event for all friends etype = EventType.objects.first().id start = timezone.now().replace(microsecond=0) strstart = start.strftime("%Y-%m-%dT%H:%M:%SZ%Z") data = { 'event_type': '/api/v1/event_type/%d/' % etype, 'start': strstart, 'location_coords': '{ "type": "Point", "coordinates": [100.0, 0.0] }' } res = c.post('/api/v1/events/mine/%s' % auth, data=json.dumps(data), content_type='application/json') self.assertEqual(res.status_code, 201) ide = Event.objects.get(owner__user__username=username, event_type=etype, start=start) emails = [] for i in ide.get_invitees(): emails.append(i.user.email) emails.sort() self.assertEqual(emails, emails_list) # create an event with selected invitees etype = EventType.objects.first().id start += datetime.timedelta(1) strstart = start.strftime("%Y-%m-%dT%H:%M:%SZ%Z") data = { 'event_type': '/api/v1/event_type/%d/' % etype, 'start': strstart, 'location_coords': '{ "type": "Point", "coordinates": [100.0, 0.0] }', 'invitees': [ '/api/v1/userprofile/%d/' % friends_list[0].id, '/api/v1/userprofile/%d/' % friends_list[1].id ] } res = c.post('/api/v1/events/mine/%s' % auth, data=json.dumps(data), content_type='application/json') self.assertEqual(res.status_code, 201) ide = Event.objects.get(owner__user__username=username, event_type=etype, start=start) emails = [] for i in ide.get_invitees(): emails.append(i.user.email) emails.sort() self.assertEqual(emails, ['*****@*****.**', '*****@*****.**'])
def setUp(self): """set up users with new links""" super(LinkTestCase, self).setUp() call_command('create_initial_data') self.u01 = register(self.c, '*****@*****.**') self.u02 = register(self.c, '*****@*****.**') self.u03 = register(self.c, '*****@*****.**') self.u04 = register(self.c, '*****@*****.**') self.u05 = register(self.c, '*****@*****.**') self.u06 = register(self.c, '*****@*****.**') self.u07 = register(self.c, '*****@*****.**') self.u08 = register(self.c, '*****@*****.**') self.u09 = register(self.c, '*****@*****.**') self.u10 = register(self.c, '*****@*****.**') self.u11 = register(self.c, '*****@*****.**') self.u12 = register(self.c, '*****@*****.**') self.l1 = Link.objects.create(sender=self.u01.profile, receiver=self.u02.profile) self.l2 = Link.objects.create(sender=self.u01.profile, receiver=self.u03.profile) self.l3 = Link.objects.create(sender=self.u01.profile, receiver=self.u04.profile) self.l4 = Link.objects.create(sender=self.u05.profile, receiver=self.u01.profile) self.l5 = Link.objects.create(sender=self.u06.profile, receiver=self.u01.profile) self.l6 = Link.objects.create(sender=self.u07.profile, receiver=self.u08.profile) self.l7 = Link.objects.create(sender=self.u09.profile, receiver=self.u10.profile)
def setUp(self): super(ContactTestCase, self).setUp() call_command('create_initial_data') self.u01 = register(self.c, '*****@*****.**')
def test_contact_and_connection(self): # first, post contacts of an existing user # and check what was created email = '*****@*****.**' (api_key, username) = login(self.c, email) auth = '?username=%s&api_key=%s'%(username, api_key) sort_contact(self.c, username, user1_contacts) self.assertEqual(Link.objects.count(), 8) #7initial+user9 self.assertEqual(Contact.objects.count(), 9) # the following should NOT raise a DoesNotExist exception Contact.objects.get(sender__user__username=username, numbers='+33600000001') Contact.objects.get(sender__user__username=username, numbers='+33600000002') Link.objects.get(sender__user__username=username, receiver__user__email='*****@*****.**') # then register a new user and check invites conversion data = {'email' : '*****@*****.**', 'password' : 'totopwd'} res = self.c.post('/api/v1/auth/register_by_email/', data = json.dumps(data), content_type='application/json') self.assertEqual(res.status_code, 201) #the following should NOT raise a DoesNotExist exception Link.objects.get(sender__user__username=username, receiver__user__email='*****@*****.**') self.assertEqual(Link.objects.count(), 9) #+newuser1 #the following MUST raise a DoesNotExist exception with self.assertRaises(Link.DoesNotExist): Link.objects.get(sender=self.u01.profile, receiver=self.u11.profile) Link.objects.get(sender=self.u01.profile, receiver=self.u12.profile) # Now post a second user email = '*****@*****.**' (api_key, username) = login(self.c, email) auth = '?username=%s&api_key=%s'%(username, api_key) sort_contact(self.c, username, user2_contacts) self.assertEqual(Link.objects.count(), 11) #+user9 +newuser1 self.assertEqual(Contact.objects.count(), 14) #the following MUST raise a DoesNotExist exception with self.assertRaises(Link.DoesNotExist): Link.objects.get(sender=self.u02.profile, receiver=self.u11.profile) Link.objects.get(sender=self.u02.profile, receiver=self.u12.profile) # And for a third user email = '*****@*****.**' (api_key, username) = login(self.c, email) auth = '?username=%s&api_key=%s'%(username, api_key) sort_contact(self.c, username, user3_contacts) self.assertEqual(Link.objects.count(), 11) self.assertEqual(Contact.objects.count(), 19) #the following MUST raise a DoesNotExist exception with self.assertRaises(Link.DoesNotExist): Link.objects.get(sender=self.u03.profile, receiver=self.u11.profile) Link.objects.get(sender=self.u03.profile, receiver=self.u12.profile) # register the common friend, should create 3 links email = '*****@*****.**' register(self.c, email) (api_key, username) = login(self.c, email) auth = '?username=%s&api_key=%s'%(username, api_key) res = self.c.post('/api/v1/userprofile/setprofile/%s'%auth, data = json.dumps({'number':'+33612312300'}), content_type='application/json') self.assertEqual(res.status_code, 200) self.assertEqual(Link.objects.count(), 14)
def setUp(self): super(ResourcesTestCase, self).setUp() call_command('create_initial_data') # create some users email = '*****@*****.**' self.u1 = register(c, email) (api_key, username) = login(c, email) self.auth1 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u2 = register(c, email) (api_key, username) = login(c, email) self.auth2 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u3 = register(c, email) (api_key, username) = login(c, email) self.auth3 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u4 = register(c, email) (api_key, username) = login(c, email) self.auth4 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u5 = register(c, email) (api_key, username) = login(c, email) self.auth5 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u6 = register(c, email) (api_key, username) = login(c, email) self.auth6 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u7 = register(c, email) (api_key, username) = login(c, email) self.auth7 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u8 = register(c, email) (api_key, username) = login(c, email) self.auth8 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u9 = register(c, email) (api_key, username) = login(c, email) self.auth9 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u10 = register(c, email) (api_key, username) = login(c, email) self.auth10 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u11 = register(c, email) (api_key, username) = login(c, email) self.auth11 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u12 = register(c, email) (api_key, username) = login(c, email) self.auth12 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u13 = register(c, email) (api_key, username) = login(c, email) self.auth13 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u14 = register(c, email) (api_key, username) = login(c, email) self.auth14 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u15 = register(c, email) (api_key, username) = login(c, email) self.auth15 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u16 = register(c, email) (api_key, username) = login(c, email) self.auth16 = '?username=%s&api_key=%s'%(username, api_key) email = '*****@*****.**' self.u17 = register(c, email) (api_key, username) = login(c, email) self.auth17 = '?username=%s&api_key=%s'%(username, api_key) # create relations for u1 Link.objects.create(sender=self.u1.profile, sender_status='NEW', receiver=self.u2.profile, receiver_status='NEW') Link.objects.create(sender=self.u1.profile, sender_status='NEW', receiver=self.u3.profile, receiver_status='IGN') Link.objects.create(sender=self.u1.profile, sender_status='IGN', receiver=self.u4.profile, receiver_status='NEW') Link.objects.create(sender=self.u1.profile, sender_status='ACC', receiver=self.u5.profile, receiver_status='PEN') Link.objects.create(sender=self.u1.profile, sender_status='PEN', receiver=self.u6.profile, receiver_status='ACC') Link.objects.create(sender=self.u1.profile, sender_status='ACC', receiver=self.u7.profile, receiver_status='REJ') Link.objects.create(sender=self.u1.profile, sender_status='REJ', receiver=self.u8.profile, receiver_status='ACC') Link.objects.create(sender=self.u1.profile, sender_status='ACC', receiver=self.u9.profile, receiver_status='ACC') Link.objects.create(sender=self.u10.profile, sender_status='NEW', receiver=self.u1.profile, receiver_status='NEW') Link.objects.create(sender=self.u11.profile, sender_status='NEW', receiver=self.u1.profile, receiver_status='IGN') Link.objects.create(sender=self.u12.profile, sender_status='IGN', receiver=self.u1.profile, receiver_status='NEW') Link.objects.create(sender=self.u13.profile, sender_status='ACC', receiver=self.u1.profile, receiver_status='PEN') Link.objects.create(sender=self.u14.profile, sender_status='PEN', receiver=self.u1.profile, receiver_status='ACC') Link.objects.create(sender=self.u15.profile, sender_status='ACC', receiver=self.u1.profile, receiver_status='REJ') Link.objects.create(sender=self.u16.profile, sender_status='REJ', receiver=self.u1.profile, receiver_status='ACC') Link.objects.create(sender=self.u17.profile, sender_status='ACC', receiver=self.u1.profile, receiver_status='ACC') # create relations for u2 Link.objects.create(sender=self.u2.profile, sender_status='PEN', receiver=self.u3.profile, receiver_status='ACC') Link.objects.create(sender=self.u2.profile, sender_status='PEN', receiver=self.u5.profile, receiver_status='ACC') Link.objects.create(sender=self.u2.profile, sender_status='PEN', receiver=self.u7.profile, receiver_status='ACC') Link.objects.create(sender=self.u2.profile, sender_status='PEN', receiver=self.u9.profile, receiver_status='ACC') Link.objects.create(sender=self.u2.profile, sender_status='PEN', receiver=self.u10.profile, receiver_status='ACC') # create relations for u3 Link.objects.create(sender=self.u3.profile, sender_status='NEW', receiver=self.u6.profile, receiver_status='NEW') Link.objects.create(sender=self.u3.profile, sender_status='NEW', receiver=self.u8.profile, receiver_status='NEW') Link.objects.create(sender=self.u3.profile, sender_status='NEW', receiver=self.u10.profile, receiver_status='NEW') Link.objects.create(sender=self.u3.profile, sender_status='ACC', receiver=self.u12.profile, receiver_status='ACC') Link.objects.create(sender=self.u3.profile, sender_status='ACC', receiver=self.u14.profile, receiver_status='ACC')