title: Testing a decorated API route in Flask
body: <p>I have the following simple controller</p>
  
  <pre><code>@companies.route('/companies/&lt;int:id&gt;', methods=['GET'])
  @inject_repository(CompanyRepository)
  def get_company(repository, id):
      """
      GET /companies/id
      """
      company = repository.get(pk=id)
      return jsonify(company.to_json())
  </code></pre>
  
  <p>The DAO is being injected by <code>@inject_repository(CompanyRepository)</code></p>
  
  <p>I do not, however, get what is happening at test time:</p>
  
  <pre><code>def test_get_company(self):
  
      response = self.client.get(url_for('companies.get_company', id=1))
      data = json.loads(response.get_data(as_text=True))
  
      assert_equal(response.status_code, 200)
  </code></pre>
  
  <p>I get the following error</p>
  
  <p><code>TypeError: get_company() missing 1 required positional argument: 'id'</code></p>
  
  <p>Isn't the controller being decorated?</p>
  
  <hr>
  
  <p>Decorator code</p>
  
  <pre><code>def inject_repository(repository_class):
  
      def decorator(func):
  
          @wraps(func)
          def wrapper(*args, **kwargs):
  
              if 'psql' in class_init_fields(repository_class):
                  repository = psql_repository_for(
                      repository_model=repository_class,
                      connection_meta=current_app.config['POSTGRESQL'])
  
              else:
                  raise ValueError("'{}' repository cannot be injected".format(repository_class.__name__))
  
              return func(repository=repository)
  
          return wrapper
  
      return decorator
  </code></pre>