def test_verify_csrf(self): auth_token = self.get_token() response = c.post('/api/authe/csrf/verify/', { AUTH_TOKEN_HEADER: auth_token, 'csrf_token': token.generate_csrf('m') }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.OK)
def test_facebook_login_wrong_token(self): response = c.post('/api/authe/facebook_login/', {'access_token': TEST_FB_ACCESS_TOKEN + 'UJ47'}, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.FB_OAUTH_TOKEN_INVALID)
def test_register_ok_without_full_name(self): response = c.post('/api/authe/register/', { 'email': TEST_USERNAME, 'password': TEST_PASSWORD }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.OK)
def test_register_bad_email3(self): response = c.post('/api/authe/register/', { 'email': 'mtemirulan@xcom', 'password': TEST_PASSWORD }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.BAD_EMAIL)
def test_create_invalid_dates(self): auth_token = self.get_token() params = { AUTH_TOKEN_HEADER: auth_token, "title": "Test title", "poll_type": 3, "date_begin": get_timestamp_in_milli(), "date_end": get_timestamp_in_milli(), "sc_choices[]": [ '{"value":"What is she?", "priority":"1"}', '{"value":"What is he?", "priority":"2"}' ] } response = c.post('/api/moderators/template/create/', params, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.INVALID_POLL_TYPE)
def test_create_categories_match(self): auth_token = self.get_token() category, _ = Category.objects.get_or_create(name="soccer") params = { AUTH_TOKEN_HEADER: auth_token, "title": "Test title", "poll_type": 1, "date_begin": get_timestamp_in_milli(), "date_end": get_timestamp_in_milli(), "sc_choices[]": [ '{"value":"What is she?", "priority":"1"}', '{"value":"What is he?", "priority":"2"}' ], "category_ids[]": [category.id, 2] } response = c.post('/api/moderators/template/create/', params, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.CATEGORIES_DOESNT_MATCH)
def test_reset_password_user_not_found(self): response = c.post( '/api/authe/reset/', {'username': '******'}, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.USERNAME_NOT_FOUND)
def test_get_articles_ok(self): auth_token = self.get_token() params = {AUTH_TOKEN_HEADER: auth_token} response = c.post('/api/moderators/articles/get/', params, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test_ok(response)
def test_poll_feed_ok(self): auth_token = self.get_token() params = {AUTH_TOKEN_HEADER: auth_token} response = c.post('/api/moderators/polls/feed/', params, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test_ok(response)
def test_get_polls_by_title_ok(self): auth_token = self.get_token() params = {AUTH_TOKEN_HEADER: auth_token, "poll_title": "Test title"} response = c.post('/api/moderators/polls/get_polls_by_title/', params, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test_ok(response)
def test_reset_password_ok(self): user, _ = User.objects.get_or_create(email=TEST_USERNAME) user.set_password(TEST_PASSWORD) user.is_active = True user.save() response = c.post('/api/authe/reset/', {'username': TEST_USERNAME}, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.OK)
def test_login_wrong_username(self): response = c.post('/api/authe/login/', { 'username': TEST_USERNAME, 'password': TEST_PASSWORD }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.USERNAME_NOT_FOUND)
def test_sms_user_activate_code_ok(self): response = c.post('/api/authe/sms_activate/', { 'phone': TEST_PHONE, 'code': CODE }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.ACTIVATION_CODE_NOT_FOUND)
def test_sms_user_activate_ok(self): Activation.objects.generate(username=TEST_PHONE, code=CODE) response = c.post('/api/authe/sms_activate/', { 'phone': TEST_PHONE, 'code': CODE }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.OK)
def test_logout_ok(self): auth_token = self.get_token() response = c.post('/api/authe/logout/', { AUTH_TOKEN_HEADER: auth_token, 'token_string': token }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.OK)
def test_feed(self): self.get_token() params = { AUTH_TOKEN_HEADER: self.token, } response = c.post('/api/polls/feed/', params, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test_ok(response)
def test_register_missing_email(self): response = c.post('/api/authe/register/', { 'full_name': 'Temirulan Mussayev', 'password': '******' }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.MISSING_REQUIRED_PARAMS)
def test_get_article_poll_article_not_found(self): self.get_token() params = { AUTH_TOKEN_HEADER: self.token, "article_id": 1 } response = c.post('/api/polls/article/get/', params, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.ARTICLE_NOT_FOUND)
def test_get_random_poll_not_found(self): self.get_token() params = { AUTH_TOKEN_HEADER: self.token, } response = c.post('/api/polls/get_random_poll/', params, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.POLL_NOT_FOUND)
def test_category_delete_ok(self): user_info = self.get_token_and_user() Category.objects.create(id=1) params = {AUTH_TOKEN_HEADER: user_info['token'], 'category_id': 1} response = c.post('/api/moderators/category/delete/', params, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test_ok(response)
def test_category_read_not_found(self): user_info = self.get_token_and_user() params = {AUTH_TOKEN_HEADER: user_info['token'], 'category_id': 1} response = c.post('/api/moderators/category/read/', params, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.CATEGORY_NOT_FOUND)
def test_update_profile_bad_email3(self): auth_token = self.get_token() response = c.post('/api/authe/update_profile/', { AUTH_TOKEN_HEADER: auth_token, 'email': 'mtemirulan@xcom', 'full_name': 'Some Awesome Guy' }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.BAD_EMAIL)
def test_update_profile_bad_email2(self): auth_token = self.get_token() response = c.post('/api/authe/update_profile/', { AUTH_TOKEN_HEADER: auth_token, 'email': 'sashachernov4@gmail', 'full_name': 'Tim' }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.BAD_EMAIL)
def test_register_wrong_password1(self): response = c.post('/api/authe/register/', { 'email': TEST_EMAIL, 'full_name': 'Temirulan Mussayev', 'password': '******' }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.PASSWORD_LENGTH_ERROR)
def test_get_article_poll_article_poll_none(self): self.get_token() article, _ = Article.objects.get_or_create(article_url=TEST_ARTICLE_URL) params = { AUTH_TOKEN_HEADER: self.token, "article_id": article.id } response = c.post('/api/polls/article/get/', params, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.ARTICLE_POLL_NONE)
def test_activate_new_phone_code_not_found(self): auth_token = self.get_token() response = c.post('/api/authe/profile/activate_new_phone/', { AUTH_TOKEN_HEADER: auth_token, 'code': CODE }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.ACTIVATION_CODE_NOT_FOUND)
def test_add_delete_category_found_ok(self): auth_token = self.get_token() response = c.post('/api/authe/profile/category/add_delete/', { AUTH_TOKEN_HEADER: auth_token, 'category_id': '1' }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.CATEGORY_NOT_FOUND)
def test_update_user_categories_match_ok(self): auth_token = self.get_token() response = c.post('/api/authe/profile/categories/', { AUTH_TOKEN_HEADER: auth_token, 'category_ids[]': ['1'] }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.CATEGORIES_DOESNT_MATCH)
def test_update_profile_ok(self): auth_token = self.get_token() response = c.post('/api/authe/update_profile/', { AUTH_TOKEN_HEADER: auth_token, 'email': TEST_EMAIL, 'full_name': 'Temirulan Mussayev' }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.OK)
def test_change_password_ok(self): auth_token = self.get_token() response = c.post('/api/authe/change_password/', { AUTH_TOKEN_HEADER: auth_token, 'current_password': TEST_PASSWORD, 'new_password': '******' }, HTTP_CSRF_TOKEN=token.generate_csrf('m')) self.common_test(response, status_code=STATUS_OK, code=codes.OK)