def test_undo_sync_without_cache(self, fake_requests, mock_update):
        user = UserFactory.create(admin=True, email_addr=u'*****@*****.**')
        project_syncer = ProjectSyncer(self.target_url, self.target_key)

        project = ProjectFactory.build(short_name=self.target_id)
        project_syncer.undo_sync(project)
        assert_raises(AssertionError, project_syncer._sync.assert_called)
    def test_get_target_owners_if_project_not_exist_prod(self, fake_requests, mock_get_user_email, mock_get):
        user = UserFactory.create(admin=True, email_addr=u'*****@*****.**')
        project_syncer = ProjectSyncer(self.target_url, self.target_key)

        mock_get.return_value = create_target()
        project = ProjectFactory.build(short_name=self.target_id)
        project_syncer.get_target_owners(project, True)
        mock_get_user_email.assert_called()
    def test_sync_update_not_enabled(self, fake_requests, mock_update, mock_cat, mock_get):
        project_syncer = ProjectSyncer(self.target_url, self.target_key)
        user = UserFactory.create(admin=True, email_addr=u'*****@*****.**')
        project_syncer.syncer = user

        target = create_target()
        target['info']['sync']['enabled'] = False
        mock_get.return_value = target
        project = ProjectFactory.create()
        assert_raises(NotEnabled, project_syncer.sync, project)
    def test_sync_create_new(self, fake_requests, mock_create, mock_cat, mock_get):
        project_syncer = ProjectSyncer(self.target_url, self.target_key)
        user = UserFactory.create(admin=True, email_addr=u'*****@*****.**')
        project_syncer.syncer = user

        fake_requests.get.return_value = create_response(True, 200, json.dumps({'info': {'x':1}}))
        project = ProjectFactory.create()
        project_syncer.sync(project)
        project_syncer.get_target.assert_called_once()
        project_syncer._create.assert_called_once()
 def test_get_target_owners_if_project_exist_prod(self, fake_requests, mock_get, mock_get_target_user):
     user = UserFactory.create(admin=True, email_addr=u'*****@*****.**')
     project_syncer = ProjectSyncer(self.target_url, self.target_key)
     mock_get_target_user.return_value = create_response(True, 200, json.dumps({'email_addr': '*****@*****.**'}))
     mock_get.return_value = create_target()
     project = ProjectFactory.build(short_name=self.target_id)
     emails = project_syncer.get_target_owners(project, False)
     assert len(emails) == 3
     assert '*****@*****.**' in emails
     mock_get_target_user.assert_called()
    def test_sync_update_existing(self, fake_requests, mock_update, mock_cache, mock_cat, mock_get):
        project_syncer = ProjectSyncer(self.target_url, self.target_key)
        user = UserFactory.create(admin=True, email_addr=u'*****@*****.**')
        project_syncer.syncer = user

        mock_get.return_value = create_target()
        project = ProjectFactory.create()
        project_syncer.sync(project)
        project_syncer.get_target.assert_called_once()
        project_syncer.cache_target.assert_called_once()
        project_syncer._sync.assert_called_once()
        mock_cat.assert_called_once()
Beispiel #7
0
 def test_sync_update_existing(self, fake_requests, mock_update, mock_cache,
                               mock_cat, mock_get):
     project_syncer = ProjectSyncer(self.target_url, self.target_key)
     user = UserFactory.create(admin=True, email_addr=u'*****@*****.**')
     project_syncer.syncer = user
     res = Response()
     res._ok = False
     res.status_code = 403
     res._content = ""
     mock_get.return_value = create_target()
     mock_update.return_value = res
     project = ProjectFactory.create()
     project_syncer.sync(project)
     project_syncer.get_target.assert_called_once()
     project_syncer.cache_target.assert_called_once()
     project_syncer._sync.assert_called_once()
     mock_cat.assert_called_once()
Beispiel #8
0
    def test_sync_api_integration(self, mock_cat):
        project_syncer = ProjectSyncer(self.target_url, self.target_key)
        user = UserFactory.create(admin=True, email_addr=u'*****@*****.**')
        project_syncer.syncer = user

        target = create_target()
        project = ProjectFactory.create()
        # no sync info by default
        assert not project.info.get("sync")

        payload = project_syncer._build_payload(project, target)

        # sync existing does put request
        headers = [('Authorization', user.api_key)]
        res = self.app.put("/api/project/{}".format(project.id),
                           headers=headers,
                           data=json.dumps(payload))
        assert res.status_code == 200, 'build_payload output should result in valid api query'
        assert res.json["info"]["sync"] == payload["info"]["sync"]
Beispiel #9
0
    def test_create_api_integration(self, mock_cat):
        project_syncer = ProjectSyncer(self.target_url, self.target_key)
        user = UserFactory.create(admin=True, email_addr=u'*****@*****.**')
        project_syncer.syncer = user

        project = ProjectFactory.create()
        payload = project_syncer._build_payload(project)

        # delete project to test api
        db.session.query(Project).delete()
        # sync create does post request
        headers = [('Authorization', user.api_key)]
        res = self.app.post("/api/project",
                            headers=headers,
                            data=json.dumps(payload))
        assert res.status_code == 200, 'build_payload output should result in valid api query'
        # check that password hash correctly handled
        data = json.loads(res.data)
        assert data['info']['passwd_hash'] == payload['info']['passwd_hash']
    def test_undo_sync_with_cache(self, fake_requests, eock_update):
        user = UserFactory.create(admin=True, email_addr=u'*****@*****.**')
        project_syncer = ProjectSyncer(self.target_url, self.target_key)

        project = ProjectFactory.build(short_name=self.target_id)
        project_syncer.cache_target(create_target(), self.target_id)
        project_syncer.undo_sync(project)
        project_syncer._sync.assert_called_once()
 def test_get_user_email(self, fake_requests, mock_requests):
     user = UserFactory.create(admin=True, email_addr=u'*****@*****.**')
     project_syncer = ProjectSyncer(self.target_url, self.target_key)
     content = json.dumps(user.dictize())
     mock_requests.get.return_value = create_response(content=content)
     project_syncer.get_user_email(user.id) == '*****@*****.**'