<commit_before>/*
This file is part of the Juju GUI, which lets users view and manage Juju
environments within a graphical interface (https://launchpad.net/juju-gui).
Copyright (C) 2012-2013 Canonical Ltd.

This program is free software: you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License version 3, as published by
the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
General Public License for more details.

You should have received a copy of the GNU Affero General Public License along
with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

'use strict';

describe('Entity Extension', function() {
  var Y, EntityModel, entityModel, jujuConfig, models, utils;

  before(function(done) {
    Y = YUI(GlobalConfig).use([
      'juju-models',
      'juju-tests-utils'
    ], function(Y) {
      models = Y.namespace('juju.models');
      utils = Y.namespace('juju-tests.utils');
      done();
    });
  });

  beforeEach(function() {
    jujuConfig = window.juju_config;
    EntityModel = Y.Base.create(
      'entity-model', Y.Base, [models.EntityExtension], {});
    entityModel = new EntityModel();
    var attrs = {
      id: '~owner/foobar',
      storeId: 'cs:~owner/foobar-132',
      name: 'foo-bar',
      description: 'A test description.',
      downloads: '0',
      is_approved: false,
      revisions: [],
      url: 'http://example.com/'
    };
    entityModel.setAttrs(attrs);
  });

  afterEach(function() {
    entityModel.destroy();
    window.juju_config = jujuConfig;
  });

  it('parses owner from the ID', function() {
    assert.equal('owner', entityModel.ownerFromId(),
                 'owner was not extracted properly from the ID');
  });

  it('defaults to charmers when owner is not in ID', function() {
    entityModel.set('id', 'foobar');
    assert.equal('charmers', entityModel.ownerFromId(),
                 'default owner was not set to "charmers"');
  });

  it('converts a charm to an entity POJO', function() {
    var attrs = {
      entityType: 'charm',
      series: 'trusty',
      tags: ['database', 'application'],
    };
    var iconPath = 'v5/' + entityModel.get('id') + '/icon.svg';
    utils.makeStubMethod(utils, 'getIconPath', iconPath);
    entityModel.setAttrs(attrs);
    var entity = entityModel.toEntity();
    var expected = {
      description: 'A test description.',
      displayName: 'foo bar',
      downloads: '0',
      id: '~owner/foobar',
      storeId: 'cs:~owner/foobar-132',
      name: 'foo-bar',
      owner: 'owner',
      promulgated: false,
      revisions: [],
      special: undefined,
      type: 'charm',
      url: 'http://example.com/',
      iconPath: iconPath,
      series: 'trusty',
      tags: ['database', 'application']
    };
    assert.deepEqual(expected, entity,
                     'charm POJO did not match expected object');
  });

  it('converts a bundle to an entity POJO', function() {
    utils.makeStubMethod(entityModel, 'parseBundleServices', []);
    var attrs = {
      id: 'foobar',
      machines: {machine1: 1, machine2: 2},
      owner: 'foobar-charmers',
      entityType: 'bundle',
      serviceCount: 3,
      applications: [],
      unitCount: 5
    };
    entityModel.setAttrs(attrs);
    var entity = entityModel.toEntity();
    var expected = {
      description: 'A test description.',
      displayName: 'foo bar',
      downloads: '0',
      id: 'foobar',
      storeId: 'cs:~owner/foobar-132',
      machineCount: 2,
      name: 'foo-bar',
      owner: 'foobar-charmers',
      promulgated: false,
      revisions: [],
      special: undefined,
      type: 'bundle',
      url: 'http://example.com/',
      // no staticURL is defined on window.juju_config.staticURL so this
      // path should not include a staticURL prefix.
      iconPath: 'static/gui/build/app/assets/images/non-sprites/bundle.svg',
      serviceCount: 3,
      applications: [],
      unitCount: 5
    };
    assert.deepEqual(expected, entity,
                     'bundle POJO did not match expected object');
  });

  it('uses the staticURL for bundle asset if available', function() {
    window.juju_config = {
      staticURL: 'static'
    };
    utils.makeStubMethod(entityModel, 'parseBundleServices', []);
    var attrs = {
      id: 'foobar',
      owner: 'foobar-charmers',
      entityType: 'bundle',
      services: [],
    };
    entityModel.setAttrs(attrs);
    var entity = entityModel.toEntity();
    assert.deepEqual(
      entity.iconPath,
       'static/static/gui/build/app/assets/images/non-sprites/bundle.svg');
  });
});
<commit_msg>Replace makeStubMethod with sinon.stub in the entity extension tests.<commit_after>/*
This file is part of the Juju GUI, which lets users view and manage Juju
environments within a graphical interface (https://launchpad.net/juju-gui).
Copyright (C) 2012-2013 Canonical Ltd.

This program is free software: you can redistribute it and/or modify it under
the terms of the GNU Affero General Public License version 3, as published by
the Free Software Foundation.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
General Public License for more details.

You should have received a copy of the GNU Affero General Public License along
with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

'use strict';

describe('Entity Extension', function() {
  var Y, EntityModel, entityModel, jujuConfig, models, utils;

  before(function(done) {
    Y = YUI(GlobalConfig).use([
      'juju-models',
      'juju-tests-utils'
    ], function(Y) {
      models = Y.namespace('juju.models');
      utils = Y.namespace('juju-tests.utils');
      done();
    });
  });

  beforeEach(function() {
    jujuConfig = window.juju_config;
    EntityModel = Y.Base.create(
      'entity-model', Y.Base, [models.EntityExtension], {});
    entityModel = new EntityModel();
    var attrs = {
      id: '~owner/foobar',
      storeId: 'cs:~owner/foobar-132',
      name: 'foo-bar',
      description: 'A test description.',
      downloads: '0',
      is_approved: false,
      revisions: [],
      url: 'http://example.com/'
    };
    entityModel.setAttrs(attrs);
  });

  afterEach(function() {
    entityModel.destroy();
    window.juju_config = jujuConfig;
  });

  it('parses owner from the ID', function() {
    assert.equal('owner', entityModel.ownerFromId(),
                 'owner was not extracted properly from the ID');
  });

  it('defaults to charmers when owner is not in ID', function() {
    entityModel.set('id', 'foobar');
    assert.equal('charmers', entityModel.ownerFromId(),
                 'default owner was not set to "charmers"');
  });

  it('converts a charm to an entity POJO', function() {
    var attrs = {
      entityType: 'charm',
      series: 'trusty',
      tags: ['database', 'application'],
    };
    var iconPath = 'v5/' + entityModel.get('id') + '/icon.svg';
    utils.getIconPath = sinon.stub().returns(iconPath);
    entityModel.setAttrs(attrs);
    var entity = entityModel.toEntity();
    var expected = {
      description: 'A test description.',
      displayName: 'foo bar',
      downloads: '0',
      id: '~owner/foobar',
      storeId: 'cs:~owner/foobar-132',
      name: 'foo-bar',
      owner: 'owner',
      promulgated: false,
      revisions: [],
      special: undefined,
      type: 'charm',
      url: 'http://example.com/',
      iconPath: iconPath,
      series: 'trusty',
      tags: ['database', 'application']
    };
    assert.deepEqual(expected, entity,
                     'charm POJO did not match expected object');
  });

  it('converts a bundle to an entity POJO', function() {
    entityModel.parseBundleServices = sinon.stub().returns([]);
    var attrs = {
      id: 'foobar',
      machines: {machine1: 1, machine2: 2},
      owner: 'foobar-charmers',
      entityType: 'bundle',
      serviceCount: 3,
      applications: [],
      unitCount: 5
    };
    entityModel.setAttrs(attrs);
    var entity = entityModel.toEntity();
    var expected = {
      description: 'A test description.',
      displayName: '<NAME>',
      downloads: '0',
      id: 'foobar',
      storeId: 'cs:~owner/foobar-132',
      machineCount: 2,
      name: 'foo-bar',
      owner: 'foobar-charmers',
      promulgated: false,
      revisions: [],
      special: undefined,
      type: 'bundle',
      url: 'http://example.com/',
      // no staticURL is defined on window.juju_config.staticURL so this
      // path should not include a staticURL prefix.
      iconPath: 'static/gui/build/app/assets/images/non-sprites/bundle.svg',
      serviceCount: 3,
      applications: [],
      unitCount: 5
    };
    assert.deepEqual(expected, entity,
                     'bundle POJO did not match expected object');
  });

  it('uses the staticURL for bundle asset if available', function() {
    window.juju_config = {
      staticURL: 'static'
    };
    entityModel.parseBundleServices = sinon.stub().returns([]);
    var attrs = {
      id: 'foobar',
      owner: 'foobar-charmers',
      entityType: 'bundle',
      services: [],
    };
    entityModel.setAttrs(attrs);
    var entity = entityModel.toEntity();
    assert.deepEqual(
      entity.iconPath,
       'static/static/gui/build/app/assets/images/non-sprites/bundle.svg');
  });
});

{'fraction_non_alphanumeric': 0.13390549064212595, 'fraction_numerical': 0.006410919243097921, 'mean_word_length': 2.7899686520376177, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 6, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7654837', 'n_tokens_mistral': 3015, 'n_tokens_neox': 2907, 'n_words': 828}