Example #1
0
    def test_put_list_notification(self):
        notification_1day = Notification.objects.get(
            id=self.notification_1day.id)
        self.assertFalse(notification_1day.delivered)

        notification_2weeks = Notification.objects.get(
            id=self.notification_2weeks.id)
        self.assertFalse(notification_2weeks.delivered)

        all_notification = self.api_client.get(
            self.url, format='json', authentication=get_credentials(self))
        all_notification = self.deserialize(all_notification)
        self.assertFalse(all_notification[0]["delivered"])
        self.assertFalse(all_notification[1]["delivered"])

        self.assertHttpAccepted(
            self.api_client.put(self.url,
                                format='json',
                                data=all_notification,
                                authentication=get_credentials(self)))

        notification_1day = Notification.objects.get(
            id=self.notification_1day.id)
        self.assertTrue(notification_1day.delivered)

        notification_2weeks = Notification.objects.get(
            id=self.notification_2weeks.id)
        self.assertTrue(notification_2weeks.delivered)
 def test_put_profile_error_not_allowed(self):
     self.assertEqual(self.user.get_profile().avatar_url, "http://www.example.com")
     self.post_data["avatar_url"] = "www.update.com"
     self.assertHttpMethodNotAllowed(self.api_client.put(self.url_with_identifier, format='json',
         data=self.post_data, authentication=get_credentials(self)))
     new_userprofile = UserProfile.objects.get(id=self.user.get_profile().id)
     self.assertEqual(new_userprofile.avatar_url, "http://www.example.com")
 def test_delete_userlinks_error_not_allowed(self):
     self.assertEqual(UserLinks.objects.count(), 7)
     self.assertHttpMethodNotAllowed(
         self.api_client.delete(self.url_with_identifier,
                                format='json',
                                authentication=get_credentials(self)))
     self.assertEqual(UserLinks.objects.count(), 7)
Example #4
0
 def test_put_user_error_not_allowed(self):
     self.assertEqual(self.user.username, "jandersonfc")
     self.post_data["username"] = "******"
     self.assertHttpMethodNotAllowed(self.api_client.put(self.url_with_identifier, format='json',
         data=self.post_data, authentication=get_credentials(self)))
     user = User.objects.get(id=self.user.id)
     self.assertEqual(user.username, "jandersonfc")
 def test_get_userlinks_filter_url_with_url_and_original_url(self):
     data = {'url': 'http://read.com'}
     resp = self.api_client.get(self.url,
                                format='json',
                                data=data,
                                authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 2)
    def test_delete_conversation_error_not_allowed(self):
        self.assertEqual(ConversationList.objects.count(), 1)

        self.assertHttpMethodNotAllowed(
            self.api_client.delete(self.url_with_identifier,
                format='json', authentication=get_credentials(self)))

        self.assertEqual(ConversationList.objects.count(), 1)
 def test_get_userlinks_search_with_word_in_title_and_description(self):
     data = {'search': 'search'}
     resp = self.api_client.get(self.url,
                                format='json',
                                data=data,
                                authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 2)
 def test_post_userlinks_error_not_allowed(self):
     self.assertEqual(UserLinks.objects.count(), 7)
     self.assertHttpMethodNotAllowed(
         self.api_client.post(self.url,
                              format='json',
                              data=self.post_data,
                              authentication=get_credentials(self)))
     self.assertEqual(UserLinks.objects.count(), 7)
 def test_get_userlinks_search_with_two_word_and_favorite(self):
     data = {'search': 'read favorite #favorite'}
     resp = self.api_client.get(self.url,
                                format='json',
                                data=data,
                                authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 1)
    def test_post_notification_error_not_allowed(self):
        self.assertEqual(Notification.objects.count(), 4)

        self.assertHttpMethodNotAllowed(self.api_client.post(self.url,
            format='json', data=self.post_data,
            authentication=get_credentials(self)))

        self.assertEqual(Notification.objects.count(), 4)
Example #11
0
 def test_get_history_search_with_search_and_days(self):
     self.assertEqual(Notification.objects.count(), 4)
     resp = self.api_client.get(self.url,
                                format='json',
                                authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 2)
     self.assertEqual(self.deserialize(resp)[0]['delivered'], False)
Example #12
0
 def test_get_userlinks_search_without_words(self):
     data = {'search': ''}
     self.assertEqual(UserLinks.objects.count(), 7)
     resp = self.api_client.get(self.url,
                                format='json',
                                data=data,
                                authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 6)
Example #13
0
 def test_get_userlinks_search_unfavorite(self):
     data = {'search': '#unfavorite'}
     resp = self.api_client.get(self.url,
                                format='json',
                                data=data,
                                authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 4)
     self.assertEqual(self.deserialize(resp)[0]['favorite'], False)
Example #14
0
 def test_get_history_search_with_search_and_days(self):
     data = {'search': 'week', 'days': 7}
     self.assertEqual(Notification.objects.count(), 7)
     resp = self.api_client.get(self.url,
                                format='json',
                                data=data,
                                authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 1)
Example #15
0
 def test_get_history_without_filters(self):
     self.assertEqual(Notification.objects.count(), 7)
     resp = self.api_client.get(self.url,
                                format='json',
                                authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 5)
     self.assertEqual(u'Test message 1 day ago',
                      self.deserialize(resp)[0]['message']['message'])
Example #16
0
 def test_post_new_message_link_is_image(self):
     data = {
         'message': 'Test Message http://www.jandersonfc.com/opa.jpg',
         'conversation': {'id': self.conversation.pk}
     }
     self.assertHttpCreated(self.api_client.post('/api/v1/user/messages', format='json',
         data=data, authentication=get_credentials(self)))
     self.assertEqual(0, Links.objects.all().count())
     self.assertEqual(0, UserLinks.objects.all().count())
Example #17
0
 def test_post_new_message_without_link(self):
     data = {
         'message': 'Test Message',
         'conversation': {'id': self.conversation.pk}
     }
     self.assertHttpCreated(self.api_client.post('/api/v1/user/messages', format='json',
         data=data, authentication=get_credentials(self)))
     self.assertEqual(0, Links.objects.all().count())
     self.assertEqual(0, UserLinks.objects.all().count())
Example #18
0
 def test_get_userlinks_search_with_read(self):
     data = {'search': '#read'}
     resp = self.api_client.get(self.url,
                                format='json',
                                data=data,
                                authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 2)
     self.assertEqual(self.deserialize(resp)[0]['read'], True)
Example #19
0
    def test_post_message(self):
        data = {
            'message': 'test message',
            'conversation': {'id': self.conversation.pk}
        }

        self.assertEqual(Message.objects.count(), 1)
        self.assertHttpCreated(self.api_client.post('/api/v1/user/messages', format='json',
            data=data, authentication=get_credentials(self)))
        self.assertEqual(Message.objects.count(), 2)
Example #20
0
 def test_post_new_message_with_two_link(self):
     data = {
         'message': 'Test Message http://www.jandersonfc.com google.com',
         'conversation': {'id': self.conversation.pk}
     }
     self.assertHttpCreated(self.api_client.post('/api/v1/user/messages', format='json',
         data=data, authentication=get_credentials(self)))
     self.assertEqual(2, Links.objects.all().count())
     self.assertEqual(4, UserLinks.objects.all().count())
     self.assertEqual(2, UserLinks.objects.filter(user=self.user).count())
     self.assertEqual(2, UserLinks.objects.filter(user=self.user2).count())
Example #21
0
    def test_post_verify_if_created_notifications(self):
        data = {
            'message': 'test message',
            'conversation': {'id': self.conversation.pk}
        }

        self.assertHttpCreated(self.api_client.post('/api/v1/user/messages', format='json',
            data=data, authentication=get_credentials(self)))
        self.assertEqual(2, Notification.objects.all().count())
        self.assertEqual(1, Notification.objects.filter(user=self.user).count())
        self.assertEqual(1, Notification.objects.filter(user=self.user2).count())
Example #22
0
 def test_get_history_filter_3months(self):
     data = {'days': 90}
     self.assertEqual(Notification.objects.count(), 7)
     resp = self.api_client.get(self.url,
                                format='json',
                                data=data,
                                authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 5)
     self.assertEqual(u'Test message 3 months ago',
                      self.deserialize(resp)[4]['message']['message'])
Example #23
0
 def test_put_profile_error_not_allowed(self):
     self.assertEqual(self.user.get_profile().avatar_url,
                      "http://www.example.com")
     self.post_data["avatar_url"] = "www.update.com"
     self.assertHttpMethodNotAllowed(
         self.api_client.put(self.url_with_identifier,
                             format='json',
                             data=self.post_data,
                             authentication=get_credentials(self)))
     new_userprofile = UserProfile.objects.get(
         id=self.user.get_profile().id)
     self.assertEqual(new_userprofile.avatar_url, "http://www.example.com")
Example #24
0
    def test_put_history_error_not_allowed(self):
        self.assertEqual(self.notification_3months.delivered, True)

        self.assertHttpMethodNotAllowed(
            self.api_client.put(self.url_with_identifier,
                                format='json',
                                data=self.post_data,
                                authentication=get_credentials(self)))

        notification = Notification.objects.get(
            id=self.notification_3months.id)
        self.assertEqual(notification.delivered, True)
Example #25
0
    def test_put_userlink_udpate_favorite(self):
        old_link = UserLinks.objects.get(id=self.link_unread.id)
        self.assertEqual(old_link.favorite, False)
        self.assertEqual(old_link.link.clicks, 0)

        userlink_original = self.api_client.get(
            self.url_with_identifier,
            format='json',
            authentication=get_credentials(self))
        userlink_original = self.deserialize(userlink_original)
        userlink_original["favorite"] = True

        self.assertHttpAccepted(
            self.api_client.put(self.url_with_identifier,
                                format='json',
                                data=userlink_original,
                                authentication=get_credentials(self)))

        new_userlinks = UserLinks.objects.get(id=self.link_unread.id)
        self.assertEqual(new_userlinks.favorite, True)
        self.assertEqual(new_userlinks.link.clicks, 0)
Example #26
0
    def test_put_detail_notification(self):
        notification_1day = Notification.objects.get(
            id=self.notification_1day.id)
        self.assertFalse(notification_1day.delivered)

        notification = self.api_client.get(
            self.url_with_identifier,
            format='json',
            authentication=get_credentials(self))
        notification = self.deserialize(notification)
        notification["delivered"] = True

        self.assertHttpAccepted(
            self.api_client.put(self.url_with_identifier,
                                format='json',
                                data=notification,
                                authentication=get_credentials(self)))

        notification_1day = Notification.objects.get(
            id=self.notification_1day.id)
        self.assertTrue(notification_1day.delivered)
    def test_post_conversation(self):
        data = {
            'name': 'maximize ideas',
            'users': [
               {'id':2}
            ]
        }

        self.assertEqual(ConversationList.objects.count(), 1)
        self.assertHttpCreated(self.api_client.post(self.url, format='json',
            data=data, authentication=get_credentials(self)))
        self.assertEqual(ConversationList.objects.count(), 2)
    def test_put_detail_notification(self):
        notification_1day = Notification.objects.get(id=self.notification_1day.id)
        self.assertFalse(notification_1day.delivered)

        notification = self.api_client.get(self.url_with_identifier, format='json', authentication=get_credentials(self))
        notification = self.deserialize(notification)
        notification["delivered"] = True

        self.assertHttpAccepted(self.api_client.put(self.url_with_identifier, format='json',
            data=notification, authentication=get_credentials(self)))

        notification_1day = Notification.objects.get(id=self.notification_1day.id)
        self.assertTrue(notification_1day.delivered)
Example #29
0
 def test_post_new_message_with_link_owner_mark_as_unread(self):
     data = {
         'message': 'Test Message Test Message http://www.jandersonfc.com',
         'conversation': {'id': self.conversation.pk}
     }
     self.assertHttpCreated(self.api_client.post('/api/v1/user/messages', format='json',
         data=data, authentication=get_credentials(self)))
     self.assertEqual(1, Links.objects.all().count())
     self.assertEqual(2, UserLinks.objects.all().count())
     link1 = UserLinks.objects.get(user=self.user)
     link2 = UserLinks.objects.get(user=self.user2)
     self.assertFalse(link1.read)
     self.assertFalse(link2.read)
    def test_put_conversation(self):
        self.assertEqual(self.conversation.name, 'My Conversation')

        conversation_original = self.api_client.get(self.url_with_identifier, format='json', authentication=get_credentials(self))
        conversation_original = self.deserialize(conversation_original)
        conversation_original["name"] = 'maximize ideas'

        self.assertHttpAccepted(
            self.api_client.put(self.url_with_identifier, format='json',
            data=conversation_original, authentication=get_credentials(self)))

        conversation = ConversationList.objects.get(id=self.conversation.id)
        self.assertEqual(conversation.name, 'maximize ideas')
Example #31
0
 def test_post_new_message_with_delivered_to_owner_of_message(self):
     data = {
         'message': 'Test Message Test Message http://www.jandersonfc.com',
         'conversation': {'id': self.conversation.pk}
     }
     self.assertHttpCreated(self.api_client.post('/api/v1/user/messages', format='json',
         data=data, authentication=get_credentials(self)))
     self.assertEqual(2, Notification.objects.all().count())
     self.assertEqual(1, Notification.objects.filter(user=self.user).count())
     self.assertEqual(1, Notification.objects.filter(user=self.user2).count())
     notification1 = Notification.objects.get(user=self.user)
     notification2 = Notification.objects.get(user=self.user2)
     self.assertTrue(notification1.delivered)
     self.assertFalse(notification2.delivered)
    def test_put_list_notification(self):
        notification_1day = Notification.objects.get(id=self.notification_1day.id)
        self.assertFalse(notification_1day.delivered)

        notification_2weeks = Notification.objects.get(id=self.notification_2weeks.id)
        self.assertFalse(notification_2weeks.delivered)

        all_notification = self.api_client.get(self.url, format='json', authentication=get_credentials(self))
        all_notification = self.deserialize(all_notification)
        self.assertFalse(all_notification[0]["delivered"])
        self.assertFalse(all_notification[1]["delivered"])

        self.assertHttpAccepted(self.api_client.put(self.url, format='json',
            data=all_notification, authentication=get_credentials(self)))

        notification_1day = Notification.objects.get(id=self.notification_1day.id)
        self.assertTrue(notification_1day.delivered)

        notification_2weeks = Notification.objects.get(id=self.notification_2weeks.id)
        self.assertTrue(notification_2weeks.delivered)
Example #33
0
 def test_get_user_with_indentifier(self):
     self.assertEqual(User.objects.count(), 2)
     resp = self.api_client.get(self.url_with_identifier, format='json', authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(self.deserialize(resp)['id'], self.user.id)
Example #34
0
 def test_get_history_filter_3months(self):
     data = {"days": 90}
     self.assertEqual(Notification.objects.count(), 7)
     resp = self.api_client.get(self.url, format="json", data=data, authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 5)
     self.assertEqual(u"Test message 3 months ago", self.deserialize(resp)[4]["message"]["message"])
 def test_get_my_conversation(self):
     self.assertEqual(ConversationList.objects.count(), 1)
     resp = self.api_client.get(self.url, format='json', authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 1)
Example #36
0
 def test_put_link_error_not_allowed(self):
     self.assertEqual(self.link.url, "http://someurl.com")
     self.assertHttpMethodNotAllowed(self.api_client.put(self.url_with_identifier, format='json',
         data=self.post_data, authentication=get_credentials(self)))
     new_link = Links.objects.get(id=self.link.id)
     self.assertEqual(new_link.url, "http://someurl.com")
Example #37
0
 def test_get_link_error_not_allowed(self):
     self.assertHttpMethodNotAllowed(self.api_client.get(self.url_with_identifier, format='json',
         authentication=get_credentials(self)))
Example #38
0
    def test_delete_history_error_not_allowed(self):
        self.assertEqual(Notification.objects.count(), 7)

        self.assertHttpMethodNotAllowed(
            self.api_client.delete(self.url_with_identifier, format="json", authentication=get_credentials(self))
        )

        self.assertEqual(Notification.objects.count(), 7)
 def test_get_all_profiles_error_not_allowed(self):
     self.assertHttpMethodNotAllowed(self.api_client.get(self.url, format='json',
         authentication=get_credentials(self)))
Example #40
0
 def test_get_user_with_indentifier_not_found(self):
     self.assertHttpNotFound(self.api_client.get(self.url_with_identifier2,
         format='json', authentication=get_credentials(self)))
Example #41
0
 def test_get_history_search_with_search_and_days(self):
     data = {"search": "week", "days": 7}
     self.assertEqual(Notification.objects.count(), 7)
     resp = self.api_client.get(self.url, format="json", data=data, authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 1)
Example #42
0
    def test_put_history_error_not_allowed(self):
        self.assertEqual(self.notification_3months.delivered, True)

        self.assertHttpMethodNotAllowed(
            self.api_client.put(
                self.url_with_identifier, format="json", data=self.post_data, authentication=get_credentials(self)
            )
        )

        notification = Notification.objects.get(id=self.notification_3months.id)
        self.assertEqual(notification.delivered, True)
Example #43
0
 def test_get_profile_error_not_allowed(self):
     self.assertHttpMethodNotAllowed(
         self.api_client.get(self.url_with_identifier,
                             format='json',
                             authentication=get_credentials(self)))
 def test_get_history_search_with_search_and_days(self):
     self.assertEqual(Notification.objects.count(), 4)
     resp = self.api_client.get(self.url, format='json', authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 2)
     self.assertEqual(self.deserialize(resp)[0]['delivered'], False)
Example #45
0
 def test_get_history_without_filters(self):
     self.assertEqual(Notification.objects.count(), 7)
     resp = self.api_client.get(self.url, format="json", authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(len(self.deserialize(resp)), 5)
     self.assertEqual(u"Test message 1 day ago", self.deserialize(resp)[0]["message"]["message"])
Example #46
0
 def test_get_userlinks_with_indentifier(self):
     resp = self.api_client.get(self.url_with_identifier,
                                format='json',
                                authentication=get_credentials(self))
     self.assertValidJSONResponse(resp)
     self.assertEqual(self.deserialize(resp)['id'], self.link_unread.id)