Passed
Push — master ( cddcf6...1d3855 )
by Alexander
01:59
created

Tag.test_get_tags_with_ids()   A

Complexity

Conditions 2

Size

Total Lines 14
Code Lines 13

Duplication

Lines 14
Ratio 100 %

Importance

Changes 0
Metric Value
eloc 13
dl 14
loc 14
rs 9.75
c 0
b 0
f 0
cc 2
nop 1
1
# -*- coding: utf-8 -*-
2
# pylint: disable=attribute-defined-outside-init
3
4
from tcms.tests.factories import TagFactory
5
from tcms.xmlrpc.tests.utils import XmlrpcAPIBaseTest
6
7
8
class Tag(XmlrpcAPIBaseTest):
9
    def _fixture_setup(self):
10
        super(Tag, self)._fixture_setup()
11
12
        self.tag_db = TagFactory(name='db')
13
        self.tag_fedora = TagFactory(name='fedora')
14
        self.tag_python = TagFactory(name='python')
15
        self.tag_tests = TagFactory(name='tests')
16
        self.tag_xmlrpc = TagFactory(name='xmlrpc')
17
        self.tags = [self.tag_db, self.tag_fedora, self.tag_python, self.tag_tests, self.tag_xmlrpc]
18
19 View Code Duplication
    def test_get_tags_with_ids(self):
0 ignored issues
show
Duplication introduced by Chenxiong Qi
This code seems to be duplicated in your project.
Loading history...
20
        test_tag = self.rpc_client.exec.Tag.filter({'id__in': [self.tag_python.pk,
21
                                                               self.tag_db.pk,
22
                                                               self.tag_fedora.pk]})
23
        self.assertIsNotNone(test_tag)
24
        self.assertEqual(3, len(test_tag))
25
26
        test_tag = sorted(test_tag, key=lambda item: item['id'])
27
        self.assertEqual(test_tag[0]['id'], self.tag_db.pk)
28
        self.assertEqual(test_tag[0]['name'], 'db')
29
        self.assertEqual(test_tag[1]['id'], self.tag_fedora.pk)
30
        self.assertEqual(test_tag[1]['name'], 'fedora')
31
        self.assertEqual(test_tag[2]['id'], self.tag_python.pk)
32
        self.assertEqual(test_tag[2]['name'], 'python')
33
34 View Code Duplication
    def test_get_tags_with_names(self):
0 ignored issues
show
Duplication introduced by Chenxiong Qi
This code seems to be duplicated in your project.
Loading history...
35
        test_tag = self.rpc_client.exec.Tag.filter({'name__in': ['python', 'fedora', 'db']})
36
        self.assertIsNotNone(test_tag)
37
        self.assertEqual(3, len(test_tag))
38
39
        test_tag = sorted(test_tag, key=lambda item: item['id'])
40
        self.assertEqual(test_tag[0]['id'], self.tag_db.pk)
41
        self.assertEqual(test_tag[0]['name'], 'db')
42
        self.assertEqual(test_tag[1]['id'], self.tag_fedora.pk)
43
        self.assertEqual(test_tag[1]['name'], 'fedora')
44
        self.assertEqual(test_tag[2]['id'], self.tag_python.pk)
45
        self.assertEqual(test_tag[2]['name'], 'python')
46