Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
A
ap-11_django
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Давид Ли
ap-11_django
Commits
56561978
Commit
56561978
authored
Nov 01, 2023
by
Давид Ли
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
esdp
parent
c0fd7ea9
Show whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
253 additions
and
11 deletions
+253
-11
.DS_Store
.DS_Store
+0
-0
environment.py
accounts/features/environment.py
+13
-0
login.feature
accounts/features/login.feature
+16
-0
login.py
accounts/features/steps/login.py
+37
-0
tests.py
accounts/tests.py
+47
-1
views.py
accounts/views.py
+9
-7
views.py
api/views.py
+1
-1
celery.py
core/celery.py
+1
-0
settings.py
core/settings.py
+2
-1
docker-compose.yml
docker-compose.yml
+48
-0
Dockerfile
docker/Dockerfile
+12
-0
reqs.txt
reqs.txt
+14
-0
tests.py
web/tests.py
+53
-1
No files found.
.DS_Store
View file @
56561978
No preview for this file type
accounts/features/environment.py
0 → 100644
View file @
56561978
from
behave
import
fixture
,
use_fixture
from
selenium.webdriver
import
Chrome
@
fixture
def
browser_chrome
(
context
):
context
.
browser
=
Chrome
()
yield
context
.
browser
context
.
browser
.
quit
()
def
before_all
(
context
):
use_fixture
(
browser_chrome
,
context
)
accounts/features/login.feature
0 → 100644
View file @
56561978
Feature
:
Вход
Scenario
:
Вход под админом
Given
Я открыл страницу
"Входа"
When
Я ввожу текст
"admin"
в поле
"username"
And
Я ввожу текст
"root"
в поле
"password"
And
Я отправляю форму
Then
Я должен быть на главной странице
Scenario
:
Не успешный вход
Given
Я открыл страницу
"Входа"
When
Я ввожу текст
"admindsf"
в поле
"username"
And
Я ввожу текст
"admindsf"
в поле
"password"
When
Я отправляю форму
Then
Я должен быть на странице входа
And
Я должен видеть сообщение об ошибке
accounts/features/steps/login.py
0 → 100644
View file @
56561978
from
behave
import
given
,
when
,
then
from
selenium.webdriver.common.by
import
By
from
selenium.webdriver.common.action_chains
import
ActionChains
@
given
(
u'Я открыл страницу "Входа"'
)
def
open_login_page
(
context
):
context
.
browser
.
get
(
'http://localhost:1026/auth/login/'
)
@
when
(
u'Я ввожу текст "{text}" в поле "{name}"'
)
def
enter_text
(
context
,
text
,
name
):
context
.
browser
.
find_element
(
By
.
NAME
,
name
)
.
send_keys
(
text
)
@
when
(
u'Я отправляю форму'
)
def
submit_form
(
context
):
button
=
context
.
browser
.
find_element
(
By
.
CLASS_NAME
,
'btn'
)
context
.
browser
.
implicitly_wait
(
10
)
ActionChains
(
context
.
browser
)
.
move_to_element
(
button
)
.
click
(
button
)
.
perform
()
@
then
(
u'Я должен быть на главной странице'
)
def
should_be_at_main_page
(
context
):
assert
context
.
browser
.
current_url
==
'http://localhost:1026/articles/'
@
then
(
u'Я должен быть на странице входа'
)
def
should_be_at_login_page
(
context
):
assert
context
.
browser
.
current_url
==
'http://localhost:1026/auth/login/?next='
@
then
(
u'Я должен видеть сообщение об ошибке'
)
def
should_see_error
(
context
):
error
=
context
.
browser
.
find_element
(
By
.
CLASS_NAME
,
'alert-danger'
)
assert
error
.
text
==
'Пожалуйста, введите правильные имя пользователя и пароль. Оба поля могут быть чувствительны к регистру.'
accounts/tests.py
View file @
56561978
from
django.test
import
TestCase
from
selenium.webdriver
import
Chrome
from
selenium.webdriver.common.by
import
By
from
selenium.webdriver.common.action_chains
import
ActionChains
# Create your tests here.
class
LoginTestCase
(
TestCase
):
def
setUp
(
self
)
->
None
:
self
.
driver
=
Chrome
()
def
tearDown
(
self
)
->
None
:
self
.
driver
.
close
()
def
test_log_in_as_admin
(
self
):
self
.
get_url
(
'http://localhost:1026/auth/login/'
)
self
.
fill_input_by_name
(
'username'
,
'admin'
)
self
.
fill_input_by_name
(
'password'
,
'root'
)
self
.
click_button
()
self
.
check_url
(
'http://localhost:1026/articles/'
)
def
test_log_in_error
(
self
):
self
.
get_url
(
'http://localhost:1026/auth/login/'
)
self
.
fill_input_by_name
(
'username'
,
'admindsf'
)
self
.
fill_input_by_name
(
'password'
,
'roodasfasdf'
)
self
.
click_button
()
self
.
check_url
(
'http://localhost:1026/auth/login/?next='
)
self
.
see_error_with_text
(
'Пожалуйста, введите правильные имя пользователя и пароль. Оба поля могут быть чувствительны к регистру.'
)
def
click_button
(
self
):
button
=
self
.
driver
.
find_element
(
By
.
CLASS_NAME
,
'btn'
)
self
.
driver
.
implicitly_wait
(
10
)
ActionChains
(
self
.
driver
)
.
move_to_element
(
button
)
.
click
(
button
)
.
perform
()
def
get_url
(
self
,
url
):
self
.
driver
.
get
(
url
)
def
fill_input_by_name
(
self
,
name
,
text
):
self
.
driver
.
find_element
(
By
.
NAME
,
name
)
.
send_keys
(
text
)
def
check_url
(
self
,
url
):
assert
self
.
driver
.
current_url
==
url
def
see_error_with_text
(
self
,
text
):
error
=
self
.
driver
.
find_element
(
By
.
CLASS_NAME
,
'alert-danger'
)
assert
error
.
text
==
text
accounts/views.py
View file @
56561978
...
...
@@ -13,13 +13,15 @@ from accounts.models import User, Profile
class
AuthSuccessUrlMixin
:
def
get_success_url
(
self
):
return
self
.
request
.
GET
.
get
(
'next'
,
self
.
request
.
POST
.
get
(
'next'
,
reverse_lazy
(
'main_page'
)
)
)
url
=
self
.
request
.
GET
.
get
(
'next'
)
if
not
url
:
url
=
self
.
request
.
POST
.
get
(
'next'
)
if
not
url
:
return
reverse_lazy
(
'main_page'
)
return
url
class
LoginView
(
AuthSuccessUrlMixin
,
views
.
LoginView
):
...
...
api/views.py
View file @
56561978
core/celery.py
0 → 100644
View file @
56561978
REDIS_URL
=
'redis://redis:6379/0'
\ No newline at end of file
core/settings.py
View file @
56561978
...
...
@@ -40,6 +40,7 @@ INSTALLED_APPS = [
'django.contrib.messages'
,
'django.contrib.staticfiles'
,
'django_extensions'
,
'behave_django'
,
'rest_framework'
,
'rest_framework.authtoken'
,
...
...
@@ -148,7 +149,7 @@ SHELL_PLUS = "bpython"
AUTH_USER_MODEL
=
'accounts.User'
LOGIN_URL
=
'login'
#
LOGIN_REDIRECT_URL = 'main_page'
LOGIN_REDIRECT_URL
=
'main_page'
# LOGOUT_REDIRECT_URL = 'main_page'
faker
=
Faker
()
...
...
docker-compose.yml
0 → 100644
View file @
56561978
version
:
'
3'
services
:
postgres
:
image
:
postgres:14-alpine
environment
:
-
POSTGRES_PASSWORD=postgres
app
:
build
:
dockerfile
:
docker/Dockerfile
ports
:
-
"
1026:8000"
depends_on
:
-
postgres
volumes
:
-
.:/usr/src/app
command
:
bash -c "python manage.py makemigrations --merge --noinput &&
python manage.py migrate --noinput &&
python manage.py runserver 0.0.0.0:8000"
redis
:
image
:
redis
celery
:
build
:
dockerfile
:
docker/Dockerfile
command
:
celery -A core/celery.py worker -l info
volumes
:
-
.:/usr/src/app
depends_on
:
-
postgres
-
redis
environment
:
-
TZ=Asia/Almaty
celery-beat
:
build
:
dockerfile
:
docker/Dockerfile
command
:
celery -A core/celery.py beat -l info
volumes
:
-
.:/usr/src/app
depends_on
:
-
postgres
-
redis
environment
:
-
TZ=Asia/Almaty
docker/Dockerfile
0 → 100644
View file @
56561978
FROM
python:3.10-slim
RUN
apt update
&&
apt
install
-y
gcc
ENV
PYTHONDONTWRITEBYTECODE 1
WORKDIR
/usr/src/app
COPY
reqs.txt ./reqs.txt
RUN
pip
install
--upgrade
pip
&&
pip
install
-r
reqs.txt
COPY
. .
reqs.txt
View file @
56561978
amqp==5.1.1
asgiref==3.7.2
billiard==4.1.0
blessed==1.20.0
bpython==0.24
celery==5.3.4
certifi==2023.5.7
charset-normalizer==3.2.0
click==8.1.7
click-didyoumean==0.3.0
click-plugins==1.1.1
click-repl==0.3.0
curtsies==0.4.1
cwcwidth==0.1.8
Django==3.2.19
django-extensions==3.2.3
djangorestframework==3.14.0
Faker==19.12.0
greenlet==2.0.2
idna==3.4
kombu==5.3.2
Pillow==10.0.0
prompt-toolkit==3.0.39
Pygments==2.15.1
python-dateutil==2.8.2
pytz==2023.3
pyxdg==0.28
requests==2.31.0
six==1.16.0
sqlparse==0.4.4
typing_extensions==4.8.0
tzdata==2023.3
urllib3==2.0.3
vine==5.0.0
wcwidth==0.2.6
web/tests.py
View file @
56561978
from
django.test
import
TestCase
from
web.models
import
Article
from
accounts.models
import
User
# Create your tests here.
class
ArticleTestCase
(
TestCase
):
def
setUp
(
self
):
admin
=
User
.
objects
.
create
(
username
=
'admin'
,
password
=
'root'
)
admin
.
is_superuser
=
True
admin
.
save
()
self
.
client
.
login
(
username
=
'admin'
,
password
=
'root'
)
a1
=
Article
.
objects
.
create
(
title
=
'Test 1'
,
text
=
'Test text 1'
)
a2
=
Article
.
objects
.
create
(
title
=
'Test 2'
,
text
=
'Test text 2'
)
a3
=
Article
.
objects
.
create
(
title
=
'Test 3'
,
text
=
'Test text 3'
)
self
.
articles
=
[
a1
,
a2
,
a3
]
def
test_update_article_success
(
self
):
article
=
self
.
articles
[
0
]
update_data
=
{
'title'
:
'Article'
,
'text'
:
'article text'
}
article
.
title
=
update_data
[
'title'
]
article
.
text
=
update_data
[
'text'
]
article
.
save
()
article_from_db
=
Article
.
objects
.
get
(
id
=
article
.
id
)
assert
article_from_db
.
title
==
update_data
[
'title'
]
assert
article_from_db
.
text
==
update_data
[
'text'
]
def
test_update_article_error
(
self
):
article
=
self
.
articles
[
0
]
update_data
=
{
'title'
:
'Article'
,
'text'
:
'article text'
}
article
.
title
=
update_data
[
'title'
]
article
.
text
=
update_data
[
'text'
]
article_from_db
=
Article
.
objects
.
get
(
id
=
article
.
id
)
assert
not
article_from_db
.
title
==
update_data
[
'title'
]
assert
not
article_from_db
.
text
==
update_data
[
'text'
]
def
test_create_article_success
(
self
):
data
=
{
'title'
:
'title'
,
'text'
:
'text'
}
response
=
self
.
client
.
post
(
'/api/article/'
,
data
=
data
)
assert
response
.
status_code
==
201
Article
.
objects
.
update
(
status
=
'accepted'
)
assert
Article
.
objects
.
filter
(
title
=
data
[
'title'
])
.
exists
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment