Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Письменов Дмитрий Иванович
/
yourroomads
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Settings
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 409d0b5d
authored
Jun 08, 2021
by
Vladislav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#19466 Остановка РК (исправление тестов)
1 parent
ce22f089
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
20 additions
and
18 deletions
app/Service/API/YandexDirect.php
app/Service/Limits.php
tests/Unit/LimitsTest.php
tests/Unit/ProcessCallSliceTest.php
app/Service/API/YandexDirect.php
View file @
409d0b5
...
...
@@ -42,7 +42,6 @@ class YandexDirect extends API{
public
function
execute
()
:
Response
{
print_r
(
$this
->
request
->
getBody
());
return
Http
::
withBody
(
$this
->
request
->
getBody
(),
'none'
)
->
withHeaders
(
$this
->
request
->
getHeaders
())
->
withToken
(
$this
->
request
->
getToken
()
->
token
)
...
...
app/Service/Limits.php
View file @
409d0b5
...
...
@@ -71,16 +71,16 @@ class Limits implements \App\Service\Contract\Limits {
}
if
(
$this
->
token
->
limits
->
count
()
>
0
){
$objectsCount
=
$request
->
getObjectsCount
();
if
(
$this
->
token
->
limits
->
count
()
>
0
){
if
(
$this
->
limitCosts
->
getCostCall
(
$request
)
>
$this
->
current
()){
return
0
;
}
$allowCount
=
floor
((
$this
->
current
()
-
$this
->
limitCosts
->
getCostCall
(
$request
))
/
$cost
);
$objectsCount
=
$request
->
getObjectsCount
();
}
else
{
$allowCount
=
$maxCount
;
//не было еще запросов, считаем что баллов хватает
$objectsCount
=
$maxCount
;
$allowCount
=
$objectsCount
;
//не было еще запросов, считаем что баллов хватает
}
...
...
@@ -106,7 +106,8 @@ class Limits implements \App\Service\Contract\Limits {
function
doRezerv
(
\App\Service\Contract\APIRequest
$request
,
int
$objects
)
:
int
{
$limit
=
$this
->
getSpent
(
$objects
,
$request
);
if
(
$this
->
token
->
limits
->
count
()
>
1
&&
$this
->
token
->
limit
<
$limit
){
if
(
$this
->
token
->
limits
->
count
()
>
0
&&
$this
->
token
->
limit
<
$limit
)
{
throw
new
\Exception
(
'Недостаточно баллов'
);
}
...
...
@@ -196,7 +197,7 @@ class Limits implements \App\Service\Contract\Limits {
}
}
private
function
getSpent
(
$objects
,
\App\Service\Contract\APIRequest
$request
)
:
int
function
getSpent
(
$objects
,
\App\Service\Contract\APIRequest
$request
)
:
int
{
$cost
=
$this
->
limitCosts
->
getCostObject
(
$request
);
...
...
tests/Unit/LimitsTest.php
View file @
409d0b5
...
...
@@ -159,14 +159,17 @@ class LimitsTest extends TestCase
Queue
::
fake
();
$requestCmpgn
=
$request
->
getRequest
(
'Campaigns'
,
'get'
);
$this
->
token
->
limit
=
191
;
$requestCmpgn
->
call
();
$objects
=
$this
->
limitService
->
countObjectsLimit
(
$requestCmpgn
);
$this
->
assertEquals
(
$objects
,
181
);
$this
->
token
->
save
();
$this
->
token
->
limit
=
DirectRequest
::
MAX_COUNT
+
100
;
$requestCmpgn
->
call
();
$objects
=
$this
->
limitService
->
countObjectsLimit
(
$requestCmpgn
);
$this
->
assertEquals
(
$objects
,
DirectRequest
::
MAX_COUNT
);
$this
->
limitService
->
doRezerv
(
$requestCmpgn
,
$objects
);
$this
->
token
->
refresh
();
$this
->
assertEquals
(
$this
->
token
->
limit
,
181
);
$requestCmpgn
=
$request
->
getRequest
(
'Campaigns'
,
'update'
);
$this
->
token
->
limit
=
191
;
...
...
tests/Unit/ProcessCallSliceTest.php
View file @
409d0b5
...
...
@@ -98,10 +98,9 @@ class ProcessCallSliceTest extends TestCase
$this
->
request
->
call
(
$this
->
params
);
$this
->
request_resume
->
call
([
'ids'
=>
range
(
0
,
$this
->
dictionaries_count
-
1
)
'ids'
=>
range
(
1
,
2005
)
]);
Queue
::
assertPushed
(
ProcessCallLimitedAPI
::
class
);
$limits
=
Limits
::
getInstance
(
$this
->
request
->
getToken
());
...
...
@@ -113,8 +112,8 @@ class ProcessCallSliceTest extends TestCase
$requestR
=
$this
->
request
->
slice
(
$maxObjects
);
$this
->
assertEquals
(
true
,
!!
$requestR
);
$this
->
assertEquals
(
2
,
$this
->
request
->
getObjectsCount
());
$this
->
assertEquals
(
$this
->
dictionaries_count
-
2
,
$requestR
->
getObjectsCount
());
$this
->
assertEquals
(
$this
->
request
->
getMaxCount
()
,
$this
->
request
->
getObjectsCount
());
$this
->
assertEquals
(
$this
->
dictionaries_count
-
$this
->
request
->
getMaxCount
()
,
$requestR
->
getObjectsCount
());
$limits
=
Limits
::
getInstance
(
$this
->
request_resume
->
getToken
());
...
...
@@ -126,8 +125,8 @@ class ProcessCallSliceTest extends TestCase
$requestR
=
$this
->
request_resume
->
slice
(
$maxObjects
);
$this
->
assertEquals
(
true
,
!!
$requestR
);
$this
->
assertEquals
(
2
,
$this
->
request_resume
->
getObjectsCount
());
$this
->
assertEquals
(
$this
->
dictionaries_count
-
2
,
$requestR
->
getObjectsCount
());
$this
->
assertEquals
(
$this
->
request_resume
->
getMaxCount
()
,
$this
->
request_resume
->
getObjectsCount
());
$this
->
assertEquals
(
2005
-
$this
->
request_resume
->
getMaxCount
()
,
$requestR
->
getObjectsCount
());
}
...
...
Write
Preview
Markdown
is supported
Attach a file
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 post a comment