Example #1
0
def test_update_user_role():
    user_id = 101
    add_new_user(user_id, datetime.now(), None)
    assert get_user_role(user_id) == 'user'
    deep_link = str(uuid4())
    _register_deep_link(1, deep_link, 'test_creator')
    update_user_role(user_id, datetime.now(), deep_link)
    assert get_user_role(user_id) == 'test_creator'
    assert not _is_valid_deep_link(deep_link)
Example #2
0
 def _handle_admin_commands(self, user_id: int, command: str) -> Answer:
     user_role = get_user_role(user_id)
     if user_role != 'admin':
         return Answer(text=self._get_default_answer('unsupported_command'))
     if command == 'create_deep_link':
         deep_link = create_deep_link(user_id)
         return Answer(text=f'Ссылка успешно создана.\n{deep_link}')
Example #3
0
 def _handle_information_commands(self, user_id: int, command: str) -> Answer:
     if get_user_role(user_id) == 'user':
         return Answer(text=self._get_default_answer('unsupported_command'))
     if command == 'languages_list':
         return Answer(text=get_formatted_languages_list())
     if command == 'test_types_list':
         return Answer(text=get_formatted_test_types_list())
Example #4
0
def test_handle_admin_commands(dispatcher, command, user_id):
    role = get_user_role(user_id)
    if role != 'admin':
        text = dispatcher._get_default_answer('unsupported_command')
    else:
        assert False
    result = dispatcher._handle_admin_commands(user_id, command)
    assert isinstance(result, Answer)
    assert result.text == text
Example #5
0
def test_handle_information_commands(dispatcher, command, user_id):
    role = get_user_role(user_id)
    if role == 'user':
        text = dispatcher._get_default_answer('unsupported_command')
    else:
        if command == 'languages_list':
            text = get_formatted_languages_list()
        else:
            text = get_formatted_test_types_list()
    result = dispatcher._handle_information_commands(user_id, command)
    assert isinstance(result, Answer)
    assert result.text == text
Example #6
0
 def _handle_start_commands(
         self, user_id: int, command: str, date: datetime, deep_link: Optional[str]
 ) -> Answer:
     if command == 'start':
         if is_new_user(user_id):
             add_new_user(user_id, date, deep_link)
         else:
             if deep_link is not None:
                 update_user_role(user_id, date, deep_link)
     self.close_session(user_id)
     role = get_user_role(user_id)
     return self._get_start_message(command, role)
Example #7
0
 def _handle_language_test_creator_commands(
         self, user_id: int, command: str, date: datetime
 ) -> Union[Answer, Tuple[Answer, CloseSession]]:
     handler_alias = 'language_test_creator_session_handler'
     user_role = get_user_role(user_id)
     if user_role == 'user':
         return Answer(text=self._get_default_answer('unsupported_command'))
     handler = self._get_handler(handler_alias)
     handler.alias = handler_alias
     try:
         session = self._create_session(user_id, date, handler)
     except UnclosedSessionError as e:
         return Answer(text=str(e))
     return handler.handle_session(session, command)
Example #8
0
def test_handle_start_commands(dispatcher, command, user_id):
    role = get_user_role(user_id)
    result = dispatcher._handle_start_commands(user_id, command,
                                               datetime.now(), None)
    assert isinstance(result, Answer)
    assert result.text == dispatcher._get_start_message(command, role).text
Example #9
0
def test_add_new_user(user_id, deep_link, final_role):
    if deep_link is not None:
        _register_deep_link(1, deep_link, 'test_creator')
    add_new_user(user_id, datetime.now(), deep_link)
    assert get_user_role(user_id) == final_role
Example #10
0
def test_get_user_role():
    assert get_user_role(1, 'role') == 'admin'
    assert get_user_role(1, 'id') == 1