def setUp(self): self.path = FauxFactory.generate_string( 'utf8', FauxFactory.generate_integer(min_value=1, max_value=100) ) self.desired = FauxFactory.generate_integer() self.response = MockResponse()
def get_value(self): """Return a value suitable for a :class:`StringField`.""" return _get_value( self, lambda: FauxFactory.generate_string( FauxFactory.generate_choice(self.str_type), FauxFactory.generate_integer(1, self.max_len) ) )
def _generate_name(self): """ Generates a random name string. :return: A random string of random length. :rtype: str """ name = unicode(FauxFactory.generate_string( FauxFactory.generate_choice(['alpha', 'cjk', 'latin1', 'utf8']), FauxFactory.generate_integer(1, 30))) return name
def test_create_auth(self): """Call ``create`` and specify the ``auth`` argument. Assert that the values provided for the ``auth`` argument are passed to :func:`robottelo.api.client.post`. """ client.post = Mock(return_value=MockResponse()) auth = ( FauxFactory.generate_string('utf8', 10), # username FauxFactory.generate_string('utf8', 10), # password ) SampleFactory().create(auth=auth) self.assertEqual(auth, client.post.call_args[1]['auth'])
def generate_system_facts(name=None): """Generate random system facts for registration. :param str name: A valid FQDN for a system. If one is not provided, then a random value will be generated. :return: A dictionary with random system facts :rtype: dict """ if name is None: name = u"{0}.example.net".format(FauxFactory.generate_alpha().lower()) # Make a copy of the system facts 'template' new_facts = copy.deepcopy(SYSTEM_FACTS) # Select a random RHEL version... distro = FauxFactory.generate_choice(DISTRO_IDS) # ...and update our facts new_facts["distribution.id"] = distro["id"] new_facts["distribution.version"] = distro["version"] new_facts["dmi.bios.relase_date"] = _bios_date().strftime("%m/%d/%Y") new_facts["dmi.memory.maximum_capacity"] = FauxFactory.generate_choice(MEMORY_CAPACITY) new_facts["dmi.memory.size"] = FauxFactory.generate_choice(MEMORY_SIZE) new_facts["dmi.system.uuid"] = FauxFactory.generate_uuid() new_facts["dmi.system.version"] = u"RHEL" new_facts["lscpu.architecture"] = distro["architecture"] new_facts["net.interface.eth1.hwaddr"] = FauxFactory.generate_mac() new_facts["net.interface.eth1.ipaddr"] = FauxFactory.generate_ipaddr() new_facts["network.hostname"] = name new_facts["network.ipaddr"] = new_facts["net.interface.eth1.ipaddr"] new_facts["uname.machine"] = distro["architecture"] new_facts["uname.nodename"] = name new_facts["uname.release"] = distro["kernel"] new_facts["virt.uuid"] = new_facts["dmi.system.uuid"] return new_facts
def test_min_val(self): """Set a ``min_val`` and call ``get_value``. Assert the number generated is greater than or equal to the specified value. """ min_val = FauxFactory.generate_integer() val = orm.IntegerField(min_val=min_val).get_value() self.assertGreaterEqual(val, min_val)
def test_max_val(self): """Set a ``max_val`` and call ``get_value``. Assert the number generated is less than or equal to the specified value. """ max_val = FauxFactory.generate_integer() val = orm.IntegerField(max_val=max_val).get_value() self.assertLessEqual(val, max_val)
def test_get_search(self): """@Test: GET ``api/v2/hosts`` and specify the ``search`` parameter. @Feature: Host @Assert: HTTP 200 is returned, along with ``search`` term. """ query = FauxFactory.generate_string( 'utf8', FauxFactory.generate_integer(1, 100) ) response = client.get( entities.Host().path(), auth=get_server_credentials(), params={'search': query}, verify=False, ) self.assertEqual(response.status_code, httplib.OK) self.assertEqual(response.json()['search'], query)
def test_min_max_val(self): """Set both ``min_val`` and ``max_val`` and call ``get_value``. Assert the number generated falls between the specified bounds. """ min_val = FauxFactory.generate_integer(-1000, 0) max_val = FauxFactory.generate_integer(0, 1000) # First, we'll allow a range of values... val = orm.IntegerField(min_val, max_val).get_value() self.assertGreaterEqual(val, min_val) self.assertLessEqual(val, max_val) # ... then, we'll allow only a single value... val = orm.IntegerField(min_val, min_val).get_value() self.assertEqual(val, min_val) # ... twice over, just to be sure. val = orm.IntegerField(max_val, max_val).get_value() self.assertEqual(val, max_val)
def setUp(self): # pylint:disable=C0103 """Back up and customize ``conf.properties`` and ``client.post``. Also generate a number suitable for use when instantiating entities. """ self.conf_properties = conf.properties.copy() conf.properties['main.server.hostname'] = 'example.com' conf.properties['foreman.admin.username'] = '******' conf.properties['foreman.admin.password'] = '******' self.client_post = client.post # SomeEntity(id=self.entity_id) self.entity_id = FauxFactory.generate_integer(min_value=1)
def _bios_date(): """Generate a random date for system's BIOS between today and 10 years ago. :return: A random `datetime.date` that falls within the last 10 years from today. :rtype: object """ # Today is... today = datetime.date.today() # and 10 years ago (~365 days * 10 years) is ten_years_ago = today - datetime.timedelta(3650) return FauxFactory.generate_date(ten_years_ago, today)
def setUp(self): # pylint:disable=C0103 """Back up several objects so they can be safely modified. Also generate a number suitable for use as an entity ID. """ self.client_delete = client.delete self.client_get = client.get self.conf_properties = conf.properties.copy() conf.properties['main.server.hostname'] = 'example.com' conf.properties['foreman.admin.username'] = '******' conf.properties['foreman.admin.password'] = '******' # e.g. SomeEntity(id=self.entity_id) self.entity_id = FauxFactory.generate_integer(min_value=1)
def test_get_per_page(self): """@Test: GET ``api/v2/hosts`` and specify the ``per_page`` parameter. @Feature: Host @Assert: HTTP 200 is returned, along with per ``per_page`` value. """ per_page = FauxFactory.generate_integer(1, 1000) response = client.get( entities.Host().path(), auth=get_server_credentials(), params={'per_page': per_page}, verify=False, ) self.assertEqual(response.status_code, httplib.OK) self.assertEqual(response.json()['per_page'], per_page)
def test_delete_202(self): """Test :meth:`robottelo.orm.EntityDeleteMixin.delete`. Assert that ``EntityDeleteMixin.delete`` returns a task ID if it receives an HTTP 202 response. """ # Create a mock server response object. foreman_task_id = FauxFactory.generate_integer() mock_response = mock.Mock() mock_response.status_code = 202 mock_response.raise_for_status.return_value = None mock_response.json.return_value = {u'id': foreman_task_id} # Make `client.delete` return the above object. client.delete = mock.Mock(return_value=mock_response) # See if EntityDeleteMixin.delete behaves correctly. response = EntityWithDelete(id=self.entity_id).delete( synchronous=False ) self.assertEqual(response, foreman_task_id)
def _get_value(field, default): """Return a value for ``field``. Use the following strategies, in order, to find a value for ``field``: 1. If ``field`` has a default value, return that value. 2. If ``field`` provides choices, randomly return one of those choices. 3. If ``default`` is callable, return ``default()``. 4. Finally, fall back to returning ``default``. :param field: A :class:`Field`, or one of its more specialized brethren. :param default: A callable which yields a value. :return: A value appropriate for that field. """ if 'default' in field.options.keys(): return field.options['default'] elif 'choices' in field.options.keys(): return FauxFactory.generate_choice(field.options['choices']) elif callable(default): return default() else: return default
def setUpClass(cls): """ Instantiate our factory object """ cls.factory = FauxFactory()
def setUp(self): # pylint:disable=C0103 """Backup and customize ``conf.properties``, and generate an ID.""" self.conf_properties = conf.properties.copy() conf.properties['main.server.hostname'] = 'example.com' self.id_ = FauxFactory.generate_integer(min_value=1)
def __init__(self): self.status_code = FauxFactory.generate_integer()
def test_smoke(self): """ @Test: Check that basic content can be created * Create a new user with admin permissions * Using the new user from above: * Create a new organization * Create two new lifecycle environments * Create a custom product * Create a custom YUM repository * Create a custom PUPPET repository * Synchronize both custom repositories * Create a new content view * Associate both repositories to new content view * Publish content view * Promote content view to both lifecycles * Create a new libvirt compute resource * Create a new subnet * Create a new domain * Create a new capsule * Create a new hostgroup and associate previous entities to it @Feature: Smoke Test @Assert: All entities are created and associated. """ # Create new user new_user = make_user({'admin': 'true'}) # Create new org as new user new_org = self._create( new_user, Org, {u'name': self._generate_name()} ) # Create new lifecycle environment 1 lifecycle1 = self._create( new_user, LifecycleEnvironment, {u'organization-id': new_org['id'], u'name': self._generate_name(), u'prior': u'Library'} ) # Create new lifecycle environment 2 lifecycle2 = self._create( new_user, LifecycleEnvironment, {u'organization-id': new_org['id'], u'name': self._generate_name(), u'prior': lifecycle1['name']} ) # Create a new product new_product = self._create( new_user, Product, {u'organization-id': new_org['id'], u'name': self._generate_name()} ) # Create a YUM repository new_repo1 = self._create( new_user, Repository, {u'product-id': new_product['id'], u'name': self._generate_name(), u'content-type': u'yum', u'publish-via-http': u'true', u'url': GOOGLE_CHROME_REPO} ) # Create a Puppet repository new_repo2 = self._create( new_user, Repository, {u'product-id': new_product['id'], u'name': self._generate_name(), u'content-type': u'puppet', u'publish-via-http': u'true', u'url': FAKE_PUPPET_REPO} ) # Synchronize YUM repository result = Repository.with_user( new_user['login'], new_user['password'] ).synchronize({'id': new_repo1['id']}) self.assertEqual( result.return_code, 0, u"Return code is non-zero: {0}".format(result.return_code)) self.assertEqual( len(result.stderr), 0, u"Failed to synchronize YUM repo: {0}".format(result.stderr)) # Synchronize puppet repository result = Repository.with_user( new_user['login'], new_user['password'] ).synchronize({'id': new_repo2['id']}) self.assertEqual( result.return_code, 0, u"Return code is non-zero: {0}".format(result.return_code)) self.assertEqual( len(result.stderr), 0, u"Failed to synchronize Puppet repo: {0}".format(result.stderr)) # Create a Content View new_cv = self._create( new_user, ContentView, {u'organization-id': new_org['id'], u'name': self._generate_name()} ) # Associate yum repository to content view result = ContentView.with_user( new_user['login'], new_user['password'] ).add_repository( {u'id': new_cv['id'], u'repository-id': new_repo1['id']}) self.assertEqual( result.return_code, 0, u"Return code is non-zero: {0}".format(result.return_code)) self.assertEqual( len(result.stderr), 0, u"Failed to add YUM repo to content view: {0}".format( result.stderr)) # Fetch puppet module puppet_result = PuppetModule.with_user( new_user['login'], new_user['password'] ).list( {u'repository-id': new_repo2['id'], u'per-page': False}) self.assertEqual( puppet_result.return_code, 0, u"Return code is non-zero: {0}".format(result.return_code)) self.assertEqual( len(puppet_result.stderr), 0, u"Puppet modules list was not generated: {0}".format( result.stderr)) # Associate puppet repository to content view result = ContentView.with_user( new_user['login'], new_user['password'] ).puppet_module_add( { u'content-view-id': new_cv['id'], u'name': puppet_result.stdout[0]['name'] } ) self.assertEqual( result.return_code, 0, u"Return code is non-zero: {0}".format(result.return_code)) self.assertEqual( len(result.stderr), 0, u"Failed to add YUM repo to content view: {0}".format( result.stderr)) # Publish content view result = ContentView.with_user( new_user['login'], new_user['password'] ).publish({u'id': new_cv['id']}) self.assertEqual( result.return_code, 0, u"Return code is non-zero: {0}".format(result.return_code)) self.assertEqual( len(result.stderr), 0, u"Failed to publish content view: {0}".format(result.stderr)) # Only after we publish version1 the info is populated. result = ContentView.with_user( new_user['login'], new_user['password'] ).info({u'id': new_cv['id']}) self.assertEqual( result.return_code, 0, u"Return code is non-zero: {0}".format(result.return_code)) self.assertEqual( len(result.stderr), 0, u"Could not fetch content view info: {0}".format(result.stderr)) # Let us now store the version1 id version1_id = result.stdout['versions'][0]['id'] # Promote content view to first lifecycle result = ContentView.with_user( new_user['login'], new_user['password'] ).version_promote( {u'id': result.stdout['versions'][0]['id'], u'lifecycle-environment-id': lifecycle1['id']}) self.assertEqual( result.return_code, 0, u"Return code is non-zero: {0}".format(result.return_code)) self.assertEqual( len(result.stderr), 0, u"Failed to promote content view to lifecycle '{0}': {1}".format( lifecycle1['name'], result.stderr)) # Promote content view to second lifecycle result = ContentView.with_user( new_user['login'], new_user['password'] ).version_promote( {u'id': version1_id, u'lifecycle-environment-id': lifecycle2['id']}) self.assertEqual( result.return_code, 0, u"Return code is non-zero: {0}".format(result.return_code)) self.assertEqual( len(result.stderr), 0, u"Failed to promote content view to lifecycle '{0}': {1}".format( lifecycle2['name'], result.stderr)) # Create a new libvirt compute resource result = self._create( new_user, ComputeResource, { u'name': self._generate_name(), u'provider': u'Libvirt', u'url': u'qemu+tcp://{0}:16509/system'.format( conf.properties['main.server.hostname']) }) # Create a new subnet new_subnet = self._create( new_user, Subnet, { u'name': self._generate_name(), u'network': FauxFactory.generate_ipaddr(ip3=True), u'mask': u'255.255.255.0' } ) # Create a domain new_domain = self._create( new_user, Domain, { u'name': self._generate_name(), } ) # Fetch Puppet environment for second lifecycle # (unfortunately it is not straight forward to extract this) # The puppet environment we want has a name like this... env_name = u'KT_{0}_{1}_'.format( # Hyphens are replaced by underscores new_org['label'].replace('-', '_',), lifecycle2['label'].replace('-', '_') ) # We fetch all the puppet environments for our organization... result = Environment.with_user( new_user['login'], new_user['password'] ).list( { u'search': u'organization=\"{0}\"'.format( new_org['name']) }) self.assertEqual( result.return_code, 0, u"Return code is non-zero: {0}".format(result.return_code)) self.assertEqual( len(result.stderr), 0, u"Failed to fetch puppet environments: {0}".format( result.stderr)) # Now look for the puppet environment that matches lifecycle2 puppet_env = [ env for env in result.stdout if env['name'].startswith( env_name)] self.assertEqual( len(puppet_env), 1, u'Could not find the puppet environment: {0}'.format(env_name)) # Create new Capsule... new_capsule = self._create( new_user, Proxy, { u'name': self._generate_name(), u'url': u'https://{0}:9090/'.format( conf.properties['main.server.hostname']) } ) # ...and add it to the organization result = Org.with_user( new_user['login'], new_user['password'] ).add_smart_proxy( { u'id': new_org['id'], u'smart-proxy-id': new_capsule['id'] } ) self.assertEqual( result.return_code, 0, u"Return code is non-zero: {0}".format(result.return_code)) self.assertEqual( len(result.stderr), 0, u"Failed to add capsule '{0}' to org '{1}': {2}".format( new_capsule['name'], new_org['name'], result.stderr)) # Create a hostgroup... new_hg = self._create( new_user, HostGroup, { u'name': self._generate_name(), u'domain-id': new_domain['id'], u'subnet-id': new_subnet['id'], u'environment-id': puppet_env[0]['id'], u'puppet-ca-proxy-id': new_capsule['id'], u'puppet-proxy-id': new_capsule['id'], } ) # ...and add it to the organization result = Org.with_user( new_user['login'], new_user['password'] ).add_hostgroup( { u'id': new_org['id'], u'hostgroup-id': new_hg['id'] } ) self.assertEqual( result.return_code, 0, u"Return code is non-zero: {0}".format(result.return_code)) self.assertEqual( len(result.stderr), 0, u"Failed to add hostgroup '{0}' to org '{1}': {2}".format( new_hg['name'], new_org['name'], result.stderr))
def setUp(self): # pylint:disable=C0103 """Back up objects and generate common values.""" self.rm_backup = decorators._get_redmine_bug_status_id self.stat_backup = decorators._redmine_closed_issue_statuses decorators._redmine_closed_issue_statuses = lambda: [1, 2] self.bug_id = FauxFactory.generate_integer()
def setUp(self): # pylint:disable=C0103 """Back up objects and generate common values.""" self.backup = decorators._get_bugzilla_bug self.bug_id = FauxFactory.generate_integer()
def get_value(self): """Return a value suitable for a :class:`IntegerField`.""" return _get_value( self, FauxFactory.generate_integer(self.min_val, self.max_val) )
# Today is... today = datetime.date.today() # and 10 years ago (~365 days * 10 years) is ten_years_ago = today - datetime.timedelta(3650) return FauxFactory.generate_date(ten_years_ago, today) ARCHITECTURES = [u"i386", u"x86_64", u"ppc", u"s390x"] # https://en.wikipedia.org/wiki/Red_Hat_Enterprise_Linux#Version_history DISTRO_IDS = [ { u"id": u"Maipo", u"version": u"7.0", # There is no 'i386' for RHEL 7 u"architecture": FauxFactory.generate_choice(ARCHITECTURES[1:]), u"kernel": u"3.10.0-123.el7", }, { u"id": u"Santiago", u"version": u"6.{0}".format(FauxFactory.generate_integer(1, 5)), u"architecture": FauxFactory.generate_choice(ARCHITECTURES), u"kernel": u"2.6.32-431.el6", }, { u"id": u"Tikanga", u"version": u"5.{0}".format(FauxFactory.generate_integer(1, 10)), u"architecture": FauxFactory.generate_choice(ARCHITECTURES), u"kernel": u"2.6.18-371.el5", }, {