Exemplo n.º 1
0
    def test_update_topic(self):

        desk_api = models.DeskApi2(sitename='testing')
        updated_topic = desk_api.topics()[0].update(name='New Name', )

        self.assertEqual(
            json.loads(unicode_str(httpretty.last_request().body)),
            json.loads(fixture('topic_update_request.json')),
        )

        self.assertEqual(updated_topic.name, 'New Name')
Exemplo n.º 2
0
    def _article_page(self, method, uri, headers):

        previous = next = 'null'

        if '?' in uri:
            page = int(parse_qs(uri.split('?', 1)[1])['page'][0])
        else:
            page = 1
        start_index = (page - 1) * self.PER_PAGE

        template = fixture('article_template.json')
        entries = [
            json.loads(
                template % dict(
                    index=index + 1,
                )
            )
            for index in
            range(start_index,
                  min(self.NUM_ARTICLES, page * self.PER_PAGE))
        ]

        if page > 1:
            previous = json.dumps({
                'href': '/api/v2/articles?page=%s' % (page - 1),
                'class': 'page',
            })
        if (page * self.PER_PAGE < self.NUM_ARTICLES):
            next = json.dumps({
                'href': '/api/v2/articles?page=%s' % (page + 1),
                'class': 'page',
            })

        content = fixture('article_page_template.json') % dict(
            entries=json.dumps(entries),
            next=next,
            previous=previous,
            num_entries=self.NUM_ARTICLES,
        )
        return (200, headers, content)
Exemplo n.º 3
0
    def setUp(self):
        httpretty.httpretty.reset()
        httpretty.enable()

        # article pagination
        httpretty.register_uri(
            httpretty.GET,
            re.compile(r'https://testing.desk.com/api/v2/articles(\?page=\d+)?$'),
            body=self._article_page,
            content_type='application/json',
        )

        # article creation
        httpretty.register_uri(
            httpretty.POST,
            re.compile('https://testing.desk.com/api/v2/articles(\?page=\d+)?$'),
            body=fixture('article_create_response.json'),
            content_type='application/json',
        )

        # article update
        httpretty.register_uri(
            httpretty.PATCH,
            'https://testing.desk.com/api/v2/articles/1',
            body=fixture('article_update_response.json'),
            content_type='application/json',
        )

        # article translations
        httpretty.register_uri(
            httpretty.GET,
            'https://testing.desk.com/api/v2/articles/1/translations',
            body=fixture('article_translations.json'),
            content_type='application/json',
        )

        # translation creation
        httpretty.register_uri(
            httpretty.POST,
            'https://testing.desk.com/api/v2/articles/1/translations',
            body=fixture('article_translation_create_response.json'),
            content_type='application/json',
        )

        # translation update
        httpretty.register_uri(
            httpretty.PATCH,
            'https://testing.desk.com/api/v2/articles/1/translations/es',
            body=fixture('article_translation_update_response.json'),
            content_type='application/json',
        )

        # single article
        httpretty.register_uri(
            httpretty.GET,
            'https://testing.desk.com/api/v2/articles/42',
            body=fixture('article_show.json'),
            content_type='application/json',
        )
Exemplo n.º 4
0
    def test_article_update(self):

        desk_api = models.DeskApi2(sitename='testing')
        updated_article = desk_api.articles()[0].update(
            subject='New Subject',
        )

        self.assertEqual(updated_article.subject, 'New Subject')

        self.assertEqual(
            json.loads(unicode_str(httpretty.last_request().body)),
            json.loads(fixture('article_update_request.json')),
        )
Exemplo n.º 5
0
    def test_create_topic(self):

        desk_api = models.DeskApi2(sitename='testing')
        topics = desk_api.topics()

        new_topic = topics.create(name='Social Media', )

        self.assertEqual(
            json.loads(unicode_str(httpretty.last_request().body)),
            json.loads(fixture('topic_create_request.json')),
        )

        self.assertEqual(new_topic.name, 'Social Media')
Exemplo n.º 6
0
    def test_update_topic(self):

        desk_api = models.DeskApi2(sitename='testing')
        updated_topic = desk_api.topics()[0].update(
            name='New Name',
        )

        self.assertEqual(
            json.loads(unicode_str(httpretty.last_request().body)),
            json.loads(fixture('topic_update_request.json')),
        )

        self.assertEqual(updated_topic.name, 'New Name')
Exemplo n.º 7
0
    def test_article_creation(self):

        articles = models.DeskApi2(sitename='testing').articles()

        new_article = articles.create(
            subject='Social Media',
        )

        self.assertEqual(
            json.loads(unicode_str(httpretty.last_request().body)),
            json.loads(fixture('article_create_request.json')),
        )
        self.assertEqual(httpretty.last_request().path, '/api/v2/articles')
        self.assertEqual(new_article.subject, 'Social Media')
Exemplo n.º 8
0
    def test_create_topic(self):

        desk_api = models.DeskApi2(sitename='testing')
        topics = desk_api.topics()

        new_topic = topics.create(
            name='Social Media',
        )

        self.assertEqual(
            json.loads(unicode_str(httpretty.last_request().body)),
            json.loads(fixture('topic_create_request.json')),
        )

        self.assertEqual(new_topic.name, 'Social Media')
Exemplo n.º 9
0
    def test_update_topic_translation(self):

        desk_api = models.DeskApi2(sitename='testing')
        topic = desk_api.topics()[0]

        ja = topic.translations['ja']
        self.assertEqual(ja.name, 'Japanese Translation')

        updated_ja = ja.update(name='日本語訳', )

        self.assertEqual(
            json.loads(unicode_str(httpretty.last_request().body)),
            json.loads(fixture('topic_translation_update_request.json')),
        )

        self.assertEqual(updated_ja.name, unicode_str('日本語訳'))
Exemplo n.º 10
0
    def test_article_translation_save(self):

        desk_api = models.DeskApi2(sitename='testing')
        article = desk_api.articles()[0]

        es = article.translations['es']
        es.subject = 'Actualizada la traducción española'
        updated_es = es.save()

        self.assertEqual(
            updated_es.subject,
            unicode_str('Actualizada la traducción española'),
        )
        self.assertEqual(
            json.loads(unicode_str(httpretty.last_request().body)),
            json.loads(fixture('article_translation_update_request.json')),
        )
Exemplo n.º 11
0
    def test_create_topic_translation(self):

        desk_api = models.DeskApi2(sitename='testing')
        topic = desk_api.topics()[0]

        es = topic.translations.create(
            name='Traducción español',
            locale='es',
        )

        self.assertEqual(
            json.loads(unicode_str(httpretty.last_request().body)),
            json.loads(fixture('topic_translation_create_request.json')),
        )

        self.assertEqual(es.name, unicode_str('Traducción español'))
        self.assertEqual(es.locale, 'es')
Exemplo n.º 12
0
    def test_create_topic_translation(self):

        desk_api = models.DeskApi2(sitename='testing')
        topic = desk_api.topics()[0]

        es = topic.translations.create(
            name='Traducción español',
            locale='es',
        )

        self.assertEqual(
            json.loads(unicode_str(httpretty.last_request().body)),
            json.loads(fixture('topic_translation_create_request.json')),
        )

        self.assertEqual(es.name, unicode_str('Traducción español'))
        self.assertEqual(es.locale, 'es')
Exemplo n.º 13
0
    def test_save_topic_translation(self):

        desk_api = models.DeskApi2(sitename='testing')
        topic = desk_api.topics()[0]

        ja = topic.translations['ja']
        self.assertEqual(ja.name, 'Japanese Translation')

        ja.name = '日本語訳'
        updated_ja = ja.save()

        self.assertEqual(
            json.loads(unicode_str(httpretty.last_request().body)),
            json.loads(fixture('topic_translation_update_request.json')),
        )

        self.assertEqual(updated_ja.name, unicode_str('日本語訳'))
Exemplo n.º 14
0
    def setUp(self):

        httpretty.httpretty.reset()
        httpretty.enable()

        # register topic list
        httpretty.register_uri(
            httpretty.GET,
            'https://testing.desk.com/api/v2/topics',
            body=fixture('topic_list_page_1.json'),
            content_type='application/json',
        )

        # register patching the first topic
        httpretty.register_uri(
            httpretty.PATCH,
            'https://testing.desk.com/api/v2/topics/1',
            body=fixture('topic_patch_topic_1.json'),
            content_type='application/json',
        )

        # register creating a new topic
        httpretty.register_uri(
            httpretty.POST,
            'https://testing.desk.com/api/v2/topics',
            body=fixture('topic_create_response.json'),
            content_type='application/json',
        )

        # topic translation list
        httpretty.register_uri(
            httpretty.GET,
            'https://testing.desk.com/api/v2/topics/1/translations',
            body=fixture('topic_translations.json'),
            content_type='application/json',
        )

        # update topic translation
        httpretty.register_uri(
            httpretty.PATCH,
            'https://testing.desk.com/api/v2/topics/1/translations/ja',
            body=fixture('topic_translation_update.json'),
            content_type='application/json',
        )

        # create topic translation
        httpretty.register_uri(
            httpretty.POST,
            'https://testing.desk.com/api/v2/topics/1/translations',
            body=fixture('topic_translation_create.json'),
            content_type='application/json',
        )
Exemplo n.º 15
0
    def setUp(self):

        httpretty.httpretty.reset()
        httpretty.enable()

        # register topic list
        httpretty.register_uri(
            httpretty.GET,
            'https://testing.desk.com/api/v2/topics',
            body=fixture('topic_list_page_1.json'),
            content_type='application/json',
        )

        # register patching the first topic
        httpretty.register_uri(
            httpretty.PATCH,
            'https://testing.desk.com/api/v2/topics/1',
            body=fixture('topic_patch_topic_1.json'),
            content_type='application/json',
        )

        # register creating a new topic
        httpretty.register_uri(
            httpretty.POST,
            'https://testing.desk.com/api/v2/topics',
            body=fixture('topic_create_response.json'),
            content_type='application/json',
        )

        # topic translation list
        httpretty.register_uri(
            httpretty.GET,
            'https://testing.desk.com/api/v2/topics/1/translations',
            body=fixture('topic_translations.json'),
            content_type='application/json',
        )

        # update topic translation
        httpretty.register_uri(
            httpretty.PATCH,
            'https://testing.desk.com/api/v2/topics/1/translations/ja',
            body=fixture('topic_translation_update.json'),
            content_type='application/json',
        )

        # create topic translation
        httpretty.register_uri(
            httpretty.POST,
            'https://testing.desk.com/api/v2/topics/1/translations',
            body=fixture('topic_translation_create.json'),
            content_type='application/json',
        )