def test_get_pub_keys_from_valid_url(self): # maybe a better idea to mock this test pub_key_url = 'https://github.com/viktorbarzin.keys' # f = urlopen(pub_key_url) # real_key = f.read().decode('utf-8').replace('\n', '') assert sorted(self.github_keys) == sorted(get_pub_keys(pub_key_url))
def test_get_pub_key_from_file(self): file_path = self.pub_key_file_path key = open(file_path, 'r').readline().replace('\n', '') result = get_pub_keys(file_path) assert type(result) is list assert len(result) == 1 assert key == result[0]
def test_get_pub_keys_from_valid_string(self): # assume this string was downloaded - should get both keys keys_str = '''ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDbXhblodPfaYUyWlI1Hvz2rLLDWi2YHZhbURyXt43g0lFEuTKa3tnWKiZKOIQWHr3WgT+EAlVgEgLjTXsIjHMrWvJcuGxPSm1Z/iXclHk1eYxPhi1/b1rQGK0PBknDivb8FqxQNbsMu6lOAVqcUuSVCSRr5tcB+NZoKVWLqjBsNuuQEaxu4dYkSbPmwTEZeSI8XnqRlVFAF9E8PuFgbl+G86SxB/RYKBiZpGr/T5ikrY2Rv68oSeL73kdPwrOj3HAmRwuiOTsSAFG4pZqRBzqL7vWlnndslXKJ9CCRzuvtWpU7G0e7uBL72b0QwgehIxQARyc8y4xSRGkCz9hofVcN ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAIAQDKGsGKcsACD8hG94zQcoB/YE8QfcgT+ZvLJttGxPDUQGwpc1LnUymXz6DrF5T9EDRjhSE9cnelMYaq1fVSVXJObYWU3sflzmR6uP8TfbL3RkDfLSQfpPhACBIvXyl3bNkTnkf2SFdYneVC6NiTPIO8bRcccap+IPFxAGq5nuEYDH3PT2rdu6XmWXUQg2tRBdrMyzgL3wE3ykdEKpEiJwcG6x+pfe1IX3CTBUipSnhsLVqqy7sFm+r1TEhXbRDgCjWIlzpyzn8FSGRkucDyahqL0I+eDdY5KPmV+a0fGS5Kf1GTrxYnlrG2VkTorEJHrFXuBXhYuKAVOr37Ci2BL4ykkfod9FE5nEIF0rsTneUo90QlgscGMm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SnxJzcqdIdlwKhePM/eH82Uvay9wVPug4/M9pDNeNguq7GLtlCmD3QmKY70yI0e3KhiE6dl/8pMXb/tFWReN6UTZ3CGbLz0IQ0040O+uhhqMVCO8I3komt7o2urB3nonSABH9WpxjJ6FLk/+KFq4Gg7gqfLAqC9+u/yBVs08ba9F6NoBc64/8EYjK0uxqSe6G/rSRBHPd7Rv5w== ''' result = get_pub_keys(keys_str) assert type(result) is list assert len(result) == 2 assert result[0] == keys_str.split('\n')[0] assert result[1] == keys_str.split('\n')[1]
def test_get_pub_keys_from_empty_retunrs_empty(self): assert get_pub_keys(None) == [] assert get_pub_keys('') == []
def test_get_pub_key_from_valid_string(self): # inputting valid pub key should be just returned result = get_pub_keys(self.valid_key) assert type(result) is list assert len(result) == 1 assert result[0] == self.valid_key
def test_get_pub_keys_from_github_valid_user(self): username = '******' # get url from username, get keys from url and test assert self.github_keys == get_pub_keys(get_github_keys_url(username))