Example #1
0
    def test_api_error_if_no_url_provided(self):
        """
        Verifies that the secure saved searched API returns an error if a
        url is not provided.

        """
        request_data = {'email': '*****@*****.**', 'url': ''}
        response = make_cors_request(self.client,
                                     self.secure_ss_url,
                                     json.dumps(request_data),
                                     http_origin="http://%s" % self.domain)
        response_msg = json.loads(response.content)
        self.assertTrue(response_msg['error'],
                        msg="Expected an error, got %s! API returned"
                        ": " % response_msg['error'])
        self.assertFalse(response_msg['search_activated'])
Example #2
0
    def test_api_works_with_authenticated_user(self):
        """
        Verifies that the secure saved searched API works properly with
        authenticated users when a valid, unclaimed email is provided

        """
        request_data = {'email': self.user.email, 'url': self.child_url}
        response = make_cors_request(self.client,
                                     self.secure_ss_url,
                                     json.dumps(request_data),
                                     http_origin="http://%s" % self.domain)
        response_msg = json.loads(response.content)
        self.assertFalse(response_msg['error'],
                         msg="Expected empty string, got %s! API returned "
                         "error" % response_msg['error'])
        self.assertTrue(response_msg['search_activated'])
Example #3
0
    def test_api_error_if_no_url_provided(self):
        """
        Verifies that the secure saved searched API returns an error if a
        url is not provided.

        """
        request_data = {'email':'*****@*****.**',
                        'url': ''}
        response = make_cors_request(self.client,
                                     self.secure_ss_url,
                                     json.dumps(request_data),
                                     http_origin="http://%s" % self.domain)
        response_msg = json.loads(response.content)
        self.assertTrue(response_msg['error'],
                         msg="Expected an error, got %s! API returned"
                             ": " % response_msg['error'])
        self.assertFalse(response_msg['search_activated'])
Example #4
0
    def test_api_works_with_authenticated_user(self):
        """
        Verifies that the secure saved searched API works properly with
        authenticated users when a valid, unclaimed email is provided

        """
        request_data = {'email':self.user.email,
                        'url': self.child_url}
        response = make_cors_request(self.client,
                                     self.secure_ss_url,
                                     json.dumps(request_data),
                                     http_origin="http://%s" % self.domain)
        response_msg = json.loads(response.content)
        self.assertFalse(response_msg['error'],
                         msg="Expected empty string, got %s! API returned "
                             "error" % response_msg['error'])
        self.assertTrue(response_msg['search_activated'])
Example #5
0
    def test_api_returns_error_if_email_is_taken(self):
        """
        Verifies that the secure saved searched API returns an error if the
        provided email is taken by another user

        """
        taken_email = '*****@*****.**'
        UserFactory(email=taken_email)
        request_data = {'email': taken_email, 'url': self.child_url}
        response = make_cors_request(self.client,
                                     self.secure_ss_url,
                                     json.dumps(request_data),
                                     http_origin="http://%s" % self.domain)
        response_msg = json.loads(response.content)
        self.assertTrue(response_msg['error'],
                        msg="Expected an error but none raised! API returned"
                        ": %s" % response_msg['error'])
        self.assertFalse(response_msg['search_activated'])
Example #6
0
    def test_api_returns_error_if_email_is_taken(self):
        """
        Verifies that the secure saved searched API returns an error if the
        provided email is taken by another user

        """
        taken_email = '*****@*****.**'
        UserFactory(email=taken_email)
        request_data = {'email':taken_email,
                        'url': self.child_url}
        response = make_cors_request(self.client,
                                     self.secure_ss_url,
                                     json.dumps(request_data),
                                     http_origin="http://%s" % self.domain)
        response_msg = json.loads(response.content)
        self.assertTrue(response_msg['error'],
                         msg="Expected an error but none raised! API returned"
                             ": %s" % response_msg['error'])
        self.assertFalse(response_msg['search_activated'])
Example #7
0
    def test_api_works_with_unauthenticated_user(self):
        """
        Verifies that the secure saved searched API works properly with
        unauthenticated users when a valid, unclaimed email is provided

        """
        self.client.logout()
        request_data = {'email':'*****@*****.**',
                        'url': self.child_url}
        response = make_cors_request(self.client,
                                     self.secure_ss_url,
                                     json.dumps(request_data),
                                     http_origin="http://%s" % self.domain)

        self.assertEqual(response.status_code, 200)
        response_msg = json.loads(response.content)
        self.assertTrue(response_msg['user_created'],
                         msg="Expected user to be created, but it was not")
        self.assertTrue(response_msg['search_activated'],
                         msg="Expected search to be activated, but it was not")
Example #8
0
    def test_api_works_with_unauthenticated_user(self):
        """
        Verifies that the secure saved searched API works properly with
        unauthenticated users when a valid, unclaimed email is provided

        """
        self.client.logout()
        request_data = {
            'email': '*****@*****.**',
            'url': self.child_url
        }
        response = make_cors_request(self.client,
                                     self.secure_ss_url,
                                     json.dumps(request_data),
                                     http_origin="http://%s" % self.domain)

        self.assertEqual(response.status_code, 200)
        response_msg = json.loads(response.content)
        self.assertTrue(response_msg['user_created'],
                        msg="Expected user to be created, but it was not")
        self.assertTrue(response_msg['search_activated'],
                        msg="Expected search to be activated, but it was not")