Esempio n. 1
0
 def test_no_transaction_rate(self):
     real_factory = RequestFactory("test_factory")
     pipe = self.PipeCls(real_factory)
     pipe.load_data(self.real_entry_list)
     pipe.run_pipe()
     assert pipe.data_store == [
         [{
             'completed': False,
             'id': 1,
             'title': 'delectus aut autem',
             'userId': 1
         }, {
             'completed': False,
             'id': 1,
             'title': 'delectus aut autem',
             'userId': 1
         }, {
             'completed': False,
             'id': 1,
             'title': 'delectus aut autem',
             'userId': 1
         }, {
             'completed': False,
             'id': 1,
             'title': 'delectus aut autem',
             'userId': 1
         }],
     ]
Esempio n. 2
0
    def test_eq_pipes(self):
        real_factory = RequestFactory("test_factory")
        pipe1 = self.PipeCls(real_factory, 0.3)
        pipe2 = self.PipeCls(real_factory, 1)

        assert pipe1 == pipe2
        assert hash(pipe1) == hash(pipe2)
Esempio n. 3
0
    def test_make_api_pipe_equals_results(self):

        real_factory = RequestFactory("test_factory")
        imperativ_pipe = make_api_pipe("test_factory",
                                       writer=self.write,
                                       sleeping_time=0.1)
        class_pipe = self.PipeCls(real_factory, 0.1)
        assert imperativ_pipe.err_params_log() == class_pipe.err_params_log()
Esempio n. 4
0
 def test_request_creation(self):
     FactoryA = RequestFactory(api_name="test_factory")
     request_a = FactoryA(end_url="todos/1")
     assert request_a.get_response().json() == {
         'completed': False,
         'id': 1,
         'title': 'delectus aut autem',
         'userId': 1
     }
Esempio n. 5
0
def make_api_pipe(api_name: str,
                  writer: Callable,
                  sleeping_time: float = None):
    """ pipe maker for Api requests

    Arguments:

        api_name(Required):

            String.
            Api identifier bound to a Config name in ConfigPath (check Pipeline doc)

            ConfigPath(
                Config(name="random_name".......)
            )

            "random_name"  <-- api_name


        writer(Required):

            Callable which take an List(request.requests)  in argument.
            Function which override the ApiPipeline.write method (check ApiPipeline doc)


        sleeping_time(Optional):

            Float.
            The time in second to sleep between 2 requests (check Pipeline doc)


    Return:

        pipe_instance:

            An Instance of pipe (an ApiPipeline subclass with 'writer' arg that override ApiPipeline.write method)

    """
    pipe_cls = type("pipe_cls", (ApiPipeline, ),
                    {"write": instance_method_wrapper(writer)})
    pipe_instance = pipe_cls(request_factory=RequestFactory(api_name),
                             sleeping_time=sleeping_time)
    del pipe_cls
    return pipe_instance
Esempio n. 6
0
 def test_repr(self):
     real_factory = RequestFactory("test_factory")
     pipe = self.PipeCls(real_factory, 0.3)
     assert str(pipe) == "PipeCls(RequestFactory('test_factory'), 0.3)"
Esempio n. 7
0
 def test_err_log(self):
     real_factory = RequestFactory("test_factory")
     pipe = self.PipeCls(real_factory, 0.3)
     pipe.load_data(self.real_entry_list)
     pipe.run_pipe()
     assert pipe.err_log != []
Esempio n. 8
0
 def test_real_load_data_gen(self):
     real_factory = RequestFactory("test_factory")
     pipe = self.PipeCls(real_factory)
     pipe.load_data(self.real_entry_gen)
     assert pipe._data == self.real_entry_gen
Esempio n. 9
0
 def test_fake_load_data(self):
     real_factory = RequestFactory("test_factory")
     with pytest.raises(ValueError):
         self.PipeCls(real_factory).load_data(self.fake_entry)
Esempio n. 10
0
 def test_true_factory_pipe_init(self):
     real_factory = RequestFactory("test_factory")
     assert self.PipeCls(real_factory).request_factory == real_factory