Пример #1
0
 def test_place_to_watch(self):
     user = UserFactory.create()
     profile = user.get_profile()
     ptw = PlaceToWatch(
         profile=profile, latitude=0.5, longitude=0.6,
         radius=5, title='Some title')
     ptw.save()
     self.assertEqual(str(ptw), 'Some title (0.50000, 0.60000)')
Пример #2
0
 def test_profile_access(self):
     # test only profile owner has access
     user = UserFactory.create()
     profile = user.get_profile()
     # without authentication
     response = self.client.get(
         reverse('profile-detail', kwargs={'pk': profile.pk}))
     self.assertEqual(response.status_code, 403)
     # authenticated
     auth_string = 'Basic %s' % base64.encodestring(
         '{username}:{password}'.format(
             username=user.username, password=user.username).rstrip())
     response = self.client.get(
         reverse('profile-detail', kwargs={'pk': profile.pk}),
         HTTP_AUTHORIZATION=auth_string)
     self.assertEqual(response.status_code, 200)
     # try to access to another profile
     user1 = UserFactory.create()
     profile1 = user1.get_profile()
     response = self.client.get(
         reverse('profile-detail', kwargs={'pk': profile1.pk}),
         HTTP_AUTHORIZATION=auth_string)
     self.assertEqual(response.status_code, 403)
Пример #3
0
 def test_image_save(self):
     user = UserFactory.create()
     profile = user.get_profile()
     self.assertFalse(profile.image200)
     self.assertFalse(profile.image32)
     # crop and save images
     image = ImageFactory.create(return_file=False)
     profile.set_image(imageobj=image)
     profile.save()
     self.assertTrue(os.path.exists(profile.image200.path))
     self.assertTrue(os.path.exists(profile.image32.path))
     # permanently remove images
     profile.delete()
     self.assertFalse(os.path.exists(profile.image200.path))
     self.assertFalse(os.path.exists(profile.image32.path))
Пример #4
0
 def test_place_to_watch(self):
     client = APIClient()
     user = UserFactory.create()
     profile = user.get_profile()
     client.login(username=user.username, password=user.username)
     # test create
     response = client.post(
         reverse('placetowatch-list'), {
             'profile': profile.pk,
             'title': 'Some title',
             'latitude': '0.5',
             'longitude': '0.7',
             'radius': '5'},
         format='json')
     data = simplejson.loads(response.content)
     self.assertEqual(data['profile'], profile.pk)
Пример #5
0
 def test_profile(self):
     client = APIClient()
     user = UserFactory.create()
     profile = user.get_profile()
     client.login(username=user.username, password=user.username)
     # test get profile data
     response = client.get(
         reverse('profile-detail', kwargs={'pk': profile.pk}),
         format='json')
     data = simplejson.loads(response.content)
     for field in ['name', 'places']:
         self.assertIn(field, data)
     for hidden_field in ['user']:
         self.assertNotIn(hidden_field, data)
     # test edit name
     new_name = '%snew' % user.username
     response = client.patch(
         reverse('profile-detail', kwargs={'pk': profile.pk}),
         {'name': new_name}, format='json')
     profile = Profile.objects.get(pk=profile.pk)
     self.assertEqual(profile.name, new_name)