def test_edit_post_not_ajax_does_not_chane_data(self):
        """/edit/ post not ajax request must change UserProfile if its valid"""
        self.client.login(username='******', password='******')

        data = user_data.copy()
        data['name'] = 'Nigel'

        self.client.post(reverse('edit'), data)

        self.assertNotEquals(UserProfile.objects.first().name, data['name'])
    def test_edit_post_not_ajax_does_not_chane_data(self):
        """/edit/ post not ajax request must change UserProfile if its valid"""
        self.client.login(username='******', password='******')

        data = user_data.copy()
        data['name'] = 'Nigel'

        self.client.post(reverse('edit'), data)

        self.assertNotEquals(UserProfile.objects.first().name, data['name'])
    def test_edit_post_ajax_changes_UserProfile(self):
        """ /edit/ post ajax request must change UserProfile if its valid"""
        self.client.login(username='******', password='******')

        data = user_data.copy()
        data['name'] = 'Nigel'

        response = self.client.post(reverse('edit'), data,
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        self.assertEquals(UserProfile.objects.first().name, data['name'])
        self.assertEquals(json.loads(response.content)['success'], True)
    def test_edit_post_with_invalid_data(self):
        """/edit/ post request with invalid data"""
        self.client.login(username='******', password='******')

        data = user_data.copy()
        data['email'] = 'dasdasdasd'

        response = self.client.post(reverse('edit'), data,
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        self.assertEquals(json.loads(response.content)['success'], False)
        self.assertEquals(json.loads(response.content)['err_msg']['email'][0],
                          'Enter a valid email address.')
    def test_edit_post_ajax_changes_UserProfile(self):
        """ /edit/ post ajax request must change UserProfile if its valid"""
        self.client.login(username='******', password='******')

        data = user_data.copy()
        data['name'] = 'Nigel'

        response = self.client.post(reverse('edit'),
                                    data,
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        self.assertEquals(UserProfile.objects.first().name, data['name'])
        self.assertEquals(json.loads(response.content)['success'], True)
    def test_edit_post_with_invalid_data(self):
        """/edit/ post request with invalid data"""
        self.client.login(username='******', password='******')

        data = user_data.copy()
        data['email'] = 'dasdasdasd'

        response = self.client.post(reverse('edit'),
                                    data,
                                    HTTP_X_REQUESTED_WITH='XMLHttpRequest')

        self.assertEquals(json.loads(response.content)['success'], False)
        self.assertEquals(
            json.loads(response.content)['err_msg']['email'][0],
            'Enter a valid email address.')