def test_get_notes_not_authenticated(self):
        user1 = UserFactory.create()
        hike1 = HikeFactory.create(owner=user1)
        note1 = NoteFactory.create(hike=hike1)

        user2 = UserFactory.create()
        hike2 = HikeFactory.create(owner=user2)
        note2 = NoteFactory.create(hike=hike2)

        url = reverse('note-list')
        self.client.force_authenticate(user=user1)
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertContains(response, note1.uuid)
        self.assertNotContains(response, note2.uuid)
 def test_put_note(self):
     note = NoteFactory.create()
     url = reverse('note-detail', args=[note.uuid])
     data = {
         "uuid": note.uuid,
         "revision": note.revision,
         "doc_type": "note",
         "date": "2013-09-10T20:33:40Z",
         "text": "Test",
         "position": {
             "latitude": 46.20934846967972,
             "longitude": 6.16333008353723
         },
         "hike": note.hike.uuid
     }
     self.client.force_authenticate(user=note.hike.owner)
     response = self.client.put(url, data)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     note = Note.objects.get(uuid=data['uuid'])
     self.assertEqual(note.text, data['text'])
     self.assertIsNotNone(note.date)
     self.assertEqual(note.hike.uuid, data['hike'])
     self.assertTrue(abs(note.position.y - data['position']['latitude'])
                     < 0.001)
     self.assertTrue(abs(note.position.x - data['position']['longitude'])
                     < 0.001)
Example #3
0
 def test_delete_note(self):
     note = NoteFactory.create()
     self.client.force_authenticate(user=note.owner)
     url = reverse('note-detail', args=[note.uuid])
     response = self.client.delete(url + "?revision={0}".format(
         note.revision))
     self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
 def test_delete_note(self):
     note = NoteFactory.create()
     self.client.force_authenticate(user=note.hike.owner)
     url = reverse('note-detail', args=[note.uuid])
     response = self.client.delete(url + "?revision={0}".format(
         note.revision))
     self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)
Example #5
0
    def test_get_notes_uuids(self):
        user1 = UserFactory.create()
        note1 = NoteFactory.create(owner=user1)

        user2 = UserFactory.create()
        note2 = NoteFactory.create(owner=user2)

        url = reverse('notes-uuids-list')
        self.client.force_authenticate(user=user1)
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertContains(response, note1.uuid)
        self.assertContains(response, note1.revision)
        self.assertNotContains(response, note1.text)
        self.assertNotContains(response, note1.title)
        self.assertNotContains(response, note2.uuid)
        self.assertNotContains(response, note2.revision)
Example #6
0
    def test_my_notes(self):
        url = reverse('my_notes')
        self.app.get(url, status=HTTP_302_FOUND)

        note = NoteFactory.create(title='Title', text='Some text.')
        response = self.app.get(url, user=note.owner.username,
                                status=HTTP_200_OK)
        self.assertContains(response, note.title)
        self.assertContains(response, note.text)
 def test_notes_location(self):
     """
     Tests that we can search notes by distance
     """
     hike = HikeFactory.create()
     position1 = Point(7.095323, 43.592157)
     position2 = Point(7.098906, 43.588535)
     note1 = NoteFactory.create(text=u"Lost my wallet around here",
                                hike=hike,
                                position=position1)
     note2 = NoteFactory.create(text=u"Discovered loss of wallet only here",
                                hike=hike,
                                position=position2)
     note1.save()
     note2.save()
     position3 = Point(7.098992, 43.586981)
     distance = D(m=300)
     proximal_notes = Note.objects.filter(position__distance_lte=(position3,
                                                                  distance))
     self.assertEqual(len(proximal_notes), 1)
Example #8
0
 def test_delete_note_invalid_revision(self):
     note = NoteFactory.create()
     self.client.force_authenticate(user=note.owner)
     url = reverse('note-detail', args=[note.uuid])
     response = self.client.delete(url + "?revision=dummy")
     self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)
     expected_response_data = {
         "error": ("Conflict, you are trying to delete an old revision "
                   "of this object")
     }
     self.assertDictContainsSubset(expected_response_data, response.data)
Example #9
0
 def test_get_note(self):
     note = NoteFactory.create()
     url = reverse('note-detail', args=[note.uuid])
     self.client.force_authenticate(user=note.owner)
     response = self.client.get(url)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertDictContainsSubset({'uuid': note.uuid}, response.data)
     self.assertDictContainsSubset({'revision': note.revision},
                                   response.data)
     self.assertDictContainsSubset({'text': note.text}, response.data)
     self.assertDictContainsSubset({'date': note.date}, response.data)
 def test_delete_note_invalid_revision(self):
     note = NoteFactory.create()
     self.client.force_authenticate(user=note.hike.owner)
     url = reverse('note-detail', args=[note.uuid])
     response = self.client.delete(url + "?revision=dummy")
     self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)
     expected_response_data = {
         "error": ("Conflict, you are trying to delete an old revision "
                   "of this object")
     }
     self.assertDictContainsSubset(expected_response_data, response.data)
Example #11
0
 def test_put_note_no_revision(self):
     note = NoteFactory.create()
     url = reverse('note-detail', args=[note.uuid])
     data = {
         "uuid": note.uuid,
         "date": "2013-09-10T20:33:40Z",
         "text": "This is a test",
         "title": "Title",
     }
     self.client.force_authenticate(user=note.owner)
     response = self.client.put(url, data)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Example #12
0
    def test_hike_detail(self):
        name = 'Grande Casse'
        hike = HikeFactory.create(name=name)
        note = NoteFactory.create(text=u"Marmots!", hike=hike)
        url = reverse('hike_detail', args=[hike.uuid])
        response = self.app.get(url)
        self.assertNotEqual(response.status_code, HTTP_200_OK)

        response = self.app.get(url, user=hike.owner.email)
        self.assertContains(response, hike.name)
        self.assertContains(response, note.text)

        url = reverse('hike_detail', args=['dummy'])
        self.app.get(url, user=hike.owner.email, status=HTTP_404_NOT_FOUND)
 def test_put_note_no_position(self):
     note = NoteFactory.create()
     url = reverse('note-detail', args=[note.uuid])
     data = {
         "uuid": note.uuid,
         "revision": note.revision,
         "doc_type": "note",
         "date": "2013-09-10T20:33:40Z",
         "text": "Test",
         "hike": note.hike.uuid
     }
     self.client.force_authenticate(user=note.hike.owner)
     response = self.client.put(url, data)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 def test_get_note(self):
     note = NoteFactory.create()
     url = reverse('note-detail', args=[note.uuid])
     self.client.force_authenticate(user=note.hike.owner)
     response = self.client.get(url)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertDictContainsSubset({'uuid': note.uuid}, response.data)
     self.assertDictContainsSubset({'revision': note.revision},
                                   response.data)
     self.assertDictContainsSubset({'doc_type': 'note'}, response.data)
     self.assertDictContainsSubset({'hike': note.hike.uuid},
                                   response.data)
     self.assertDictContainsSubset({'text': note.text}, response.data)
     self.assertDictContainsSubset({'date': note.date}, response.data)
Example #15
0
    def test_after_creating_note_a_created_note_action_is_triggered(self):
        a_user = UserFactory.create()
        a_map = MapFactory.create(creator=a_user)
        a_note = NoteFactory.create(map=a_map, creator=a_user)

        am = ActivityManager()
        created = am.created_note(a_user)

        self.assertTrue(len(created))
        action = list(created)[0]

        self.assertEqual(action.actor, a_user)
        self.assertEqual(action.target, a_map)
        self.assertEqual(action.verb, CREATED_NOTE)
        self.assertEqual(action.action_object, a_note)
 def test_put_note_invalid_position(self):
     note = NoteFactory.create()
     url = reverse('note-detail', args=[note.uuid])
     data = {
         "uuid": note.uuid,
         "revision": note.revision,
         "doc_type": "note",
         "date": "2013-09-10T20:33:40Z",
         "text": "Test",
         "hike": note.hike.uuid,
         "position": "test"
     }
     self.client.force_authenticate(user=note.hike.owner)
     response = self.client.put(url, data)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Example #17
0
    def test_after_deleting_note_a_deleted_note_action_is_triggered(self):
        a_user = UserFactory.create()
        a_map = MapFactory.create(creator=a_user)
        a_note = NoteFactory.create(map=a_map, creator=a_user)
        a_note.delete()

        am = ActivityManager()
        deleted = am.deleted_note(a_user)

        self.assertTrue(len(deleted))
        action = deleted[0]

        self.assertEqual(action.actor, a_user)
        self.assertEqual(action.target, a_map)
        self.assertEqual(action.verb, DELETED_NOTE)
Example #18
0
 def test_put_note(self):
     note = NoteFactory.create()
     url = reverse('note-detail', args=[note.uuid])
     data = {
         "uuid": note.uuid,
         "revision": note.revision,
         "date": "2013-09-10T20:33:40Z",
         "text": "This is a test",
         "title": "Title",
     }
     self.client.force_authenticate(user=note.owner)
     response = self.client.put(url, data)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     note = Note.objects.get(uuid=data['uuid'])
     self.assertEqual(note.text, data['text'])
     self.assertEqual(note.title, data['title'])
     self.assertIsNotNone(note.date)
 def test_put_note_no_hike(self):
     note = NoteFactory.create()
     url = reverse('note-detail', args=[note.uuid])
     data = {
         "uuid": note.uuid,
         "revision": note.revision,
         "doc_type": "note",
         "date": "2013-09-10T20:33:40Z",
         "text": "Test",
         "position": {
             "latitude": 46.20934846967972,
             "longitude": 6.1633300835308615
         }
     }
     self.client.force_authenticate(user=note.hike.owner)
     response = self.client.put(url, data)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
Example #20
0
 def test_put_note_invalid_revision(self):
     note = NoteFactory.create()
     url = reverse('note-detail', args=[note.uuid])
     data = {
         "uuid": note.uuid,
         "revision": "invalid",
         "date": "2013-09-10T20:33:40Z",
         "text": "This is a test",
         "title": "Title",
     }
     self.client.force_authenticate(user=note.owner)
     response = self.client.put(url, data)
     self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)
     expected_response_data = {
         "error": ("Conflict, you are trying to update an old revision "
                   "of this object")
     }
     self.assertDictContainsSubset(expected_response_data, response.data)
 def test_put_note_invalid_revision(self):
     note = NoteFactory.create()
     url = reverse('note-detail', args=[note.uuid])
     data = {
         "uuid": note.uuid,
         "revision": "invalid",
         "doc_type": "note",
         "date": "2013-09-10T20:33:40Z",
         "text": "Test",
         "position": {
             "latitude": 46.20934846967972,
             "longitude": 6.1633300835308615
         },
         "hike": note.hike.uuid
     }
     self.client.force_authenticate(user=note.hike.owner)
     response = self.client.put(url, data)
     self.assertEqual(response.status_code, status.HTTP_409_CONFLICT)
     expected_response_data = {
         "error": ("Conflict, you are trying to update an old revision "
                   "of this object")
     }
     self.assertDictContainsSubset(expected_response_data, response.data)
Example #22
0
 def test_delete_note_not_authenticated(self):
     note = NoteFactory.create()
     url = reverse('note-detail', args=[note.uuid])
     response = self.client.delete(url)
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
 def test_delete_note_not_authenticated(self):
     note = NoteFactory.create()
     url = reverse('note-detail', args=[note.uuid])
     response = self.client.delete(url)
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Example #24
0
 def test_delete_note_no_revision(self):
     note = NoteFactory.create()
     self.client.force_authenticate(user=note.owner)
     url = reverse('note-detail', args=[note.uuid])
     response = self.client.delete(url)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 def test_delete_note_no_revision(self):
     note = NoteFactory.create()
     self.client.force_authenticate(user=note.hike.owner)
     url = reverse('note-detail', args=[note.uuid])
     response = self.client.delete(url)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)