示例#1
0
    def test_serializer_domain_event(self):
        event = Event(Id="Identificador0",
                      Type="Push",
                      Repo_Id=12345,
                      Repo_Name="Repo",
                      Repo_Url="https://github.com/user/repoName",
                      User="******",
                      User_Url="https://github.com/user",
                      Public=True,
                      Date="2019-10-13T23:08:50Z")

        expected_json = """
            {
                "Id": "Identificador0", 
                "Type": "Push", 
                "Repo_Id": 12345, 
                "Repo_Name": "Repo", 
                "Repo_Url": "https://github.com/user/repoName", 
                "User": "******", 
                "User_Url": "https://github.com/user", 
                "Public": true, 
                "Date": "2019-10-13T23:08:50Z" 
            }
        """

        json_event = json.dumps(event, cls=srs.EventEncoder)

        self.assertEqual(json.loads(json_event), json.loads(expected_json))
    def test_event_model_comparison(self):
        event_dict = {
            'Id' : "Identificador0", 
            'Type' : "Push", 
            'Repo_Id' : 12345, 
            'Repo_Name' : "Repo", 
            'Repo_Url' : "https://github.com/user/repoName", 
            'User' : "user", 
            'User_Url' : "https://github.com/user", 
            'Public' : True, 
            'Date' : "2019-10-13T23:08:50Z" 
        }
        
        event1 = Event.from_dict(event_dict)
        event2 = Event.from_dict(event_dict)

        self.assertEqual(event1, event2)
    def setUp(self):
        """ setUp """

        self.domain_events = [
            Event(Id="Identificador0",
                  Type="Push",
                  Repo_Id=12345,
                  Repo_Name="Repo",
                  Repo_Url="https://github.com/user/repoName",
                  User="******",
                  User_Url="https://github.com/user",
                  Public=True,
                  Date="2019-10-13T23:08:50Z"),
            Event(Id="Identificador1",
                  Type="pull",
                  Repo_Id=1234589,
                  Repo_Name="Repo",
                  Repo_Url="https://github.com/user/repoName",
                  User="******",
                  User_Url="https://github.com/user",
                  Public=True,
                  Date="2019-12-13T23:08:50Z")
        ]
    def test_event_model_init(self):

        event = Event(
            Id = "Identificador0",
            Type = "Push",
            Repo_Id = 12345,
            Repo_Name = "Repo",
            Repo_Url = "https://github.com/user/repoName",
            User = "******",
            User_Url = "https://github.com/user",
            Public = True,
            Date = "2019-10-13T23:08:50Z"
        )

        self.assertEqual(event.Id, "Identificador0")
        self.assertEqual(event.Type, "Push")
        self.assertEqual(event.Repo_Id, 12345)
        self.assertEqual(event.Repo_Name, "Repo")
        self.assertEqual(event.Repo_Url, "https://github.com/user/repoName")
        self.assertEqual(event.User, "user")
        self.assertEqual(event.User_Url, "https://github.com/user")
        self.assertEqual(event.Public, True)
        self.assertEqual(event.Date, "2019-10-13T23:08:50Z")
 def test_event_model_from_dict(self):
     
     event = Event.from_dict(
         {
             'Id' : "Identificador0", 
             'Type' : "Push", 
             'Repo_Id' : 12345, 
             'Repo_Name' : "Repo", 
             'Repo_Url' : "https://github.com/user/repoName", 
             'User' : "user", 
             'User_Url' : "https://github.com/user", 
             'Public' : True, 
             'Date' : "2019-10-13T23:08:50Z" 
         }
     )
     self.assertEqual(event.Id,  "Identificador0")
     self.assertEqual(event.Type,    "Push")
     self.assertEqual(event.Repo_Id,     12345)
     self.assertEqual(event.Repo_Name,   "Repo")
     self.assertEqual(event.Repo_Url,    "https://github.com/user/repoName")
     self.assertEqual(event.User,    "user")
     self.assertEqual(event.User_Url,    "https://github.com/user")
     self.assertEqual(event.Public,  True)
     self.assertEqual(event.Date,    "2019-10-13T23:08:50Z")
from S4NGithubApi.domain.Event  import Event
from S4NGithubApi.shared import response_object as res

event_dict = {
            'Id' : "Identificador0", 
            'Type' : "Push", 
            'Repo_Id' : 12345, 
            'Repo_Name' : "Repo", 
            'Repo_Url' : "https://github.com/user/repoName", 
            'User' : "user", 
            'User_Url' : "https://github.com/user", 
            'Public' : True, 
            'Date' : "2019-10-13T23:08:50Z" 
        }

event_domain_model = Event.from_dict(event_dict)

events = [event_domain_model]

class TestRestEvents(unittest.TestCase):

    @mock.patch('S4NGithubApi.use_cases.event_list_use_case.EventListUseCase')
    def test_get(self, mock_use_case, client):
        mock_use_case().execute.return_value = res.ResponseSuccess(events)

        http_response = client.post('/', json=)

        assert json.loads(http_response.data.decode('UTF-8')) == {
            "Identificador0": event_dict
        }
        assert http_response.status_code == 200