Ejemplo n.º 1
0
class TestSpaces(TestCase, EntityTestCase):
    entity = Entity.Spaces
    entity_id = '023a02ca-3e73-11e4-8e50-7b146cbe6428'
    entity_count = 4
    skip_list = ['delete', 'edit', 'create']

    def setUp(self):
        self.client = CoredataClient(
            host=self.host, auth=(self.username, self.password))

    def test_get_spaces_files(self):
        """ GET /api/v2/spaces/{id}/files/ """
        # TODO: Get some better data here.
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.entity_id, Entity.Files),
            body=open('tests/json/empty.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id, Entity.Files)
        self.assertEqual(len(entities), 0)

    @skip('Client doesn\'t support sub-sub-entities yet')
    def test_get_spaces_files_templates(self):
        """ GET /api/v2/spaces/{id}/files/templates/ """
        # TODO: Get some better data here.
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(
                self.entity, self.entity_id, Entity.Files, 'templates'),
            body=open('tests/json/empty.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(
            self.entity, self.entity_id, Entity.Files, 'templates')
        self.assertEqual(len(entities), 0)

    def test_get_space_projects(self):
        """" GET /api/v2/spaces/{id}/projects/ """
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.entity_id, Entity.Projects),
            body=open('tests/json/empty.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(
            self.entity, self.entity_id, Entity.Projects)
        self.assertEqual(len(entities), 0)

    @skip('Client doesn\'t support sub-sub-entities yet')
    def test_get_space_project_templates(self):
        """ GET /api/v2/spaces/{id}/projects/templates """
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(
                self.entity, self.entity_id, Entity.Projects, 'templates'),
            body=open('tests/json/empty.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(
            self.entity, self.entity_id, Entity.Projects, 'templates')
        self.assertEqual(len(entities), 0)
Ejemplo n.º 2
0
class TestSpaces(TestCase, EntityTestCase):
    entity = Entity.Spaces
    entity_id = '023a02ca-3e73-11e4-8e50-7b146cbe6428'
    entity_count = 4
    skip_list = ['delete', 'edit', 'create']

    def setUp(self):
        self.client = CoredataClient(host=self.host,
                                     auth=(self.username, self.password))

    def test_get_spaces_files(self):
        """ GET /api/v2/spaces/{id}/files/ """
        # TODO: Get some better data here.
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, self.entity_id,
                                               Entity.Files),
                               body=open('tests/json/empty.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id, Entity.Files)
        self.assertEqual(len(entities), 0)

    @skip('Client doesn\'t support sub-sub-entities yet')
    def test_get_spaces_files_templates(self):
        """ GET /api/v2/spaces/{id}/files/templates/ """
        # TODO: Get some better data here.
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, self.entity_id,
                                               Entity.Files, 'templates'),
                               body=open('tests/json/empty.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id, Entity.Files,
                                   'templates')
        self.assertEqual(len(entities), 0)

    def test_get_space_projects(self):
        """" GET /api/v2/spaces/{id}/projects/ """
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, self.entity_id,
                                               Entity.Projects),
                               body=open('tests/json/empty.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id,
                                   Entity.Projects)
        self.assertEqual(len(entities), 0)

    @skip('Client doesn\'t support sub-sub-entities yet')
    def test_get_space_project_templates(self):
        """ GET /api/v2/spaces/{id}/projects/templates """
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, self.entity_id,
                                               Entity.Projects, 'templates'),
                               body=open('tests/json/empty.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id,
                                   Entity.Projects, 'templates')
        self.assertEqual(len(entities), 0)
Ejemplo n.º 3
0
class TestFiles(TestCase, EntityTestCase):
    entity = Entity.Files
    entity_id = '4ab3bb32-3e72-11e4-bfaa-ebeae41148db'
    entity_count = 45
    skip_list = []

    def setUp(self):
        self.client = CoredataClient(
            host=self.host, auth=(self.username, self.password))

    def test_getting_content(self):
        # TODO: There is a better way to do this.
        returned_content = open('tests/files/get_file', 'rb').read()
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(Entity.Files, self.entity_id, Entity.Content),
            body=returned_content
        )

        content = self.client.get(Entity.Files, self.entity_id, Entity.Content)
        self.assertEqual(content, returned_content)

    @skip('Unable to test in swagger UI!')
    def test_editing_content(self):
        httpretty.register_uri(
            httpretty.PUT,
            self.create_url(Entity.Files, self.entity_id, Entity.Content),
            status=204
        )

        self.client.edit(
            Entity.Files, self.entity_id, Entity.Content, payload='hey')

    def test_getting_files_with_filtering(self):
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(Entity.Files),
            body=open('tests/json/get_files_filtering.json').read(),
            content_type="application/json; charset=utf-8")
        r = self.client.get(
            Entity.Files, search_terms={'title__startswith': 'Y'})
        self.assertEqual(len(r), 6)
Ejemplo n.º 4
0
class TestFiles(TestCase, EntityTestCase):
    entity = Entity.Files
    entity_id = '4ab3bb32-3e72-11e4-bfaa-ebeae41148db'
    entity_count = 45
    skip_list = []

    def setUp(self):
        self.client = CoredataClient(host=self.host,
                                     auth=(self.username, self.password))

    def test_getting_content(self):
        # TODO: There is a better way to do this.
        returned_content = open('tests/files/get_file', 'rb').read()
        httpretty.register_uri(httpretty.GET,
                               self.create_url(Entity.Files, self.entity_id,
                                               Entity.Content),
                               body=returned_content)

        content = self.client.get(Entity.Files, self.entity_id, Entity.Content)
        self.assertEqual(content, returned_content)

    @skip('Unable to test in swagger UI!')
    def test_editing_content(self):
        httpretty.register_uri(httpretty.PUT,
                               self.create_url(Entity.Files, self.entity_id,
                                               Entity.Content),
                               status=204)

        self.client.edit(Entity.Files,
                         self.entity_id,
                         Entity.Content,
                         payload='hey')

    def test_getting_files_with_filtering(self):
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(Entity.Files),
            body=open('tests/json/get_files_filtering.json').read(),
            content_type="application/json; charset=utf-8")
        r = self.client.get(Entity.Files,
                            search_terms={'title__startswith': 'Y'})
        self.assertEqual(len(r), 6)
Ejemplo n.º 5
0
class TestContacts(TestCase, EntityTestCase):
    entity = Entity.Contacts
    entity_id = 'f24203a0-3d8b-11e4-8e77-7ba23226dee9'
    entity_count = 11
    skip_list = []

    def setUp(self):
        self.client = CoredataClient(
            host=self.host, auth=(self.username, self.password))

    def test_get_contact_files(self):
        """ GET /api/v2/contacts/{id}/files/ """
        # TODO: Get some better data here.
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.entity_id, Entity.Files),
            body=open('tests/json/empty.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id, Entity.Files)
        self.assertEqual(len(entities), 0)

    def test_get_contact_projects(self):
        """ GET /api/v2/contacts/{id}/projects/ """
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.entity_id, Entity.Projects),
            body=open('tests/json/empty.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(
            self.entity, self.entity_id, Entity.Projects)
        self.assertEqual(len(entities), 0)

    def test_get_contact_tasks(self):
        """ GET /api/v2/contacts/{id}/tasks/ """
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.entity_id, Entity.Tasks),
            body=open('tests/json/empty.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id, Entity.Tasks)
        self.assertEqual(len(entities), 0)
Ejemplo n.º 6
0
class TestContacts(TestCase, EntityTestCase):
    entity = Entity.Contacts
    entity_id = 'f24203a0-3d8b-11e4-8e77-7ba23226dee9'
    entity_count = 11
    skip_list = []

    def setUp(self):
        self.client = CoredataClient(host=self.host,
                                     auth=(self.username, self.password))

    def test_get_contact_files(self):
        """ GET /api/v2/contacts/{id}/files/ """
        # TODO: Get some better data here.
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, self.entity_id,
                                               Entity.Files),
                               body=open('tests/json/empty.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id, Entity.Files)
        self.assertEqual(len(entities), 0)

    def test_get_contact_projects(self):
        """ GET /api/v2/contacts/{id}/projects/ """
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, self.entity_id,
                                               Entity.Projects),
                               body=open('tests/json/empty.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id,
                                   Entity.Projects)
        self.assertEqual(len(entities), 0)

    def test_get_contact_tasks(self):
        """ GET /api/v2/contacts/{id}/tasks/ """
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, self.entity_id,
                                               Entity.Tasks),
                               body=open('tests/json/empty.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id, Entity.Tasks)
        self.assertEqual(len(entities), 0)
Ejemplo n.º 7
0
class TestValuelist(TestCase, EntityTestCase):
    entity = Entity.Valuelist
    entity_id = 'f24203a0-3d8b-11e4-8e77-7ba23226dee9'
    entity_count = 49
    skip_list = ['create', 'edit', 'get', 'delete']

    def setUp(self):
        self.client = CoredataClient(host=self.host,
                                     auth=(self.username, self.password))

    def test_getting_valuelist_by_name(self):
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, 'templates_labels'),
            body=open('tests/json/get_valuelist_by_name.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, 'templates_labels')
        self.assertEqual(len(entities['objects'][0]['entries']), 28)
Ejemplo n.º 8
0
class TestValuelist(TestCase, EntityTestCase):
    entity = Entity.Valuelist
    entity_id = 'f24203a0-3d8b-11e4-8e77-7ba23226dee9'
    entity_count = 49
    skip_list = ['create', 'edit', 'get', 'delete']

    def setUp(self):
        self.client = CoredataClient(
            host=self.host, auth=(self.username, self.password))

    def test_getting_valuelist_by_name(self):
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, 'templates_labels'),
            body=open('tests/json/get_valuelist_by_name.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, 'templates_labels')
        self.assertEqual(len(entities['objects'][0]['entries']), 28)
Ejemplo n.º 9
0
class TestNav(TestCase, EntityTestCase):
    entity = Entity.Nav
    entity_id = 'f24203a0-3d8b-11e4-8e77-7ba23226dee9'
    entity_count = 1
    skip_list = ['create', 'edit', 'get', 'delete']

    def setUp(self):
        self.client = CoredataClient(host=self.host,
                                     auth=(self.username, self.password))

    @skip('Seems broken in the API itself')
    def test_getting_by_name(self):
        name = 'awesome_name'
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, name),
                               body=open('tests/json/get_all_nav.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, name)
        self.assertEqual(len(entities['objects'][0]['entries']), 1)
Ejemplo n.º 10
0
class TestUsers(TestCase, EntityTestCase):
    entity = Entity.Users
    entity_id = 'f24203a0-3d8b-11e4-8e77-7ba23226dee9'
    entity_count = 9
    skip_list = ['create', 'edit', 'get', 'delete']
    username = '******'

    def setUp(self):
        self.client = CoredataClient(
            host=self.host, auth=(self.username, self.password))

    def test_get_users_by_username(self):
        """ GET /api/v2/users/{username}/ """
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.username),
            body=open('tests/json/get_single_users.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.username),
        self.assertEqual(len(entities), 1)
Ejemplo n.º 11
0
class TestNav(TestCase, EntityTestCase):
    entity = Entity.Nav
    entity_id = 'f24203a0-3d8b-11e4-8e77-7ba23226dee9'
    entity_count = 1
    skip_list = ['create', 'edit', 'get', 'delete']

    def setUp(self):
        self.client = CoredataClient(
            host=self.host, auth=(self.username, self.password))

    @skip('Seems broken in the API itself')
    def test_getting_by_name(self):
        name = 'awesome_name'
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, name),
            body=open('tests/json/get_all_nav.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, name)
        self.assertEqual(len(entities['objects'][0]['entries']), 1)
Ejemplo n.º 12
0
class TestUsers(TestCase, EntityTestCase):
    entity = Entity.Users
    entity_id = 'f24203a0-3d8b-11e4-8e77-7ba23226dee9'
    entity_count = 9
    skip_list = ['create', 'edit', 'get', 'delete']
    username = '******'

    def setUp(self):
        self.client = CoredataClient(host=self.host,
                                     auth=(self.username, self.password))

    def test_get_users_by_username(self):
        """ GET /api/v2/users/{username}/ """
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.username),
            body=open('tests/json/get_single_users.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.username),
        self.assertEqual(len(entities), 1)
Ejemplo n.º 13
0
 def setUp(self):
     self.client = CoredataClient(
         host=self.host, auth=(self.username, self.password))
Ejemplo n.º 14
0
class TestUser(TestCase, EntityTestCase):
    entity = Entity.User
    entity_id = 'f24203a0-3d8b-11e4-8e77-7ba23226dee9'
    entity_count = 1
    skip_list = ['create', 'edit', 'get', 'delete']
    username = '******'

    def setUp(self):
        self.client = CoredataClient(host=self.host,
                                     auth=(self.username, self.password))

    def test_get_user_by_username(self):
        """ GET /api/v2/user/{username}/ """
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.username),
            body=open('tests/json/get_single_user.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.username),
        self.assertEqual(len(entities), 1)

    def test_get_user_files(self):
        """ GET /api/v2/user/{username}/files/ """
        # TODO: Get some better data here.
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, self.username,
                                               Entity.Files),
                               body=open('tests/json/empty.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.username, Entity.Files)
        self.assertEqual(len(entities), 0)

    @skip('Client doesn\'t support sub-sub-entities yet')
    def test_get_user_files_templates(self):
        """ GET /api/v2/user/{id}/files/templates/ """
        # TODO: Get some better data here.
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, self.username,
                                               Entity.Files, 'templates'),
                               body=open('tests/json/empty.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.username, Entity.Files,
                                   'templates')
        self.assertEqual(len(entities), 0)

    def test_get_user_tasks(self):
        """ GET /api/v2/user/{username}/tasks/ """
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, self.username,
                                               Entity.Tasks),
                               body=open('tests/json/empty.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.username, Entity.Tasks)
        self.assertEqual(len(entities), 0)

    def test_get_user_projects(self):
        """ GET /api/v2/user/{username}/projects/ """
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.username, Entity.Projects),
            body=open('tests/json/get_user_projects.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.username, Entity.Projects)
        self.assertEqual(len(entities), 6)
Ejemplo n.º 15
0
class TestProjects(TestCase, EntityTestCase):
    """
    Unit tests for /projects/ endpoint.
    """
    entity = Entity.Projects
    entity_id = 'f24203a0-3d8b-11e4-8e77-7ba23226dee9'
    entity_count = 20
    skip_list = []

    def setUp(self):
        self.client = CoredataClient(
            host=self.host, auth=(self.username, self.password))

    def test_get_project_files(self):
        """ GET /api/v2/projects/{id}/files/ """
        # TODO: Get some better data here.
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.entity_id, Entity.Files),
            body=open('tests/json/empty.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id, Entity.Files)
        self.assertEqual(len(entities), 0)

    @skip('Client doesn\'t support sub-sub-entities yet')
    def test_get_project_file_templates(self):
        """ GET /api/v2/projects/{id}/files/templates/ """
        # TODO: Get some better data here.
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(
                self.entity, self.entity_id, Entity.Files, 'templates'),
            body=open('tests/json/empty.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(
            self.entity, self.entity_id, Entity.Files, 'templates')
        self.assertEqual(len(entities), 0)

    def test_get_project_tasks(self):
        """ GET /api/v2/project/{id}/tasks/ """
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.entity_id, Entity.Tasks),
            body=open('tests/json/empty.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id, Entity.Tasks)
        self.assertEqual(len(entities), 0)

    @skip('Client doesn\'t support sub-sub-entities yet')
    def test_get_project_tasks_templates(self):
        """ GET /api/v2/project/{id}/tasks/templates """
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(
                self.entity, self.entity_id, Entity.Tasks, 'templates'),
            body=open('tests/json/empty.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(
            self.entity, self.entity_id, Entity.Tasks, 'templates')
        self.assertEqual(len(entities), 0)

    def test_getting_projects_with_filtering(self):
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(Entity.Projects),
            body=open('tests/json/get_projects_filtered.json').read(),
            content_type="application/json; charset=utf-8")
        r = self.client.get(
            Entity.Projects, search_terms={'title__startswith': 'Y'})
        self.assertEqual(len(r), 1)
Ejemplo n.º 16
0
class TestProjects(TestCase, EntityTestCase):
    """
    Unit tests for /projects/ endpoint.
    """
    entity = Entity.Projects
    entity_id = 'f24203a0-3d8b-11e4-8e77-7ba23226dee9'
    entity_count = 20
    skip_list = []

    def setUp(self):
        self.client = CoredataClient(host=self.host,
                                     auth=(self.username, self.password))

    def test_get_project_files(self):
        """ GET /api/v2/projects/{id}/files/ """
        # TODO: Get some better data here.
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, self.entity_id,
                                               Entity.Files),
                               body=open('tests/json/empty.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id, Entity.Files)
        self.assertEqual(len(entities), 0)

    @skip('Client doesn\'t support sub-sub-entities yet')
    def test_get_project_file_templates(self):
        """ GET /api/v2/projects/{id}/files/templates/ """
        # TODO: Get some better data here.
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, self.entity_id,
                                               Entity.Files, 'templates'),
                               body=open('tests/json/empty.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id, Entity.Files,
                                   'templates')
        self.assertEqual(len(entities), 0)

    def test_get_project_tasks(self):
        """ GET /api/v2/project/{id}/tasks/ """
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, self.entity_id,
                                               Entity.Tasks),
                               body=open('tests/json/empty.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id, Entity.Tasks)
        self.assertEqual(len(entities), 0)

    @skip('Client doesn\'t support sub-sub-entities yet')
    def test_get_project_tasks_templates(self):
        """ GET /api/v2/project/{id}/tasks/templates """
        httpretty.register_uri(httpretty.GET,
                               self.create_url(self.entity, self.entity_id,
                                               Entity.Tasks, 'templates'),
                               body=open('tests/json/empty.json').read(),
                               content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.entity_id, Entity.Tasks,
                                   'templates')
        self.assertEqual(len(entities), 0)

    def test_getting_projects_with_filtering(self):
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(Entity.Projects),
            body=open('tests/json/get_projects_filtered.json').read(),
            content_type="application/json; charset=utf-8")
        r = self.client.get(Entity.Projects,
                            search_terms={'title__startswith': 'Y'})
        self.assertEqual(len(r), 1)
Ejemplo n.º 17
0
class TestUser(TestCase, EntityTestCase):
    entity = Entity.User
    entity_id = 'f24203a0-3d8b-11e4-8e77-7ba23226dee9'
    entity_count = 1
    skip_list = ['create', 'edit', 'get', 'delete']
    username = '******'

    def setUp(self):
        self.client = CoredataClient(
            host=self.host, auth=(self.username, self.password))

    def test_get_user_by_username(self):
        """ GET /api/v2/user/{username}/ """
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.username),
            body=open('tests/json/get_single_user.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.username),
        self.assertEqual(len(entities), 1)

    def test_get_user_files(self):
        """ GET /api/v2/user/{username}/files/ """
        # TODO: Get some better data here.
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.username, Entity.Files),
            body=open('tests/json/empty.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.username, Entity.Files)
        self.assertEqual(len(entities), 0)

    @skip('Client doesn\'t support sub-sub-entities yet')
    def test_get_user_files_templates(self):
        """ GET /api/v2/user/{id}/files/templates/ """
        # TODO: Get some better data here.
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(
                self.entity, self.username, Entity.Files, 'templates'),
            body=open('tests/json/empty.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(
            self.entity, self.username, Entity.Files, 'templates')
        self.assertEqual(len(entities), 0)

    def test_get_user_tasks(self):
        """ GET /api/v2/user/{username}/tasks/ """
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.username, Entity.Tasks),
            body=open('tests/json/empty.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.username, Entity.Tasks)
        self.assertEqual(len(entities), 0)

    def test_get_user_projects(self):
        """ GET /api/v2/user/{username}/projects/ """
        httpretty.register_uri(
            httpretty.GET,
            self.create_url(self.entity, self.username, Entity.Projects),
            body=open('tests/json/get_user_projects.json').read(),
            content_type="application/json; charset=utf-8")
        entities = self.client.get(self.entity, self.username, Entity.Projects)
        self.assertEqual(len(entities), 6)
Ejemplo n.º 18
0
 def test_init(self):
     CoredataClient(host='derp://example.coredata.is',
                    auth=('username', 'password'))
Ejemplo n.º 19
0
 def setUp(self):
     self.client = CoredataClient(host=self.host,
                                  auth=(self.username, self.password))
Ejemplo n.º 20
0

def get_padding(key, results):
    """ Gets the length of the longest property in results """
    return len(sorted([x[key] for x in results], key=len, reverse=True)[0])

try:
    username = os.environ['COREDATA_USERNAME']
    password = os.environ['COREDATA_PASSWORD']
except KeyError:
    print ('You need to set your Coredata username and passwords as the '
           'environ variables: COREDATA_USERNAME and COREDATA_PASSWORD '
           'respectivly.')
    sys.exit(1)

client = CoredataClient(
    host='https://azazo.coredata.is', auth=(username, password))

search_terms = {'title': sys.argv[1]} if len(sys.argv) > 1 else None
contacts = client.get(Entity.Contacts, search_terms=search_terms)

results = [{'name': contact['title'],
            'phones': ', '.join([x['number'] for x in contact['phones']]),
            'emails': ', '.join([x['email'] for x in contact['emails']])}
           for contact in contacts]

title_padding = get_padding('name', results)
phone_padding = get_padding('phones', results)
email_padding = get_padding('emails', results)

for contact in results:
    print(u'{name} | {phones} | {emails}'.format(