Skip to content

Commit

Permalink
corrigindo erros de teste
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroBinotto committed Sep 6, 2024
1 parent 89a0b63 commit 0e631d1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 14 deletions.
14 changes: 14 additions & 0 deletions metrify/github/auth/model.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
"""
metrify/github/auth/model/__init__.py
Exports Pydantic model classes for the github module
"""

from datetime import datetime
from enum import Enum
from pydantic import BaseModel


class PermissionsEnum(str, Enum):
"""Github API PermissionsEnum model for deserialization"""
# pylint: disable=invalid-name
read = "read"
# pylint: disable=invalid-name
write = "write"


class RepositorySelectionEnum(str, Enum):
"""Github API RepositorySelectionEnum model for deserialization"""
# pylint: disable=invalid-name
all = "all"
# pylint: disable=invalid-name
selected = "selected"


class Permissions(BaseModel):
"""Github API Permissions model for deserialization"""
organization_projects: PermissionsEnum
issues: PermissionsEnum
metadata: PermissionsEnum
repository_projects: PermissionsEnum


class AuthResponse(BaseModel):
"""Github API AuthResponse model for deserialization"""
token: str
expires_at: datetime
permissions: Permissions
Expand Down
2 changes: 0 additions & 2 deletions mypy.ini
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,3 @@ warn_unused_configs = True
# Disable errors
disable_error_code = import-untyped
# FIXME: remover quando adicionar stubs que faltam

enable-incomplete-feature=NewGenericSyntax
6 changes: 3 additions & 3 deletions stubs/flask_apscheduler/scheduler.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ from typing_extensions import Unpack

from flask import Flask

type Args = list[Any] | tuple[Any] | None # type: ignore[misc, valid-type] # noqa: F821
type Kwargs = dict[Any, Any] | None # type: ignore[misc, valid-type] # noqa: F821
type F = Callable[[Any], Any] | Never # type: ignore[misc, valid-type] # noqa: F821
type Args = list[Any] | tuple[Any] | None # type: ignore[valid-type] # noqa: F821
type Kwargs = dict[Any, Any] | None # type: ignore[valid-type] # noqa: F821
type F = Callable[[Any], Any] | Never # type: ignore[valid-type] # noqa: F821

class _Undefined(object): ...
class BaseTrigger(object): ...
Expand Down
8 changes: 4 additions & 4 deletions stubs/flask_pymongo/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from typing import Any
from flask import Flask, Response

type Kwargs = Any # type: ignore[misc, valid-type] # noqa: F821
type Args = Any # type: ignore[misc, valid-type] # noqa: F821
type File = Any # type: ignore[misc, valid-type] # noqa: F821
type Id = Any # type: ignore[misc, valid-type] # noqa: F821
type Kwargs = Any # type: ignore[valid-type] # noqa: F821
type Args = Any # type: ignore[valid-type] # noqa: F821
type File = Any # type: ignore[valid-type] # noqa: F821
type Id = Any # type: ignore[valid-type] # noqa: F821

class PyMongo(object):
def __init__(
Expand Down
15 changes: 10 additions & 5 deletions tests/github/auth/test_strategies.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,25 @@
Test suite for metrify.github.auth.strategies
"""

from sys import path
from typing import Any, Generator, Tuple
from unittest.mock import MagicMock, patch
from pytest import raises
import pytest

from requests import RequestException

from metrify.github.auth.model import AuthResponse
from metrify.github.auth.strategies import get_access_token

type Fixture = Tuple[Any, Any, Any, Any, Any]


class MockAuthResponse:
"""Test class for mocking metrify.github.auth.model.AuthResponse"""

def __init__(self, token: str):
self.token = token


class TestGetAccessToken:
"""Test suite for `get_access_token` function"""

Expand Down Expand Up @@ -45,16 +50,16 @@ def test_returns_token(
Should correctly extract and return the 'token' attribute value from
the response body
"""

jwt, installation_id, url, headers, timeout = data

token_value = "test_token"
response_content = "{ token: { " + token_value + " } }"
response_content = "{ 'token': 'test_token' }"
parsed_response = MockAuthResponse(token_value)

response = MagicMock()
response.content = response_content
mock_post.return_value = response
mock_parse.return_value = token_value
mock_parse.return_value = parsed_response

result = get_access_token(jwt, installation_id)

Expand Down

0 comments on commit 0e631d1

Please sign in to comment.