def getSpaces(self): self.assembla = API( key='69d28d064554d5316c04', secret='9d44b1e5082c9fb41c4012065384942cdb7c3116', # Use your API key/secret from https://www.assembla.com/user/edit/manage_clients ) spaces = self.assembla.spaces() return spaces
def test_failed_instantiating_assembla_api(): try: API() except: return # Shouldn't hit this raise Exception
class GlobalInfo(object): def __init__(self): self.assembla = None self.swat_space = None self.swat_users = None self.seismic_tickets = None def load(self): self.assembla = API(key=swat_settings.SWAT_API_KEY, secret=swat_settings.SWAT_API_SECRET) self.swat_space = self.assembla.spaces(name=swat_settings.SWAT_SPACE_NAME)[0] self.swat_users = self.__get_swat_user_info() self.seismic_tickets = self.swat_space.tickets() def __get_swat_user_info(self): swat_users = [] for user in self.swat_space.users(): if 'email' in user.keys() and user['email'] in swat_settings.SWAT_EMAILS: swat_users.append(user) return swat_users
class TestAssembla(unittest.TestCase): assembla = API( key=auth[0], secret=auth[1], ) assembla.cache_responses = False def __space_with_tickets(self, cutoff=1): for space in self.assembla.spaces(): if len(space.tickets()) > cutoff: return space def test_update_ticket(self): space = self.__space_with_tickets() ticket = space.tickets()[0] current_summary = ticket['summary'] new_summary = u"TEST" ticket['summary'] = new_summary ticket = ticket.write() # fetch a copy, assert it has the summary we just pushed ticket2 = space.tickets()[0] self.assertEqual(ticket2['summary'], new_summary) #put back the original summary ticket2['summary'] = current_summary ticket2.write() def test_new_ticket(self): space = self.__space_with_tickets() ticket = Ticket({'summary': "Here is a new ticket"}) ticket.space = space assert 'number' not in ticket.data ticket = ticket.write() # ticket now has a number self.assertTrue(ticket['number']) self.assertTrue(ticket['id']) # tidy up (oh and test delete) ticket.delete() def _get_space_with_wiki_tools(self): for space in self.assembla.spaces(): for tool in space.tools(): if 'wiki' in tool['menu_name'].lower(): return space raise Exception('Can\'t find a space with the Wiki tool') def test_wiki_page_write_and_delete(self): space = self._get_space_with_wiki_tools() page_name = 'Test_page' wiki_page = WikiPage() wiki_page.space = space wiki_page['page_name'] = page_name wiki_page['contents'] = 'Test content' wiki_page = wiki_page.write() self.assertTrue(wiki_page['id']) self.assertTrue(len(space.wiki_pages(page_name=page_name)) > 0) space.wiki_pages(page_name=page_name)[0].delete() self.assertTrue(len(space.wiki_pages(page_name=page_name)) == 0)
def insertRows(self,tickets): for ticket in tickets: self.insertRow(ticket) self.db.commit() def flushDb(self): sql = "Delete from issues" cursor = self.db.cursor() cursor.execute(sql) self.db.commit() # import mysql.connector assembla = API( key='c247861e00b49cfccca6', secret='258ebad8926c49509e8e37451b1dd4b5e639406b', # Auth details from https://www.assembla.com/user/edit/manage_clients ) space = assembla.spaces(name='IF Web')[0] milestone = space.milestones(title='Backlog- IF Web QA')[0] milestones = [(milestone['title'],milestone['id']) for milestone in space.milestones() ] space_ios = assembla.spaces(name='IF Athan iOS')[0] milestone_ios = space_ios.milestones(title='Backlog- Athan iOS QA')[0] space_android = assembla.spaces(name='IF Athan Android')[0] milestone_android = space_android.milestones(title='Backlog- Athan Android QA')[0] tickets = space.tickets( milestone_id=milestone['id'],
from assembla import API GITHUB_USER = os.environ.get("GITHUB_USER", "") GITHUB_PASS = os.environ.get("GITHUB_PASS", "") ASSEMBLA_KEY = os.environ.get("ASSEMBLA_KEY", "") ASSEMBLA_SECRET = os.environ.get("ASSEMBLA_SECRET", "") ASSEMBLA_SPACE = os.environ.get("ASSEMBLA_SPACE", "") GITHUB_AUTHOR = os.environ.get("GITHUB_AUTHOR", "") GITHUB_REPO = os.environ.get("GITHUB_REPO", "") gh = login(GITHUB_USER, password=GITHUB_PASS) assembla = API( key=ASSEMBLA_KEY, secret=ASSEMBLA_SECRET, ) def get_user_info(gh, my_space): """ Use this to help you extract the github users and assembla users, so you can setup the usermap """ users = my_space.users() for user in users: print user['id'], user['login'] repo = gh.repository(GITHUB_AUTHOR, GITHUB_REPO) for user in repo.iter_assignees(): print user.login
def test_instantiating_assembla_api(): API(key='key', secret='secret')
class TestAssembla(TestCase): assembla = API( key=auth[0], secret=auth[1], ) assembla.cache_responses = True def __check_ticket_is_valid(self, ticket): for key in ( 'id', 'number', 'summary', 'description', 'priority', 'completed_date', 'component_id', 'created_on', 'permission_type', 'importance', 'is_story', 'milestone_id', 'notification_list', 'space_id', 'state', 'status', 'story_importance', 'updated_at', 'working_hours', 'estimate', 'total_estimate', 'total_invested_hours', 'total_working_hours', 'assigned_to_id', 'reporter_id', 'custom_fields', ): self.assertIn(key, ticket.keys()) # Some of the fields may have been returned with null-esque values if key not in ( 'completed_date', 'component_id', 'assigned_to_id', ): self.assertIsNotNone(ticket[key]) def __space_with_tickets(self, cutoff=1): for space in self.assembla.spaces(): if len(space.tickets()) > cutoff: return space def __milestone_with_tickets(self, cutoff=1): space = self.__space_with_tickets() for milestone in space.milestones(): if len(milestone.tickets()) > cutoff: return milestone def test_api_methods_exist(self): attrs = ( 'spaces', 'stream', ) for attr in attrs: self.assertTrue( hasattr(self.assembla, attr), 'assembla.API does not have an attribute named {0}'.format( attr)) def test_api_stream(self): stream = self.assembla.stream() self.assertGreater(len(stream), 0) for event in stream: for key in ('date', 'operation', 'object', 'object_id', 'title', 'space_id', 'space_name', 'author_id', 'author_name'): self.assertIn(key, event.keys()) self.assertIsNotNone(event[key]) def test_api_spaces(self): spaces = self.assembla.spaces() self.assertGreater(len(spaces), 0) for space in spaces: for key in ( 'id', 'name', 'description', 'wiki_name', 'public_permissions', 'team_permissions', 'watcher_permissions', 'share_permissions', 'team_tab_role', 'created_at', 'updated_at', 'default_showpage', 'tabs_order', 'parent_id', 'restricted', 'restricted_date', 'commercial_from', 'banner', 'banner_height', 'banner_text', 'banner_link', 'style', 'status', 'approved', 'is_manager', 'is_volunteer', 'is_commercial', 'can_join', 'last_payer_changed_at', ): self.assertIn(key, space.keys()) # A few of the fields appear not to have had their values set if key not in ('tabs_order', 'parent_id', 'restricted_date', 'banner_link', 'last_payer_changed_at', 'banner', 'banner_height', 'banner_text', 'banner_link', 'style'): self.assertIsNotNone(space[key]) def test_space_methods_exist(self): space = self.assembla.spaces()[0] attrs = ( 'milestones', 'users', 'tickets', ) for attr in attrs: self.assertTrue( hasattr(space, attr), 'assembla.Space does not have an attribute named {0}'.format( attr)) def test_space_tickets(self): space = self.__space_with_tickets() ticket = space.tickets()[0] self.__check_ticket_is_valid(ticket) self.assertEqual(ticket.space['id'], space['id']) self.assertEqual(ticket.api, self.assembla) def test_pagination(self): # WARNING: this wont pass unless you have some spaces with more than 1000 tickets in them for space in self.assembla.spaces(): if len(space.tickets()) > 1000: # Exit once we've hit a space with correctly paginated tickets return self.assertTrue( False, 'This may fail if you Assembla spaces have insufficient ' 'numbers of tickets to trigger pagination') def test_space_milestones(self): milestone = self.__milestone_with_tickets() for key in ( 'id', 'due_date', 'title', 'user_id', 'created_at', 'created_by', 'space_id', 'description', 'is_completed', 'completed_date', 'updated_at', 'updated_by', 'release_level', 'release_notes', 'planner_type', 'pretty_release_level', ): self.assertIn(key, milestone.keys()) # Some of the fields may have been returned with null-esque values if key not in ( 'completed_date', 'release_level', 'release_notes', ): self.assertIsNotNone(milestone[key]) self.assertIsNotNone(milestone.space) self.assertEqual(milestone.api, self.assembla) def test_space_users(self): for space in self.assembla.spaces(): for user in space.users(): for key in ('id', 'login', 'name', 'email', 'organization', 'organization', 'im', 'im2'): self.assertIn(key, user.keys()) self.assertEqual(user.api, self.assembla) # Exit once we've hit a space with tickets return def test_milestone_tickets(self): milestone = self.__milestone_with_tickets() ticket = milestone.tickets()[0] self.__check_ticket_is_valid(ticket) self.assertEqual(ticket.milestone['id'], milestone['id']) self.assertEqual(ticket.milestone.space['id'], milestone.space['id']) self.assertIsNotNone(ticket.space) self.assertEqual(ticket.api, self.assembla) def test_user_tickets(self): for space in self.assembla.spaces(): for user in space.users(): for ticket in user.tickets(): self.__check_ticket_is_valid(ticket) self.assertEqual(ticket['assigned_to_id'], user['id']) self.assertEqual(ticket.user['id'], user['id']) self.assertEqual(ticket.space['id'], space['id']) self.assertEqual(ticket.api, self.assembla) # Exit once we've hit a user with tickets return self.assertTrue( False, 'this may fail if your Assembla account has insufficient data') def test_api_space_filtering(self): test_space = self.assembla.spaces()[-1] filtered_spaces = self.assembla.spaces( id=test_space.get('id'), name=test_space.get('name'), ) self.assertEqual(len(filtered_spaces), 1) for space in filtered_spaces: self.assertEqual(space.get('id'), test_space.get('id')) def test_space_ticket_filtering(self): space = self.__space_with_tickets() last_ticket = space.tickets()[-1] self.assertEqual(len(space.tickets(number=last_ticket.get('number'))), 1) # This works 100% of the time, most of the time self.assertGreater( len(space.tickets(priority=last_ticket.get('priority'))), 1) def test_space_tickets_does_not_return_duplicates(self): space = self.__space_with_tickets(10) ids = [t['id'] for t in space.tickets()] self.assertItemsEqual(ids, list(set(ids))) def test_space_tickets_does_not_return_duplicates_if_paginating(self): space = self.__space_with_tickets(1000) ids = [t['id'] for t in space.tickets()] self.assertItemsEqual(ids, list(set(ids)))
class TestAssembla(unittest.TestCase): assembla = API( key=auth[0], secret=auth[1], ) assembla.cache_responses = True def __check_ticket_is_valid(self, ticket): for key in ( 'id', 'number', 'summary', 'description', 'priority', 'completed_date', 'component_id', 'created_on', 'permission_type', 'importance', 'is_story', 'milestone_id', 'notification_list', 'space_id', 'state', 'status', 'story_importance', 'updated_at', 'working_hours', 'estimate', 'total_estimate', 'total_invested_hours', 'total_working_hours', 'assigned_to_id', 'reporter_id', 'custom_fields', ): self.assertIn(key, ticket.keys()) # Some of the fields may have been returned with null-esque values if key not in ('completed_date', 'component_id', 'assigned_to_id', 'description', 'milestone_id'): try: self.assertIsNotNone(ticket[key]) except AssertionError: print key, "is None in" print ticket.data raise def __space_with_tickets(self, cutoff=1, skip=0): s = 0 for space in self.assembla.spaces(): if s >= skip and len(space.tickets()) > cutoff: return space s = s + 1 raise ValueError("No spaces had tickets") def __milestone_with_tickets(self, cutoff=1, skip=0): space = self.__space_with_tickets(cutoff=cutoff, skip=skip) for milestone in space.milestones(): if len(milestone.tickets()) > cutoff: return milestone #reached when a space with tickets doesn't have milestones with tickets. return self.__milestone_with_tickets(cutoff, skip=skip + 1) def test_api_methods_exist(self): attrs = ( 'spaces', 'stream', ) for attr in attrs: self.assertTrue( hasattr(self.assembla, attr), 'assembla.API does not have an attribute named {0}'.format( attr)) def test_api_stream(self): stream = self.assembla.stream() self.assertGreater(len(stream), 0) for event in stream: for key in ('date', 'operation', 'object', 'object_id', 'title', 'space_id', 'space_name', 'author_id', 'author_name'): self.assertIn(key, event.keys()) self.assertIsNotNone(event[key]) def test_api_spaces(self): spaces = self.assembla.spaces() self.assertGreater(len(spaces), 0) for space in spaces: for key in ( 'id', 'name', 'description', 'wiki_name', 'public_permissions', 'team_permissions', 'watcher_permissions', 'share_permissions', 'team_tab_role', 'created_at', 'updated_at', 'default_showpage', 'tabs_order', 'parent_id', 'restricted', 'restricted_date', 'commercial_from', 'banner', 'banner_height', 'banner_text', 'banner_link', 'style', 'status', 'approved', 'is_manager', 'is_volunteer', 'is_commercial', 'can_join', 'last_payer_changed_at', ): self.assertIn(key, space.keys()) # A few of the fields appear not to have had their values set if key not in ( 'tabs_order', 'parent_id', 'restricted_date', 'banner_link', 'last_payer_changed_at', 'banner', 'banner_height', 'banner_text', 'banner_link', 'style', 'description', 'commercial_from', ): self.assertIsNotNone(space[key]) def test_space_methods_exist(self): space = self.assembla.spaces()[0] attrs = ( 'milestones', 'users', 'tickets', ) for attr in attrs: self.assertTrue( hasattr(space, attr), 'assembla.Space does not have an attribute named {0}'.format( attr)) def test_space_tickets(self): space = self.__space_with_tickets() ticket = space.tickets()[0] self.__check_ticket_is_valid(ticket) self.assertEqual(ticket.space['id'], space['id']) self.assertEqual(ticket.api, self.assembla) def test_pagination(self): # WARNING: this wont pass unless you have some spaces with more than 1000 tickets in them for space in self.assembla.spaces(): if len(space.tickets()) > 1000: # Exit once we've hit a space with correctly paginated tickets return self.assertTrue( False, 'This may fail if you Assembla spaces have insufficient ' 'numbers of tickets to trigger pagination') def test_space_milestones(self): milestone = self.__milestone_with_tickets() for key in ( 'id', 'due_date', 'title', 'user_id', 'created_at', 'created_by', 'space_id', 'is_completed', 'completed_date', 'updated_at', 'updated_by', 'release_level', 'release_notes', 'planner_type', 'pretty_release_level', ): self.assertIn(key, milestone.keys()) # Some of the fields may have been returned with null-esque values if key not in ( 'completed_date', 'release_level', 'release_notes', 'due_date', 'user_id', 'description', ): self.assertIsNotNone(milestone[key]) self.assertIsNotNone(milestone.space) self.assertEqual(milestone.api, self.assembla) def test_space_users(self): for space in self.assembla.spaces(): for user in space.users(): for key in ('id', 'login', 'name'): self.assertIn(key, user.keys()) self.assertEqual(user.api, self.assembla) # Exit once we've hit a space with tickets return def test_milestone_tickets(self): milestone = self.__milestone_with_tickets() ticket = milestone.tickets()[0] self.__check_ticket_is_valid(ticket) self.assertEqual(ticket.milestone()['id'], milestone['id']) self.assertEqual(ticket.milestone().space['id'], milestone.space['id']) self.assertIsNotNone(ticket.space) self.assertEqual(ticket.api, self.assembla) def test_user_tickets(self): for space in self.assembla.spaces(): for user in space.users(): for ticket in user.tickets(): self.__check_ticket_is_valid(ticket) self.assertEqual(ticket['assigned_to_id'], user['id']) self.assertEqual(ticket.user['id'], user['id']) self.assertEqual(ticket.api, self.assembla) # Exit once we've hit a user with tickets return self.assertTrue( False, 'this may fail if your Assembla account has insufficient data') def test_api_space_filtering(self): test_space = self.assembla.spaces()[-1] filtered_spaces = self.assembla.spaces( id=test_space.get('id'), name=test_space.get('name'), ) self.assertEqual(len(filtered_spaces), 1) for space in filtered_spaces: self.assertEqual(space.get('id'), test_space.get('id')) def test_space_ticket_filtering(self): space = self.__space_with_tickets() last_ticket = space.tickets()[-1] self.assertEqual(len(space.tickets(number=last_ticket.get('number'))), 1) # This works 100% of the time, most of the time self.assertGreater( len(space.tickets(priority=last_ticket.get('priority'))), 1) def test_space_tickets_does_not_return_duplicates(self): space = self.__space_with_tickets(10) ids = [t['id'] for t in space.tickets()] self.assertItemsEqual(ids, list(set(ids))) def test_space_tickets_does_not_return_duplicates_if_paginating(self): space = self.__space_with_tickets(1000) ids = [t['id'] for t in space.tickets()] self.assertItemsEqual(ids, list(set(ids))) def test_extra_params_filtering(self): # Find two different timestamps in the stream and filter by the later one # so that we can see if the filtering by extra_params works stream = self.assembla.stream() first_time = None second_time = None for event in stream: # Strip the time from the Event time_struct = time.strptime(event.get('date'), '%Y-%m-%dT%H:%M:%S+00:00') # Instantiate a datetime using only the Year, Month, Day, Hour and Minute event_time = datetime.datetime(*time_struct[:5]) if not first_time: first_time = event_time if event_time < first_time: second_time = event_time filter_from = first_time.strftime('%Y-%m-%d %H:%M') filtered_stream = self.assembla.stream( extra_params={"from": filter_from}) self.assertLess(len(filtered_stream), len(stream)) def test_space_tools(self): self.assertTrue(len(self.assembla.spaces()[0].tools()) > 0) def _get_space_with_wiki_tools(self): for space in self.assembla.spaces(): for tool in space.tools(): if 'wiki' in tool['menu_name'].lower(): return space raise Exception('Can\'t find a space with the Wiki tool') def test_space_wiki_pages(self): space = self._get_space_with_wiki_tools() for page in space.wiki_pages(): self.assertTrue(page['page_name']) self.assertTrue(page['contents'])
def load(self): self.assembla = API(key=swat_settings.SWAT_API_KEY, secret=swat_settings.SWAT_API_SECRET) self.swat_space = self.assembla.spaces(name=swat_settings.SWAT_SPACE_NAME)[0] self.swat_users = self.__get_swat_user_info() self.seismic_tickets = self.swat_space.tickets()
from random import choice import json import requests from assembla import API, Space, Milestone, Ticket, settings from assembla.tests.auth import auth SPACE_NAME = 'API Test Space 7500' NUMBER_OF_MILESTONES = 5 MILESTONE_TITLE_FORMAT = 'Test Milestone #{0}' NUMBER_OF_TICKETS = 7500 TICKET_SUMMARY_FORMAT = 'Test Ticket #{0}' assembla = API( key=auth[0], secret=auth[1], ) class TestDataBuilder(object): """ Build a space with sufficient data to run the tests against """ def _post_json(self, model, rel_path=None, data=None): url = '{0}/{1}/{2}.json'.format(settings.API_ROOT_PATH, settings.API_VERSION, rel_path or model.rel_path) if data: data = json.dumps(data)
class GetData(): ''' classdocs ''' def __init__(self): ''' Constructor ''' pass def getSpaces(self): self.assembla = API( key='69d28d064554d5316c04', secret='9d44b1e5082c9fb41c4012065384942cdb7c3116', # Use your API key/secret from https://www.assembla.com/user/edit/manage_clients ) spaces = self.assembla.spaces() return spaces def getUsers(self, space_name=''): my_space = self.assembla.spaces(name=space_name)[0] print "Space ID " + my_space.data["id"] users = my_space.users() roles = my_space.roles() print roles for user in users: login_user = user.data['login'] id_user = user.data['id'] print("User LogIn: "******" With ID: " + id_user) return users, roles, id def getUserList(self): filename = '/home/davidryv/workspace/DeleteUsers_2/Scripts/userlist.txt' data_chomp = [] # Using the newer with construct to close the file automatically. with open(filename) as f: data = f.readlines() for username in data: data_chomp.append(username.rstrip()) return data_chomp def DeleteUsersList(self, userID, UserName, roles, space_name): Delete_user = Delete() for roles_id in roles: if roles_id['user_id'] == userID: role_number = roles_id['id'] Delete_user.delete_users(id_role=role_number, wiki_name=space_name) break else: print "ID not found in the list"