# Building Tests for New discourse\_api Endpoints

**URL:** <https://meta.discourse.org/t/building-tests-for-new-discourse-api-endpoints/118639>\
**Category:** Development\
**Created:** [24.Май.2019 22:21:24 UTC](https://meta.discourse.org/t/building-tests-for-new-discourse-api-endpoints/118639 "2019-05-24T22:21:24Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![kimardenmiller](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kimardenmiller/32/119631_2.png) [@kimardenmiller](https://meta.discourse.org/u/kimardenmiller)\
**Post date:** [01.Октябрь.2019 23:13:28 UTC](https://meta.discourse.org/t/building-tests-for-new-discourse-api-endpoints/118639/9 "2019-10-01T23:13:28Z")

</div>

Вот что у меня есть:

#### examples/example\_helper.rb

```
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__ )
require File.expand_path('../../lib/discourse_api', __FILE__ )
require 'yaml'

CONFIG = YAML.load_file(File.expand_path('../../config.yml', __FILE__ ))

def client
  discourse_client = DiscourseApi::Client.new(CONFIG['host'])
  discourse_client.api_key = CONFIG['api_key']
  discourse_client.api_username = CONFIG['api_username']
  discourse_client
end

```

#### examples/config-example.yml

```
# host, например localhost:3000 или discourse.my_domain.com
host: ВАШЕ_ИМЯ_ХОСТА

# пользователь API (может влиять на возвращаемые результаты, например, метод .categories возвращает только те категории, которые видит api_username)
# создавайте нового клиента при смене пользователя API
api_username: ВАШ_API_КЛЮЧ

# ключ API из панели администратора Discourse /admin/api/keys
api_key: ВАШ_API_КЛЮЧ

```

#### examples/badges.rb

```
require_relative 'example_helper'

# получить значки
puts client.badges

```

Что думаете? Нам действительно нужен файл yml сейчас, учитывая example\_helper.rb?

---

_[View the full topic](https://meta.discourse.org/t/building-tests-for-new-discourse-api-endpoints/118639)._
