Пример #1
0
 def test_user_signin_check(self):
     test = {'email': '*****@*****.**', 'password': '******'}
     response = Client().post('/user/signin',
                              json.dumps(test),
                              content_type='applications/json')
     access_token = response.json()['access_token']
     self.assertEqual(response.status_code, 200)
     self.assertEqual(response.json(), {"access_token": access_token})
Пример #2
0
def retrieve_signatures(
    url, headers, session=None, params=None, inline_domain=None, keepalive=True
):
    if params is None or inline_domain is None:
        params, inline_domain = get_requests_params(url)
    prepared_url = url.rstrip("?&")
    # signatures should be on first page
    prepared_url = "%s%skeys" % (
        prepared_url,
        "&" if "?" in prepared_url else "?",
    )
    jsonob = None
    if inline_domain:
        response = Client().get(
            prepared_url,
            Connection="Keep-Alive" if keepalive else "close",
            SERVER_NAME=inline_domain,
            **headers,
        )
        if response.status_code == 200:
            jsonob = response.json()
        else:
            logger.warning(
                "Could not retrieve signatures:\n%s", response.content
            )
    else:
        if session:
            s = session
        else:
            s = requests.Session()
        try:
            response = s.get(
                prepared_url,
                headers={
                    "Connection": "Keep-Alive" if keepalive else "close",
                    **headers,
                },
                **params,
            )
            if response.status_code == 200:
                jsonob = response.json()
            else:
                logger.warning(
                    "Could not retrieve signatures:\n%s", response.content
                )
        except Exception as exc:
            logger.error("Error while fetching signatures", exc_info=exc)
        finally:
            if not session:
                s.close()
    try:
        for i in jsonob["signatures"].values():
            if "=" not in i.get("signature", ""):
                raise
        return jsonob["signatures"]
    except Exception as exc:
        logger.error("Invalid format:\n%s", jsonob, exc_info=exc)
        return None
Пример #3
0
    def test_it_returns_all_lists(self):
        List.objects.create(name="Shopping", icon="example-icon")
        List.objects.create(name="Diy", icon="example-icon")

        response = Client().get('/api/lists')

        self.assertEqual(HTTPStatus.OK, response.status_code)
        self.assertEqual(2, len(response.json()['data']))
        self.assertEqual('John', response.json()['data'])
Пример #4
0
    def test_signin(self):
        test = {
            'name': 'yerin',
            'password': '******',
        }
        response = Client().post('/user/auth',
                                 json.dumps(test),
                                 content_type='application/json')

        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.json(),
                         {"access_token": response.json()["access_token"]})
Пример #5
0
    def test_registration(self):
        # No body
        response = Client().post(reverse('registration'),
                                 content_type="application/json")
        self.assertEqual(response.status_code, 400)
        self.assertEqual(response.json()['result'], None)

        # Empty password
        body = {'password': ''}
        response = Client().post(reverse('registration'),
                                 body,
                                 content_type="application/json")
        self.assertEqual(response.status_code, 400)
        self.assertEqual(response.json()['result'], None)
        self.assertEqual(response.json()['error'], 'Password can not be empty')
Пример #6
0
    def test_filter(self):
        """ Test filtering API """
        result_1 = Client().get('/Currency/?iso=INR',
                                content_type='application/json')

        self.assertEqual(result_1.status_code, status.HTTP_200_OK)
        self.assertEqual((result_1.json()['results'])[0]['iso'], 'INR')
Пример #7
0
    def test_filter(self):
        """ Test filtering API """
        result_1 = Client().get('/Domain/?search=BING_1',
                                content_type='application/json')

        self.assertEqual(result_1.status_code, status.HTTP_200_OK)
        self.assertEqual((result_1.json()['results'])[0]['name'], 'BING_1')
Пример #8
0
def test_json_empty():
    resp = Client().post("/json-validation", content_type="application/json")
    assert resp.status_code == 400
    assert resp.json() == {
        "message": "Bad request",
        "errors": {"id": "is required"},
    }
Пример #9
0
def test_async_query_extra_params():
    resp = Client().get("/async/query-validation?id=1&foo=bar")
    assert resp.status_code == 400
    assert resp.json() == {
        "message": "Bad request",
        "errors": {"foo": "foo is not allowed key"},
    }
Пример #10
0
    def test_user_info_get_gender_null_success(self):
        user_number = ''.join(
            random.choice(string.ascii_uppercase + string.digits)
            for x in range(12))

        token = jwt.encode({
            "email": "*****@*****.**"
        },
                           SECRET_KEY,
                           algorithm=ALGORITHM).decode('utf-8')

        cache.get_or_set(user_number, token)

        response = Client().get('/user/info',
                                **{'HTTP_Authorization': user_number},
                                content_type='application/json')

        self.assertEqual(
            response.json(), {
                "user_info": {
                    "id": 2,
                    "name": "홍",
                    "nickname": "dev",
                    "phone_number": "01012345678",
                    "email": "*****@*****.**",
                    "gender": None
                }
            })
        self.assertEqual(response.status_code, 200)
Пример #11
0
 def testToken(self):
     test = {'email': '*****@*****.**', 'password': '******'}
     response = Client().post('/user/signin',
                              json.dumps(test),
                              content_type='applications/json')
     access_token = response.json()['access_token']
     return access_token
Пример #12
0
def test_async_query_wrong_type():
    resp = Client().get("/async/query-validation?id=foo")
    assert resp.status_code == 400
    assert resp.json() == {
        "message": "Bad request",
        "errors": {"id": "value can't be converted to int"},
    }
Пример #13
0
 def test_user_signin_email_check(self):
     test = {'email': '*****@*****.**', 'password': '******'}
     response = Client().post('/user/signin',
                              json.dumps(test),
                              content_type='applications/json')
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.json(), {'message': 'INVALID_USER'})
Пример #14
0
 def test_user_signin_except_check(self):
     test = {'Email': '*****@*****.**', 'password': '******'}
     response = Client().post('/user/signin',
                              json.dumps(test),
                              content_type='applications/json')
     self.assertEqual(response.status_code, 400)
     self.assertEqual(response.json(), {'message': 'INVALID_KEYS'})
Пример #15
0
def test_query_empty():
    resp = Client().get("/query-validation")
    assert resp.status_code == 400
    assert resp.json() == {
        "message": "Bad request",
        "errors": {"id": "is required"},
    }
Пример #16
0
    def test_pagination(self):
        """ Test pagination feature """
        result_1 = Client().get('/Currency/?limit=1',
                                content_type='application/json')

        self.assertEqual(result_1.status_code, status.HTTP_200_OK)
        self.assertEqual(result_1.json()['next'],
                         'http://testserver/Currency/?limit=1&offset=1')
Пример #17
0
 def test_post_not_exist(self):
     res = Client().post(
         '/api/u/user/bind/', {
             'openid': 'not_exist_',
             'student_id': '2016013999',
             'password': '******'
         })
     self.assertNotEqual(res.json()['code'], 0)
Пример #18
0
    def test_list(self):
        """ Test list API """

        # Create an instance of a GET request.
        list_data = Client().get('/Domain/', content_type='application/json')

        self.assertEqual(list_data.status_code, status.HTTP_200_OK)
        self.assertEqual(list_data.json()['count'], 3)
Пример #19
0
    def test_sign_in_post_password_key_fail(self):
        user_data = {"email": "*****@*****.**"}
        response = Client().post('/user/sign-in',
                                 json.dumps(user_data),
                                 content_type='application/json')

        self.assertEqual(response.json(), {"error": "INVALID_KEYS"})
        self.assertEqual(response.status_code, 400)
Пример #20
0
    def test_sign_in_post_email_fail(self):
        user_data = {"email": "*****@*****.**", "password": "******"}
        response = Client().post('/user/sign-in',
                                 json.dumps(user_data),
                                 content_type='application/json')

        self.assertEqual(response.json(), {"error": "USER_DOES_NOT_EXIST"})
        self.assertEqual(response.status_code, 400)
Пример #21
0
    def test_sign_in_post_password_fail(self):
        user_data = {"email": "*****@*****.**", "password": "******"}
        response = Client().post('/user/sign-in',
                                 json.dumps(user_data),
                                 content_type='application/json')

        self.assertEqual(response.json(), {"error": "WRONG_PASSWORD"})
        self.assertEqual(response.status_code, 401)
Пример #22
0
    def setUp(self):
        no_exp = Client().post('/api/shortner/create/',
                               json.dumps({'url': 'www.google.com'}),
                               content_type='application/json')

        _url = no_exp.json()['url']
        self.url_hash = _url[_url.rfind('/') + 1:]
        self.url = '/api/shortner/usage/'
Пример #23
0
 def test_post_has_bind(self):
     res = Client().post(
         '/api/u/user/bind/', {
             'openid': 'has_bind',
             'student_id': '2016013210',
             'password': '******'
         })
     self.assertNotEqual(res.json()['code'], 0)
Пример #24
0
 def test_post_conflict(self):
     res = Client().post(
         '/api/u/user/bind/', {
             'openid': 'wrong_bind',
             'student_id': '2016013666',
             'password': '******'
         })
     self.assertNotEqual(res.json()['code'], 0)
Пример #25
0
def test_json_wrong_type():
    resp = Client().post(
        "/json-validation", {"id": "foo"}, content_type="application/json"
    )
    assert resp.status_code == 400
    assert resp.json() == {
        "message": "Bad request",
        "errors": {"id": "value can't be converted to int"},
    }
Пример #26
0
 def create_calendar(self, token, return_response=False):
     calendar_data = {'name': 'Test Calendar Name'}
     response = Client().post('/events/calendars/',
                              json.dumps(calendar_data),
                              'application/json',
                              HTTP_AUTHORIZATION='Token ' + token)
     if return_response:
         return response
     return response.json()
Пример #27
0
    def test_signin_view_post_success(self):
        user    = {
            'email'     : '*****@*****.**',
            'password'  : '12Ab34Cd!!',
        }
        response    = Client().post('/account/signin', json.dumps(user), content_type='applications/json')
        token       = response.json()['Authorization']

        self.assertEqual(response.status_code, 200)
Пример #28
0
 def fetch_token(self, return_response=False):
     test_user_data = {
         'email': test_user_email,
         'password': test_user_password
     }
     response = Client().post('/users/tokens/', json.dumps(test_user_data),
                              'application/json')
     if return_response:
         return response
     return response.json()['token']
Пример #29
0
 def test_get_403(self):
     response = Client().get(
         reverse("pl_sandbox:request-detail", args=(self.request.pk, )))
     expected = {
         "status": False,
         "message": "Missing view permission on Request",
         "code": ErrorCode.PermissionDenied.value
     }
     self.assertEqual(403, response.status_code)
     self.assertEqual(expected, response.json())
Пример #30
0
 def test_delete_403(self):
     response = Client().delete(
         reverse("pl_sandbox:sandbox-detail", args=(1, )))
     expected = {
         "status": False,
         "message": "Missing delete permission on Sandbox",
         "code": ErrorCode.PermissionDenied.value
     }
     self.assertEqual(403, response.status_code)
     self.assertDictEqual(expected, response.json())
Пример #31
0
    def test_post(self):
        response = Client().post('/api/v2/accounts', {
            'username': '******',
            'password1': 'a',
            'password2': 'a',
        })
        self.assertTrue(response.json()['ok'])

        response = self.client.post('/api/v2/auth', {
            'username': '******',
            'password': '******',
        })
        self.assertFalse(response.json()['ok'])

        response = self.client.get('/api/v2/auth')
        self.assertFalse(response.json()['ok'])

        response = self.client.post('/api/v2/auth', {
            'username': '******',
            'password': '******',
        })
        self.assertTrue(response.json()['ok'])
        session_key = response.json()['session_key']

        response = self.client.get('/api/v2/auth', HTTP_X_ANIMETA_SESSION_KEY=session_key)
        self.assertTrue(response.json()['ok'])
Пример #32
0
    def test_get(self):
        """
        The manifest is valid JSON served with the application/manifest+json
        content type.
        """
        # Setting HOT to True prevents the latest_static template tag from
        # listing files in the static directory which doesn't necessarily exist
        # (particularly on CI).
        with self.settings(HOT=True):
            response = Client().get('/manifest.webmanifest')

        self.assertEqual(200, response.status_code)
        self.assertEqual('application/manifest+json', response['Content-Type'])

        manifest = response.json()
        self.assertEqual('Yarrharr', manifest['name'])