def test_repo_dir_exist_no_svn_info(self): """Test that an empty info string returns an unknown status """ stat = ExternalStatus() # Now we over-ride the _svn_info method on the repo to return # a known value without requiring access to svn. self._repo._svn_info = self._svn_info_empty self._repo._check_sync(stat, '.') self.assertEqual(stat.sync_state, ExternalStatus.UNKNOWN) # check_dir should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_sync_dir_not_exist(self): """Test that a directory that doesn't exist returns an error status Note: the Repository classes should be prevented from ever working on an empty directory by the _Source object. """ stat = ExternalStatus() self._repo._check_sync(stat, 'invalid_directory_name') self.assertEqual(stat.sync_state, ExternalStatus.STATUS_ERROR) # check_dir should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_sync_dir_exist_no_git_info(self): """Test that an empty info string returns an unknown status """ stat = ExternalStatus() # Now we over-ride the _git_branch method on the repo to return # a known value without requiring access to git. self._repo._git_remote_verbose = self._git_remote_origin_upstream self._repo._git_branch_vv = self._git_branch_empty self._repo._check_sync(stat, self.TMP_FAKE_DIR) self.assertEqual(stat.sync_state, ExternalStatus.UNKNOWN) # check_sync should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_repo_dir_modified(self): """Test that a valid svn info string that is out of sync with the externals description returns a modified status. """ stat = ExternalStatus() # Now we over-ride the _svn_info method on the repo to return # a known value without requiring access to svn. self._repo._svn_info = self._svn_info_modified self._repo._check_sync(stat, '.') self.assertEqual(stat.sync_state, ExternalStatus.MODEL_MODIFIED) # check_dir should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_sync_branch_on_detached_tag(self): """Test expect branch on detached tag --> status modified """ stat = ExternalStatus() self._repo._git_remote_verbose = self._git_remote_origin_upstream self._repo._branch = 'feature-2' self._repo._tag = '' self._repo._git_branch_vv = self._git_branch_detached_tag self._repo._check_sync_logic(stat, self.TMP_FAKE_DIR) self.assertEqual(stat.sync_state, ExternalStatus.MODEL_MODIFIED) # check_sync should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_repo_dir_synced(self): """Test that a valid info string that is synced to the repo in the externals description returns an ok status. """ stat = ExternalStatus() # Now we over-ride the _svn_info method on the repo to return # a known value without requiring access to svn. self._repo._svn_info = self._svn_info_synced self._repo._check_sync(stat, '.') self.assertEqual(stat.sync_state, ExternalStatus.STATUS_OK) # check_dir should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_sync_invalid_reference(self): """Test that an invalid reference returns out-of-sync """ stat = ExternalStatus() self._repo._git_remote_verbose = self._git_remote_origin_upstream self._repo._tag = 'tag1' self._repo._git_current_hash = self._git_current_hash('abc123') self._repo._git_revparse_commit = self._git_revparse_commit( 'tag1', 1, '') self._repo._check_sync_logic(stat, self.TMP_FAKE_DIR) self.assertEqual(stat.sync_state, ExternalStatus.MODEL_MODIFIED) # check_sync should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_sync_branch_on_tracking_branch_same_remote(self): """Test expect branch on tracking branch with same remote --> status ok """ stat = ExternalStatus() self._repo._git_remote_verbose = self._git_remote_origin_upstream self._repo._branch = 'feature-2' self._repo._tag = '' self._repo._git_branch_vv = self._git_branch_tracked_branch self._repo._check_sync_logic(stat, self.TMP_FAKE_DIR) self.assertEqual(stat.sync_state, ExternalStatus.STATUS_OK) # check_sync should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_sync_tag_on_untracked_branch(self): """Test expect tag on untracked branch --> status modified """ stat = ExternalStatus() self._repo._git_remote_verbose = self._git_remote_origin_upstream self._repo._branch = '' self._repo._tag = 'tag1' self._repo._git_branch_vv = self._git_branch_untracked_branch self._repo._check_sync_logic(stat, self.TMP_FAKE_DIR) self.assertEqual(stat.sync_state, ExternalStatus.MODEL_MODIFIED) # check_sync should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_sync_tag_on_detached_tag(self): """Test expect tag on detached tag --> status ok """ stat = ExternalStatus() self._repo._git_remote_verbose = self._git_remote_origin_upstream self._repo._branch = '' self._repo._tag = 'tag1' self._repo._git_branch_vv = self._git_branch_detached_tag self._repo._check_sync_logic(stat, self.TMP_FAKE_DIR) self.assertEqual(stat.sync_state, ExternalStatus.STATUS_OK) # check_sync should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_sync_tag_on_different_hash(self): """Test expect tag on a different hash --> status modified """ stat = ExternalStatus() self._repo._git_remote_verbose = self._git_remote_origin_upstream self._repo._tag = 'tag1' self._repo._git_current_hash = self._git_current_hash('def456') self._repo._git_revparse_commit = self._git_revparse_commit( 'tag1', 0, 'abc123') self._repo._check_sync_logic(stat, self.TMP_FAKE_DIR) self.assertEqual(stat.sync_state, ExternalStatus.MODEL_MODIFIED) # check_sync should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_sync_branch_on_unknown_remote(self): """Test expect branch, but remote is unknown --> status modified """ stat = ExternalStatus() self._repo._git_remote_verbose = self._git_remote_origin_upstream self._repo._branch = 'feature-2' self._repo._tag = '' self._repo._url = '/path/to/unknown/repo' self._repo._git_branch_vv = self._git_branch_untracked_branch self._repo._check_sync_logic(stat, self.TMP_FAKE_DIR) self.assertEqual(stat.sync_state, ExternalStatus.MODEL_MODIFIED) # check_sync should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_sync_branch_on_same_hash(self): """Test expect branch on same hash --> status ok """ stat = ExternalStatus() self._repo._git_remote_verbose = self._git_remote_origin_upstream self._repo._branch = 'feature-2' self._repo._tag = '' self._repo._git_current_hash = self._git_current_hash('abc123') self._repo._git_revparse_commit = (self._git_revparse_commit( 'origin/feature-2', 0, 'abc123')) self._repo._check_sync_logic(stat, self.TMP_FAKE_DIR) self.assertEqual(stat.sync_state, ExternalStatus.STATUS_OK) # check_sync should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_sync_dir_exist_no_git_info(self): """Test that a non-existent git repo returns an unknown status """ stat = ExternalStatus() # Now we over-ride the _git_remote_verbose method on the repo to return # a known value without requiring access to git. self._repo._git_remote_verbose = self._git_remote_origin_upstream self._repo._tag = 'tag1' self._repo._git_current_hash = self._git_current_hash('') self._repo._git_revparse_commit = self._git_revparse_commit( 'tag1', 1, '') self._repo._check_sync(stat, self.TMP_FAKE_DIR) self.assertEqual(stat.sync_state, ExternalStatus.UNKNOWN) # check_sync should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_sync_branch_on_untracked_branch(self): """Test expect branch on untracked branch --> status modified NOTE(bja, 2017-11) the externals description url is always a remote repository. A local untracked branch only exists locally, therefore it is always a modified state, even if this is what the user wants. """ stat = ExternalStatus() self._repo._git_remote_verbose = self._git_remote_origin_upstream self._repo._branch = 'feature-2' self._repo._tag = '' self._repo._git_branch_vv = self._git_branch_untracked_branch self._repo._check_sync_logic(stat, self.TMP_FAKE_DIR) self.assertEqual(stat.sync_state, ExternalStatus.MODEL_MODIFIED) # check_sync should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_sync_branch_on_untracked_local(self): """Test expect branch, on untracked branch in local repo --> status ok Setting the externals description to '.' indicates that the user only want's to consider the current local repo state without fetching from remotes. This is required to preserve the current branch of a repository during an update. NOTE(bja, 2017-11) the externals description is always a remote repository. A local untracked branch only exists locally, therefore it is always a modified state, even if this is what the user wants. """ stat = ExternalStatus() self._repo._git_remote_verbose = self._git_remote_origin_upstream self._repo._branch = 'feature3' self._repo._tag = '' self._repo._git_branch_vv = self._git_branch_untracked_branch self._repo._url = '.' self._repo._check_sync_logic(stat, self.TMP_FAKE_DIR) self.assertEqual(stat.sync_state, ExternalStatus.STATUS_OK) # check_sync should only modify the sync_state, not clean_state self.assertEqual(stat.clean_state, ExternalStatus.DEFAULT)
def test_update_modified_all(self): """If the repository in-sync is modified, then it is safe to update only if clean state is ok """ stat = ExternalStatus() stat.sync_state = ExternalStatus.MODEL_MODIFIED stat.clean_state = ExternalStatus.DEFAULT safe_to_update = stat.safe_to_update() self.assertFalse(safe_to_update) stat.clean_state = ExternalStatus.EMPTY safe_to_update = stat.safe_to_update() self.assertFalse(safe_to_update) stat.clean_state = ExternalStatus.UNKNOWN safe_to_update = stat.safe_to_update() self.assertFalse(safe_to_update) stat.clean_state = ExternalStatus.STATUS_OK safe_to_update = stat.safe_to_update() self.assertTrue(safe_to_update) stat.clean_state = ExternalStatus.DIRTY safe_to_update = stat.safe_to_update() self.assertFalse(safe_to_update)
def test_exists_empty_all(self): """If the repository sync-state is empty (doesn't exist), and there is no clean state, then it is considered not to exist. """ stat = ExternalStatus() stat.sync_state = ExternalStatus.EMPTY stat.clean_state = ExternalStatus.DEFAULT exists = stat.exists() self.assertFalse(exists) stat.clean_state = ExternalStatus.EMPTY exists = stat.exists() self.assertFalse(exists) stat.clean_state = ExternalStatus.UNKNOWN exists = stat.exists() self.assertFalse(exists) # this state represtens an internal logic error in how the # repo status was determined. stat.clean_state = ExternalStatus.STATUS_OK exists = stat.exists() self.assertTrue(exists) # this state represtens an internal logic error in how the # repo status was determined. stat.clean_state = ExternalStatus.DIRTY exists = stat.exists() self.assertTrue(exists)
def test_exists_unknown_all(self): """If the repository sync-state is unknown, then it is considered to exist regardless of clean state. """ stat = ExternalStatus() stat.sync_state = ExternalStatus.UNKNOWN stat.clean_state = ExternalStatus.DEFAULT exists = stat.exists() self.assertTrue(exists) stat.clean_state = ExternalStatus.EMPTY exists = stat.exists() self.assertTrue(exists) stat.clean_state = ExternalStatus.UNKNOWN exists = stat.exists() self.assertTrue(exists) stat.clean_state = ExternalStatus.STATUS_OK exists = stat.exists() self.assertTrue(exists) stat.clean_state = ExternalStatus.DIRTY exists = stat.exists() self.assertTrue(exists)
def test_update_empty_all(self): """If the repository in-sync is empty, then it is not safe to update, regardless of the clean state. """ stat = ExternalStatus() stat.sync_state = ExternalStatus.UNKNOWN stat.clean_state = ExternalStatus.DEFAULT safe_to_update = stat.safe_to_update() self.assertFalse(safe_to_update) stat.clean_state = ExternalStatus.EMPTY safe_to_update = stat.safe_to_update() self.assertFalse(safe_to_update) stat.clean_state = ExternalStatus.UNKNOWN safe_to_update = stat.safe_to_update() self.assertFalse(safe_to_update) stat.clean_state = ExternalStatus.STATUS_OK safe_to_update = stat.safe_to_update() self.assertFalse(safe_to_update) stat.clean_state = ExternalStatus.DIRTY safe_to_update = stat.safe_to_update() self.assertFalse(safe_to_update)