Best Python code snippet using assertpy_python
win_secedit_facts.py
Source:win_secedit_facts.py  
1#!/usr/bin/python2# -*- coding: utf-8 -*-3# Copyright 2016, Red Hat Inc  4#5# This file is part of Ansible6#7# Ansible is free software: you can redistribute it and/or modify8# it under the terms of the GNU General Public License as published by9# the Free Software Foundation, either version 3 of the License, or10# (at your option) any later version.11#12# Ansible is distributed in the hope that it will be useful,13# but WITHOUT ANY WARRANTY; without even the implied warranty of14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the15# GNU General Public License for more details.16#17# You should have received a copy of the GNU General Public License18# along with Ansible.  If not, see <http://www.gnu.org/licenses/>.19# this is a windows documentation stub.  actual code lives in the .ps120# file of the same name21DOCUMENTATION = '''22---23module: win_secedit_facts24version_added: '2.3'25short_description: Gets facts about local security policies via secedit26description:27    - Gathers key values for local security policies from secedit. Note that all the return examples are not guaranteed to be present. Secedit removes all keys that have blank values, so systems that do not have anything set for a given key will not be returned. Also note that the categories are returned with the spaces replaced with underscores since they are keys in the dictionary.28options: {}29author:30    - James Mighion (@jmighion) 31'''32EXAMPLES = '''33# Gather all secedit facts34- name: Gather secedit facts 35win_secedit_facts:36'''37RETURN = '''38# Event Audit39AuditAccountLogon: 40    description:41    returned: if exists42    type: string43    sample: 044AuditAccountManage: 45    description:46    returned: if exists47    type: string48    sample: 049AuditDSAccess: 50    description:51    returned: if exists52    type: string53    sample: 054AuditLogonEvents: 55    description:56    returned: if exists57    type: string58    sample: 059AuditObjectAccess: 60    description:61    returned: if exists62    type: string63    sample: 064AuditPolicyChange: 65    description:66    returned: if exists67    type: string68    sample: 069AuditPrivilegeUse: 70    description:71    returned: if exists72    type: string73    sample: 074AuditProcessTracking: 75    description:76    returned: if exists77    type: string78    sample: 079AuditSystemEvents: 80    description:81    returned: if exists82    type: string83    sample: 084# Privilege Rights85SeAssignPrimaryTokenPrivilege: 86    description:87    returned: if exists88    type: string89    sample: *S-1-5-19,*S-1-5-2090SeAuditPrivilege: 91    description:92    returned: if exists93    type: string94    sample: *S-1-5-19,*S-1-5-2095SeBackupPrivilege: 96    description:97    returned: if exists98    type: string99    sample: *S-1-5-32-544,*S-1-5-32-551100SeBatchLogonRight: 101    description:102    returned: if exists103    type: string104    sample: *S-1-5-32-544,*S-1-5-32-551,*S-1-5-32-559,*S-1-5-32-568105SeChangeNotifyPrivilege: 106    description:107    returned: if exists108    type: string109    sample: *S-1-1-0,*S-1-5-19,*S-1-5-20,*S-1-5-32-544,*S-1-5-32-545,*S-1-5-32-551110SeCreateGlobalPrivilege: 111    description:112    returned: if exists113    type: string114    sample: *S-1-5-19,*S-1-5-20,*S-1-5-32-544,*S-1-5-6115SeCreatePagefilePrivilege: 116    description:117    returned: if exists118    type: string119    sample: *S-1-5-32-544120SeCreateSymbolicLinkPrivilege: 121    description:122    returned: if exists123    type: string124    sample: *S-1-5-32-544125SeDebugPrivilege: 126    description:127    returned: if exists128    type: string129    sample: *S-1-5-32-544130SeImpersonatePrivilege: 131    description:132    returned: if exists133    type: string134    sample: *S-1-5-19,*S-1-5-20,*S-1-5-32-544,*S-1-5-32-568,*S-1-5-6135SeIncreaseBasePriorityPrivilege: 136    description:137    returned: if exists138    type: string139    sample: *S-1-5-32-544140SeIncreaseQuotaPrivilege: 141    description:142    returned: if exists143    type: string144    sample: *S-1-5-19,*S-1-5-20,*S-1-5-32-544145SeIncreaseWorkingSetPrivilege: 146    description:147    returned: if exists148    type: string149    sample: *S-1-5-32-545150SeInteractiveLogonRight: 151    description:152    returned: if exists153    type: string154    sample: *S-1-5-32-544,*S-1-5-32-545,*S-1-5-32-551155SeLoadDriverPrivilege: 156    description:157    returned: if exists158    type: string159    sample: *S-1-5-32-544160SeManageVolumePrivilege: 161    description:162    returned: if exists163    type: string164    sample: *S-1-5-32-544165SeNetworkLogonRight: 166    description:167    returned: if exists168    type: string169    sample: *S-1-1-0,*S-1-5-32-544,*S-1-5-32-545,*S-1-5-32-551170SeProfileSingleProcessPrivilege: 171    description:172    returned: if exists173    type: string174    sample: *S-1-5-32-544175SeRemoteInteractiveLogonRight: 176    description:177    returned: if exists178    type: string179    sample: *S-1-5-32-544,*S-1-5-32-555180SeRemoteShutdownPrivilege: 181    description:182    returned: if exists183    type: string184    sample: *S-1-5-32-544185SeRestorePrivilege: 186    description:187    returned: if exists188    type: string189    sample: *S-1-5-32-544,*S-1-5-32-551190SeSecurityPrivilege: 191    description:192    returned: if exists193    type: string194    sample: *S-1-5-32-544195SeServiceLogonRight: 196    description:197    returned: if exists198    type: string199    sample: *S-1-5-80-0200SeShutdownPrivilege: 201    description:202    returned: if exists203    type: string204    sample: *S-1-5-32-544,*S-1-5-32-551205SeSystemEnvironmentPrivilege: 206    description:207    returned: if exists208    type: string209    sample: *S-1-5-32-544210SeSystemProfilePrivilege: 211    description:212    returned: if exists213    type: string214    sample: *S-1-5-32-544,*S-1-5-80-3139157870-2983391045-3678747466-658725712-1809340420215SeSystemtimePrivilege: 216    description:217    returned: if exists218    type: string219    sample: *S-1-5-19,*S-1-5-32-544220SeTakeOwnershipPrivilege: 221    description:222    returned: if exists223    type: string224    sample: *S-1-5-32-544225SeTimeZonePrivilege: 226    description:227    returned: if exists228    type: string229    sample: *S-1-5-19,*S-1-5-32-544230SeUndockPrivilege: 231    description:232    returned: if exists233    type: string234    sample: *S-1-5-32-544235# Registry Values236MACHINE\\\\Software\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Setup\\\\RecoveryConsole\\\\SecurityLevel: 237    description:238    returned: if exists239    type: string240    sample: 4,0 241MACHINE\\\\Software\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Setup\\\\RecoveryConsole\\\\SetCommand: 242    description:243    returned: if exists244    type: string245    sample: 4,0 246MACHINE\\\\Software\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Winlogon\\\\CachedLogonsCount: 247    description:248    returned: if exists249    type: string250    sample: 1,\\"10\\" 251MACHINE\\\\Software\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Winlogon\\\\ForceUnlockLogon: 252    description:253    returned: if exists254    type: string255    sample: 4,0 256MACHINE\\\\Software\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Winlogon\\\\PasswordExpiryWarning: 257    description:258    returned: if exists259    type: string260    sample: 4,5 261MACHINE\\\\Software\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Winlogon\\\\ScRemoveOption: 262    description:263    returned: if exists264    type: string265    sample: 1,\\"0\\" 266MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\ConsentPromptBehaviorAdmin: 267    description:268    returned: if exists269    type: string270    sample: 4,5 271MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\ConsentPromptBehaviorUser: 272    description:273    returned: if exists274    type: string275    sample: 4,3 276MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\DisableCAD: 277    description:278    returned: if exists279    type: string280    sample: 4,0 281MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\DontDisplayLastUserName: 282    description:283    returned: if exists284    type: string285    sample: 4,0 286MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\EnableInstallerDetection: 287    description:288    returned: if exists289    type: string290    sample: 4,1 291MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\EnableLUA: 292    description:293    returned: if exists294    type: string295    sample: 4,1 296MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\EnableSecureUIAPaths: 297    description:298    returned: if exists299    type: string300    sample: 4,1 301MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\EnableUIADesktopToggle: 302    description:303    returned: if exists304    type: string305    sample: 4,0 306MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\EnableVirtualization: 307    description:308    returned: if exists309    type: string310    sample: 4,1 311MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\FilterAdministratorToken: 312    description:313    returned: if exists314    type: string315    sample: 4,0 316MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\LegalNoticeCaption: 317    description:318    returned: if exists319    type: string320    sample: 1,\\"\\" 321MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\LegalNoticeText: 322    description:323    returned: if exists324    type: string325    sample: 7, 326MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\PromptOnSecureDesktop: 327    description:328    returned: if exists329    type: string330    sample: 4,1 331MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\ScForceOption: 332    description:333    returned: if exists334    type: string335    sample: 4,0 336MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\ShutdownWithoutLogon: 337    description:338    returned: if exists339    type: string340    sample: 4,0 341MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\UndockWithoutLogon: 342    description:343    returned: if exists344    type: string345    sample: 4,1 346MACHINE\\\\Software\\\\Microsoft\\\\Windows\\\\CurrentVersion\\\\Policies\\\\System\\\\ValidateAdminCodeSignatures: 347    description:348    returned: if exists349    type: string350    sample: 4,0 351MACHINE\\\\Software\\\\Policies\\\\Microsoft\\\\Windows\\\\Safer\\\\CodeIdentifiers\\\\AuthenticodeEnabled: 352    description:353    returned: if exists354    type: string355    sample: 4,0 356MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\AuditBaseObjects: 357    description:358    returned: if exists359    type: string360    sample: 4,0 361MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\CrashOnAuditFail: 362    description:363    returned: if exists364    type: string365    sample: 4,0 366MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\DisableDomainCreds: 367    description:368    returned: if exists369    type: string370    sample: 4,0 371MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\EveryoneIncludesAnonymous: 372    description:373    returned: if exists374    type: string375    sample: 4,0 376MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\FIPSAlgorithmPolicy\\\\Enabled: 377    description:378    returned: if exists379    type: string380    sample: 4,0 381MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\ForceGuest: 382    description:383    returned: if exists384    type: string385    sample: 4,0 386MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\FullPrivilegeAuditing: 387    description:388    returned: if exists389    type: string390    sample: 3,0 391MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\LimitBlankPasswordUse: 392    description:393    returned: if exists394    type: string395    sample: 4,1 396MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\MSV1_0\\\\NTLMMinClientSec: 397    description:398    returned: if exists399    type: string400    sample: 4,536870912 401MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\MSV1_0\\\\NTLMMinServerSec: 402    description:403    returned: if exists404    type: string405    sample: 4,536870912 406MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\NoLMHash: 407    description:408    returned: if exists409    type: string410    sample: 4,1 411MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\RestrictAnonymous: 412    description:413    returned: if exists414    type: string415    sample: 4,0 416MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Lsa\\\\RestrictAnonymousSAM: 417    description:418    returned: if exists419    type: string420    sample: 4,1 421MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Print\\\\Providers\\\\LanMan Print Services\\\\Servers\\\\AddPrinterDrivers: 422    description:423    returned: if exists424    type: string425    sample: 4,1 426MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\SecurePipeServers\\\\Winreg\\\\AllowedExactPaths\\\\Machine: 427    description:428    returned: if exists429    type: string430    sample: 7,System\\\\CurrentControlSet\\\\Control\\\\ProductOptions,System\\\\CurrentControlSet\\\\Control\\\\Server Applications,Software\\\\Microsoft\\\\Windows NT\\\\CurrentVersion 431MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\SecurePipeServers\\\\Winreg\\\\AllowedPaths\\\\Machine: 432    description:433    returned: if exists434    type: string435    sample: 7,System\\\\CurrentControlSet\\\\Control\\\\Print\\\\Printers,System\\\\CurrentControlSet\\\\Services\\\\Eventlog,Software\\\\Microsoft\\\\OLAP Server,Software\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Print,Software\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Windows,System\\\\CurrentControlSet\\\\Control\\\\ContentIndex,System\\\\CurrentControlSet\\\\Control\\\\Terminal Server,System\\\\CurrentControlSet\\\\Control\\\\Terminal Server\\\\UserConfig,System\\\\CurrentControlSet\\\\Control\\\\Terminal Server\\\\DefaultUserConfiguration,Software\\\\Microsoft\\\\Windows NT\\\\CurrentVersion\\\\Perflib,System\\\\CurrentControlSet\\\\Services\\\\SysmonLog 436MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Session Manager\\\\Kernel\\\\ObCaseInsensitive: 437    description:438    returned: if exists439    type: string440    sample: 4,1 441MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Session Manager\\\\Memory Management\\\\ClearPageFileAtShutdown: 442    description:443    returned: if exists444    type: string445    sample: 4,0 446MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Session Manager\\\\ProtectionMode: 447    description:448    returned: if exists449    type: string450    sample: 4,1 451MACHINE\\\\System\\\\CurrentControlSet\\\\Control\\\\Session Manager\\\\SubSystems\\\\optional: 452    description:453    returned: if exists454    type: string455    sample: 7, 456MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\LDAP\\\\LDAPClientIntegrity: 457    description:458    returned: if exists459    type: string460    sample: 4,1 461MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\LanManServer\\\\Parameters\\\\AutoDisconnect: 462    description:463    returned: if exists464    type: string465    sample: 4,15 466MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\LanManServer\\\\Parameters\\\\EnableForcedLogOff: 467    description:468    returned: if exists469    type: string470    sample: 4,1 471MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\LanManServer\\\\Parameters\\\\EnableSecuritySignature: 472    description:473    returned: if exists474    type: string475    sample: 4,1 476MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\LanManServer\\\\Parameters\\\\NullSessionPipes: 477    description:478    returned: if exists479    type: string480    sample: 7,,netlogon,samr,lsarpc 481MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\LanManServer\\\\Parameters\\\\RequireSecuritySignature: 482    description:483    returned: if exists484    type: string485    sample: 4,1 486MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\LanManServer\\\\Parameters\\\\RestrictNullSessAccess: 487    description:488    returned: if exists489    type: string490    sample: 4,1 491MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\LanmanWorkstation\\\\Parameters\\\\EnablePlainTextPassword: 492    description:493    returned: if exists494    type: string495    sample: 4,0 496MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\LanmanWorkstation\\\\Parameters\\\\EnableSecuritySignature: 497    description:498    returned: if exists499    type: string500    sample: 4,1 501MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\LanmanWorkstation\\\\Parameters\\\\RequireSecuritySignature: 502    description:503    returned: if exists504    type: string505    sample: 4,0 506MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\NTDS\\\\Parameters\\\\LDAPServerIntegrity: 507    description:508    returned: if exists509    type: string510    sample: 4,1 511MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\Netlogon\\\\Parameters\\\\DisablePasswordChange: 512    description:513    returned: if exists514    type: string515    sample: 4,0 516MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\Netlogon\\\\Parameters\\\\MaximumPasswordAge: 517    description:518    returned: if exists519    type: string520    sample: 4,30 521MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\Netlogon\\\\Parameters\\\\RequireSignOrSeal: 522    description:523    returned: if exists524    type: string525    sample: 4,1 526MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\Netlogon\\\\Parameters\\\\RequireStrongKey: 527    description:528    returned: if exists529    type: string530    sample: 4,1 531MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\Netlogon\\\\Parameters\\\\SealSecureChannel: 532    description:533    returned: if exists534    type: string535    sample: 4,1 536MACHINE\\\\System\\\\CurrentControlSet\\\\Services\\\\Netlogon\\\\Parameters\\\\SignSecureChannel: 537    description:538    returned: if exists539    type: string540    sample: 4,1541# System Access542ClearTextPassword: 543    description:544    returned: if exists545    type: string546    sample: 0 547EnableAdminAccount: 548    description:549    returned: if exists550    type: string551    sample: 1 552EnableGuestAccount: 553    description:554    returned: if exists555    type: string556    sample: 0 557ForceLogoffWhenHourExpire: 558    description:559    returned: if exists560    type: string561    sample: 0 562LSAAnonymousNameLookup: 563    description:564    returned: if exists565    type: string566    sample: 0 567LockoutBadCount: 568    description:569    returned: if exists570    type: string571    sample: 0 572MaximumPasswordAge: 573    description:574    returned: if exists575    type: string576    sample: 42 577MinimumPasswordAge: 578    description:579    returned: if exists580    type: string581    sample: 1 582MinimumPasswordLength: 583    description:584    returned: if exists585    type: string586    sample: 7 587NewAdministratorName: 588    description:589    returned: if exists590    type: string591    sample: \\"Administrator\\" 592NewGuestName: 593    description:594    returned: if exists595    type: string596    sample: \\"Guest\\" 597PasswordComplexity: 598    description:599    returned: if exists600    type: string601    sample: 1 602PasswordHistorySize: 603    description:604    returned: if exists605    type: string606    sample: 24 607RequireLogonToChangePassword: 608    description:609    returned: if exists610    type: string611    sample: 0612# Unicode613Unicode: 614    description:615    returned: if exists616    type: string617    sample: yes618# Version619Revision: 620    description:621    returned: if exists622    type: string623    sample: 1624signature: 625    description:626    returned: if exists627    type: string628    sample: \\"$CHICAGO$\\"...files-and-ignores.js
Source:files-and-ignores.js  
1'use strict'2var test = require('tap').test3var common = require('../common-tap.js')4var path = require('path')5var rimraf = require('rimraf')6var mkdirp = require('mkdirp')7var fs = require('graceful-fs')8var tar = require('tar')9var zlib = require('zlib')10var basepath = path.resolve(__dirname, path.basename(__filename, '.js'))11var fixturepath = path.resolve(basepath, 'npm-test-files')12var targetpath = path.resolve(basepath, 'target')13var Tacks = require('tacks')14var File = Tacks.File15var Dir = Tacks.Dir16test('basic file inclusion', function (t) {17  var fixture = new Tacks(18    Dir({19      'package.json': File({20        name: 'npm-test-files',21        version: '1.2.5',22        files: [23          'include',24          'sub/include'25        ]26      }),27      include: File(''),28      sub: Dir({ include: File('') }),29      notincluded: File('')30    })31  )32  withFixture(t, fixture, function (done) {33    t.ok(fileExists('include'), 'toplevel file included')34    t.ok(fileExists('sub/include'), 'nested file included')35    t.notOk(fileExists('notincluded'), 'unspecified file not included')36    done()37  })38})39test('basic file exclusion', function (t) {40  var fixture = new Tacks(41    Dir({42      'package.json': File({43        name: 'npm-test-files',44        version: '1.2.5'45      }),46      '.npmignore': File(47        'ignore\n' +48        'sub/ignore\n'49      ),50      include: File(''),51      ignore: File(''),52      sub: Dir({ ignore: File('') })53    })54  )55  withFixture(t, fixture, function (done) {56    t.notOk(fileExists('ignore'), 'toplevel file excluded')57    t.notOk(fileExists('sub/ignore'), 'nested file excluded')58    t.ok(fileExists('include'), 'unignored file included')59    done()60  })61})62test('toplevel-only and blanket ignores', function (t) {63  var fixture = new Tacks(64    Dir({65      'package.json': File({66        name: 'npm-test-files',67        version: '1.2.5'68      }),69      '.npmignore': File(70        './shallow1\n' +71        '/shallow2\n' +72        '/sub/onelevel\n' +73        'deep\n' +74        ''75      ),76      shallow1: File(''),77      shallow2: File(''),78      deep: File(''),79      sub: Dir({80        shallow1: File(''),81        shallow2: File(''),82        onelevel: File(''),83        deep: File(''),84        sub: Dir({85          deep: File(''),86          onelevel: File('')87        })88      })89    })90  )91  withFixture(t, fixture, function (done) {92    t.notOk(fileExists('shallow2'), '/ file excluded')93    t.ok(fileExists('sub/shallow1'), 'nested ./ file included')94    t.ok(fileExists('sub/shallow2'), 'nested / file included')95    t.ok(fileExists('sub/sub/onelevel'), 'double-nested file included')96    t.notOk(fileExists('sub/onelevel'), 'nested / file excluded')97    t.notOk(fileExists('deep'), 'deep file excluded')98    t.notOk(fileExists('sub/deep'), 'nested deep file excluded')99    t.notOk(fileExists('sub/sub/deep'), 'double-nested deep file excluded')100    t.ok(fileExists('shallow1'), './ file included')101    done()102  })103})104test('.npmignore works for nested directories recursively', function (t) {105  var fixture = new Tacks(106    Dir({107      'package.json': File({108        name: 'npm-test-files',109        version: '1.2.5'110      }),111      '.npmignore': File(112        '/ignore\n' +113        'deep\n'114      ),115      include: File(''),116      ignore: File(''),117      deep: File(''),118      sub: Dir({119        ignore: File(''),120        include: File(''),121        deep: File(''),122        sub: Dir({123          '.npmignore': File(124            '/ignore\n'125          ),126          ignore: File(''),127          include: File(''),128          deep: File('')129        })130      })131    })132  )133  withFixture(t, fixture, function (done) {134    t.notOk(fileExists('ignore'), 'toplevel file excluded')135    t.ok(fileExists('include'), 'unignored file included')136    t.ok(fileExists('sub/ignore'), 'same-name file in nested dir included')137    t.ok(fileExists('sub/include'), 'unignored nested dir file included')138    t.notOk(fileExists('sub/sub/ignore'), 'sub-sub-directory file excluded')139    t.ok(fileExists('sub/sub/include'), 'sub-sube-directory file included')140    t.notOk(fileExists('deep'), 'deep file excluded')141    t.notOk(fileExists('sub/deep'), 'sub-dir deep file excluded')142    t.notOk(fileExists('sub/sub/deep'), 'sub-sub-dir deep file excluded')143    done()144  })145})146test('.gitignore should have identical semantics', function (t) {147  var fixture = new Tacks(148    Dir({149      'package.json': File({150        name: 'npm-test-files',151        version: '1.2.5'152      }),153      '.gitignore': File(154        './shallow1\n' +155        '/shallow2\n' +156        '/sub/onelevel\n' +157        'deep\n' +158        ''159      ),160      shallow1: File(''),161      shallow2: File(''),162      deep: File(''),163      sub: Dir({164        shallow1: File(''),165        shallow2: File(''),166        onelevel: File(''),167        deep: File(''),168        sub: Dir({169          deep: File(''),170          onelevel: File('')171        })172      })173    })174  )175  withFixture(t, fixture, function (done) {176    t.notOk(fileExists('shallow2'), '/ file excluded')177    t.ok(fileExists('sub/shallow1'), 'nested ./ file included')178    t.ok(fileExists('sub/shallow2'), 'nested / file included')179    t.ok(fileExists('sub/sub/onelevel'), 'double-nested file included')180    t.notOk(fileExists('sub/onelevel'), 'nested / file excluded')181    t.notOk(fileExists('deep'), 'deep file excluded')182    t.notOk(fileExists('sub/deep'), 'nested deep file excluded')183    t.notOk(fileExists('sub/sub/deep'), 'double-nested deep file excluded')184    t.ok(fileExists('shallow1'), './ file included')185    done()186  })187})188test('.npmignore should always be overridden by files array', function (t) {189  var fixture = new Tacks(190    Dir({191      'package.json': File({192        name: 'npm-test-files',193        version: '1.2.5',194        files: [195          'include',196          'sub'197        ]198      }),199      '.npmignore': File(200        'include\n' +201        'ignore\n' +202        'sub/included\n'203      ),204      include: File(''),205      ignore: File(''),206      sub: Dir({207        include: File('')208      })209    })210  )211  withFixture(t, fixture, function (done) {212    t.notOk(fileExists('ignore'), 'toplevel file excluded')213    t.ok(fileExists('include'), 'unignored file included')214    t.ok(fileExists('sub/include'), 'nested file included')215    done()216  })217})218test('.gitignore supported for ignores', function (t) {219  var fixture = new Tacks(220    Dir({221      'package.json': File({222        name: 'npm-test-files',223        version: '1.2.5'224      }),225      '.gitignore': File(226        'ignore\n' +227        'sub/ignore\n'228      ),229      include: File(''),230      ignore: File(''),231      sub: Dir({ ignore: File('') })232    })233  )234  withFixture(t, fixture, function (done) {235    t.notOk(fileExists('ignore'), 'toplevel file excluded')236    t.notOk(fileExists('sub/ignore'), 'nested file excluded')237    t.ok(fileExists('include'), 'unignored file included')238    done()239  })240})241test('.npmignore completely overrides .gitignore', function (t) {242  var fixture = new Tacks(243    Dir({244      'package.json': File({245        name: 'npm-test-files',246        version: '1.2.5'247      }),248      '.npmignore': File(249        'ignore\n' +250        'sub/ignore\n'251      ),252      '.gitignore': File(253        'include\n' +254        'sub/include\n' +255        'extra\n'256      ),257      include: File(''),258      sub: Dir({ include: File('') }),259      extra: File('')260    })261  )262  withFixture(t, fixture, function (done) {263    t.ok(fileExists('include'), 'gitignored toplevel file included')264    t.ok(fileExists('extra'), 'gitignored extra toplevel file included')265    t.ok(fileExists('sub/include'), 'gitignored nested file included')266    t.notOk(fileExists('ignore'), 'toplevel file excluded')267    t.notOk(fileExists('sub/ignore'), 'nested file excluded')268    done()269  })270})271test('files array overrides .npmignore', function (t) {272  var fixture = new Tacks(273    Dir({274      'package.json': File({275        name: 'npm-test-files',276        version: '1.2.5',277        files: [278          'include',279          'sub/include'280        ]281      }),282      '.npmignore': File(283        'include\n' +284        'sub/include\n'285      ),286      include: File(''),287      sub: Dir({ include: File('') })288    })289  )290  withFixture(t, fixture, function (done) {291    t.ok(fileExists('include'), 'toplevel file included')292    t.ok(fileExists('sub/include'), 'nested file included')293    done()294  })295})296test('includes files regardless of emptiness', function (t) {297  var fixture = new Tacks(298    Dir({299      'package.json': File({300        name: 'npm-test-files',301        version: '1.2.5',302        files: [303          'full',304          'empty'305        ]306      }),307      full: File('This file has contents~'),308      empty: File('')309    })310  )311  withFixture(t, fixture, function (done) {312    t.ok(fileExists('full'), 'contentful file included')313    t.ok(fileExists('empty'), 'empty file included')314    done()315  })316})317test('.npmignore itself gets included', function (t) {318  var fixture = new Tacks(319    Dir({320      'package.json': File({321        name: 'npm-test-files',322        version: '1.2.5',323        files: [324          '.npmignore'325        ]326      }),327      '.npmignore': File('')328    })329  )330  withFixture(t, fixture, function (done) {331    t.ok(fileExists('.npmignore'), '.npmignore included')332    done()333  })334})335test('include default files when missing files spec', function (t) {336  var fixture = new Tacks(337    Dir({338      'package.json': File({339        name: 'npm-test-files',340        version: '1.2.5'341      }),342      'index.js': File(''),343      foo: File(''),344      node_modules: Dir({foo: Dir({bar: File('')})})345    })346  )347  withFixture(t, fixture, function (done) {348    t.ok(fileExists('index.js'), 'index.js included')349    t.ok(fileExists('foo'), 'foo included')350    t.notOk(fileExists('node_modules'), 'node_modules not included')351    done()352  })353})354test('include main file', function (t) {355  var fixture = new Tacks(356    Dir({357      'package.json': File({358        name: 'npm-test-files',359        version: '1.2.5',360        main: 'foo.js',361        files: []362      }),363      'index.js': File(''),364      'foo.js': File('')365    })366  )367  withFixture(t, fixture, function (done) {368    t.ok(fileExists('foo.js'), 'foo.js included because of main')369    t.notOk(fileExists('index.js'), 'index.js not included')370    done()371  })372})373test('certain files ignored unconditionally', function (t) {374  var fixture = new Tacks(375    Dir({376      'package.json': File({377        name: 'npm-test-files',378        version: '1.2.5',379        files: [380          '.git',381          '.svn',382          'CVS',383          '.hg',384          '.lock-wscript',385          '.wafpickle-0',386          '.wafpickle-5',387          '.wafpickle-50',388          'build/config.gypi',389          'npm-debug.log',390          '.npmrc',391          '.foo.swp',392          '.DS_Store',393          '._ohno'394        ]395      }),396      '.git': Dir({foo: File('')}),397      '.svn': Dir({foo: File('')}),398      'CVS': Dir({foo: File('')}),399      '.hg': Dir({foo: File('')}),400      '.lock-wscript': File(''),401      '.wafpickle-0': File(''),402      '.wafpickle-5': File(''),403      '.wafpickle-50': File(''),404      'build': Dir({'config.gypi': File('')}),405      'npm-debug.log': File(''),406      '.npmrc': File(''),407      '.foo.swp': File(''),408      '.DS_Store': Dir({foo: File('')}),409      '._ohno': File(''),410      '._ohnoes': Dir({noes: File('')})411    })412  )413  withFixture(t, fixture, function (done) {414    t.notOk(fileExists('.git'), '.git not included')415    t.notOk(fileExists('.svn'), '.svn not included')416    t.notOk(fileExists('CVS'), 'CVS not included')417    t.notOk(fileExists('.hg'), '.hg not included')418    t.notOk(fileExists('.lock-wscript'), '.lock-wscript not included')419    t.notOk(fileExists('.wafpickle-0'), '.wafpickle-0 not included')420    t.notOk(fileExists('.wafpickle-5'), '.wafpickle-5 not included')421    t.notOk(fileExists('.wafpickle-50'), '.wafpickle-50 not included')422    t.notOk(fileExists('build/config.gypi'), 'build/config.gypi not included')423    t.notOk(fileExists('npm-debug.log'), 'npm-debug.log not included')424    t.notOk(fileExists('.npmrc'), '.npmrc not included')425    t.notOk(fileExists('.foo.swp'), '.foo.swp not included')426    t.notOk(fileExists('.DS_Store'), '.DS_Store not included')427    t.notOk(fileExists('._ohno'), '._ohno not included')428    t.notOk(fileExists('._ohnoes'), '._ohnoes not included')429    done()430  })431})432test('certain files included unconditionally', function (t) {433  var fixture = new Tacks(434    Dir({435      'package.json': File({436        name: 'npm-test-files',437        version: '1.2.5'438      }),439      '.npmignore': File(440        'package.json',441        'README',442        'Readme',443        'readme.md',444        'readme.randomext',445        'changelog',446        'CHAngelog',447        'ChangeLOG.txt',448        'history',449        'HistorY',450        'HistorY.md',451        'license',452        'licence',453        'LICENSE',454        'LICENCE'455      ),456      'README': File(''),457      'Readme': File(''),458      'readme.md': File(''),459      'readme.randomext': File(''),460      'changelog': File(''),461      'CHAngelog': File(''),462      'ChangeLOG.txt': File(''),463      'history': File(''),464      'HistorY': File(''),465      'HistorY.md': File(''),466      'license': File(''),467      'licence': File(''),468      'LICENSE': File(''),469      'LICENCE': File('')470    })471  )472  withFixture(t, fixture, function (done) {473    t.ok(fileExists('package.json'), 'package.json included')474    t.ok(fileExists('README'), 'README included')475    t.ok(fileExists('Readme'), 'Readme included')476    t.ok(fileExists('readme.md'), 'readme.md included')477    t.ok(fileExists('readme.randomext'), 'readme.randomext included')478    t.ok(fileExists('changelog'), 'changelog included')479    t.ok(fileExists('CHAngelog'), 'CHAngelog included')480    t.ok(fileExists('ChangeLOG.txt'), 'ChangeLOG.txt included')481    t.ok(fileExists('license'), 'license included')482    t.ok(fileExists('licence'), 'licence included')483    t.ok(fileExists('LICENSE'), 'LICENSE included')484    t.ok(fileExists('LICENCE'), 'LICENCE included')485    done()486  })487})488test('unconditional inclusion does not capture modules', function (t) {489  var fixture = new Tacks(490    Dir({491      'package.json': File({492        name: 'npm-test-files',493        version: '1.2.5'494      }),495      'node_modules': Dir({496        'readme': Dir({ 'file': File('') }),497        'README': Dir({ 'file': File('') }),498        'licence': Dir({ 'file': File('') }),499        'license': Dir({ 'file': File('') }),500        'history': Dir({ 'file': File('') }),501        'History': Dir({ 'file': File('') }),502        'changelog': Dir({ 'file': File('') }),503        'ChangeLOG': Dir({ 'file': File('') })504      })505    })506  )507  withFixture(t, fixture, function (done) {508    t.notOk(fileExists('node_modules/readme/file'), 'readme module not included')509    t.notOk(fileExists('node_modules/README/file'), 'README module not included')510    t.notOk(fileExists('node_modules/licence/file'), 'licence module not included')511    t.notOk(fileExists('node_modules/license/file'), 'license module not included')512    t.notOk(fileExists('node_modules/history/file'), 'history module not included')513    t.notOk(fileExists('node_modules/History/file'), 'History module not included')514    t.notOk(fileExists('node_modules/changelog/file'), 'changelog module not included')515    t.notOk(fileExists('node_modules/ChangeLOG/file'), 'ChangeLOG module not included')516    done()517  })518})519test('folder-based inclusion works', function (t) {520  var fixture = new Tacks(521    Dir({522      'package.json': File({523        name: 'npm-test-files',524        version: '1.2.5',525        files: [526          'sub1/sub',527          'sub2'528        ]529      }),530      sub1: Dir({531        sub: Dir({532          include1: File(''),533          include2: File('')534        }),535        ignored: File('')536      }),537      sub2: Dir({538        include1: File(''),539        include2: File(''),540        empty: Dir({})541      })542    })543  )544  withFixture(t, fixture, function (done) {545    t.ok(fileExists('sub1/sub/include1'), 'nested dir included')546    t.ok(fileExists('sub1/sub/include2'), 'nested dir included')547    t.notOk(fileExists('sub1/ignored'), 'unspecified file not included')548    t.ok(fileExists('sub2/include1'), 'dir contents included')549    t.ok(fileExists('sub2/include2'), 'dir contents included')550    t.notOk(fileExists('sub2/empty'), 'empty dir not included')551    done()552  })553})554function fileExists (file) {555  try {556    return !!fs.statSync(path.resolve(targetpath, 'package', file))557  } catch (_) {558    return false559  }560}561function withFixture (t, fixture, tester) {562  fixture.create(fixturepath)563  mkdirp.sync(targetpath)564  common.npm(['pack', fixturepath], {cwd: basepath}, extractAndCheck)565  function extractAndCheck (err, code) {566    if (err) throw err567    t.is(code, 0, 'pack went ok')568    extractTarball(checkTests)569  }570  function checkTests (err) {571    if (err) throw err572    tester(removeAndDone)573  }574  function removeAndDone (err) {575    if (err) throw err576    fixture.remove(fixturepath)577    rimraf.sync(basepath)578    t.done()579  }580}581function extractTarball (cb) {582  // Unpack to disk so case-insensitive filesystems are consistent583  fs.createReadStream(path.join(basepath, 'npm-test-files-1.2.5.tgz'))584    .pipe(zlib.Unzip())585    .on('error', cb)586    .pipe(tar.Extract(targetpath))587    .on('error', cb)588    .on('end', function () { cb() })...test_ofc_manager.py
Source:test_ofc_manager.py  
1# vim: tabstop=4 shiftwidth=4 softtabstop=42# Copyright 2012 NEC Corporation.  All rights reserved.3#4#    Licensed under the Apache License, Version 2.0 (the "License"); you may5#    not use this file except in compliance with the License. You may obtain6#    a copy of the License at7#8#         http://www.apache.org/licenses/LICENSE-2.09#10#    Unless required by applicable law or agreed to in writing, software11#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT12#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the13#    License for the specific language governing permissions and limitations14#    under the License.15# @author: Ryota MIBU16from quantum import context17from quantum.openstack.common import uuidutils18from quantum.plugins.nec.common import config19from quantum.plugins.nec.db import api as ndb20from quantum.plugins.nec.db import models as nmodels  # noqa21from quantum.plugins.nec import ofc_manager22from quantum.tests import base23class OFCManagerTestBase(base.BaseTestCase):24    """Class conisting of OFCManager unit tests."""25    def setUp(self):26        super(OFCManagerTestBase, self).setUp()27        driver = "quantum.tests.unit.nec.stub_ofc_driver.StubOFCDriver"28        config.CONF.set_override('driver', driver, 'OFC')29        ndb.initialize()30        self.addCleanup(ndb.clear_db)31        self.ofc = ofc_manager.OFCManager()32        self.ctx = context.get_admin_context()33    def get_random_params(self):34        """create random parameters for portinfo test."""35        tenant = uuidutils.generate_uuid()36        network = uuidutils.generate_uuid()37        port = uuidutils.generate_uuid()38        _filter = uuidutils.generate_uuid()39        none = uuidutils.generate_uuid()40        return tenant, network, port, _filter, none41class OFCManagerTest(OFCManagerTestBase):42    def testa_create_ofc_tenant(self):43        """test create ofc_tenant."""44        t, n, p, f, none = self.get_random_params()45        self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_tenant', t))46        self.ofc.create_ofc_tenant(self.ctx, t)47        self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_tenant', t))48        tenant = ndb.get_ofc_item(self.ctx.session, 'ofc_tenant', t)49        self.assertEqual(tenant.ofc_id, "ofc-" + t[:-4])50    def testb_exists_ofc_tenant(self):51        """test exists_ofc_tenant."""52        t, n, p, f, none = self.get_random_params()53        self.assertFalse(self.ofc.exists_ofc_tenant(self.ctx, t))54        self.ofc.create_ofc_tenant(self.ctx, t)55        self.assertTrue(self.ofc.exists_ofc_tenant(self.ctx, t))56    def testc_delete_ofc_tenant(self):57        """test delete ofc_tenant."""58        t, n, p, f, none = self.get_random_params()59        self.ofc.create_ofc_tenant(self.ctx, t)60        self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_tenant', t))61        self.ofc.delete_ofc_tenant(self.ctx, t)62        self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_tenant', t))63    def testd_create_ofc_network(self):64        """test create ofc_network."""65        t, n, p, f, none = self.get_random_params()66        self.ofc.create_ofc_tenant(self.ctx, t)67        self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_network', n))68        self.ofc.create_ofc_network(self.ctx, t, n)69        self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_network', n))70        network = ndb.get_ofc_item(self.ctx.session, 'ofc_network', n)71        self.assertEqual(network.ofc_id, "ofc-" + n[:-4])72    def teste_exists_ofc_network(self):73        """test exists_ofc_network."""74        t, n, p, f, none = self.get_random_params()75        self.ofc.create_ofc_tenant(self.ctx, t)76        self.assertFalse(self.ofc.exists_ofc_network(self.ctx, n))77        self.ofc.create_ofc_network(self.ctx, t, n)78        self.assertTrue(self.ofc.exists_ofc_network(self.ctx, n))79    def testf_delete_ofc_network(self):80        """test delete ofc_network."""81        t, n, p, f, none = self.get_random_params()82        self.ofc.create_ofc_tenant(self.ctx, t)83        self.ofc.create_ofc_network(self.ctx, t, n)84        self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_network', n))85        self.ofc.delete_ofc_network(self.ctx, n, {'tenant_id': t})86        self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_network', n))87    def testg_create_ofc_port(self):88        """test create ofc_port."""89        t, n, p, f, none = self.get_random_params()90        self.ofc.create_ofc_tenant(self.ctx, t)91        self.ofc.create_ofc_network(self.ctx, t, n)92        ndb.add_portinfo(self.ctx.session, p, "0xabc", 1, 65535,93                         "00:11:22:33:44:55")94        self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_port', p))95        port = {'tenant_id': t, 'network_id': n}96        self.ofc.create_ofc_port(self.ctx, p, port)97        self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_port', p))98        port = ndb.get_ofc_item(self.ctx.session, 'ofc_port', p)99        self.assertEqual(port.ofc_id, "ofc-" + p[:-4])100    def testh_exists_ofc_port(self):101        """test exists_ofc_port."""102        t, n, p, f, none = self.get_random_params()103        self.ofc.create_ofc_tenant(self.ctx, t)104        self.ofc.create_ofc_network(self.ctx, t, n)105        ndb.add_portinfo(self.ctx.session, p, "0xabc", 2, 65535,106                         "00:12:22:33:44:55")107        self.assertFalse(self.ofc.exists_ofc_port(self.ctx, p))108        port = {'tenant_id': t, 'network_id': n}109        self.ofc.create_ofc_port(self.ctx, p, port)110        self.assertTrue(self.ofc.exists_ofc_port(self.ctx, p))111    def testi_delete_ofc_port(self):112        """test delete ofc_port."""113        t, n, p, f, none = self.get_random_params()114        self.ofc.create_ofc_tenant(self.ctx, t)115        self.ofc.create_ofc_network(self.ctx, t, n)116        ndb.add_portinfo(self.ctx.session, p, "0xabc", 3, 65535,117                         "00:13:22:33:44:55")118        port = {'tenant_id': t, 'network_id': n}119        self.ofc.create_ofc_port(self.ctx, p, port)120        self.assertTrue(ndb.get_ofc_item(self.ctx.session, 'ofc_port', p))121        self.ofc.delete_ofc_port(self.ctx, p, port)122        self.assertFalse(ndb.get_ofc_item(self.ctx.session, 'ofc_port', p))123    def testj_create_ofc_packet_filter(self):124        """test create ofc_filter."""125        t, n, p, f, none = self.get_random_params()126        self.ofc.create_ofc_tenant(self.ctx, t)127        self.ofc.create_ofc_network(self.ctx, t, n)128        self.assertFalse(ndb.get_ofc_item(self.ctx.session,129                                          'ofc_packet_filter', f))130        pf = {'tenant_id': t, 'network_id': n}131        self.ofc.create_ofc_packet_filter(self.ctx, f, pf)132        self.assertTrue(ndb.get_ofc_item(self.ctx.session,133                                         'ofc_packet_filter', f))134        _filter = ndb.get_ofc_item(self.ctx.session, 'ofc_packet_filter', f)135        self.assertEqual(_filter.ofc_id, "ofc-" + f[:-4])136    def testk_exists_ofc_packet_filter(self):137        """test exists_ofc_packet_filter."""138        t, n, p, f, none = self.get_random_params()139        self.ofc.create_ofc_tenant(self.ctx, t)140        self.ofc.create_ofc_network(self.ctx, t, n)141        self.assertFalse(self.ofc.exists_ofc_packet_filter(self.ctx, f))142        pf = {'tenant_id': t, 'network_id': n}143        self.ofc.create_ofc_packet_filter(self.ctx, f, pf)144        self.assertTrue(self.ofc.exists_ofc_packet_filter(self.ctx, f))145    def testl_delete_ofc_packet_filter(self):146        """test delete ofc_filter."""147        t, n, p, f, none = self.get_random_params()148        self.ofc.create_ofc_tenant(self.ctx, t)149        self.ofc.create_ofc_network(self.ctx, t, n)150        pf = {'tenant_id': t, 'network_id': n}151        self.ofc.create_ofc_packet_filter(self.ctx, f, pf)152        self.assertTrue(ndb.get_ofc_item(self.ctx.session,153                                         'ofc_packet_filter', f))154        self.ofc.delete_ofc_packet_filter(self.ctx, f)155        self.assertFalse(ndb.get_ofc_item(self.ctx.session,156                                          'ofc_packet_filter', f))157class OFCManagerTestWithOldMapping(OFCManagerTestBase):158    def test_exists_ofc_tenant(self):159        t, n, p, f, none = self.get_random_params()160        ofc_t, ofc_n, ofc_p, ofc_f, ofc_none = self.get_random_params()161        self.assertFalse(self.ofc.exists_ofc_tenant(self.ctx, t))162        session = self.ctx.session163        ndb.add_ofc_item(session, 'ofc_tenant', t, ofc_t, old_style=True)164        self.assertTrue(self.ofc.exists_ofc_tenant(self.ctx, t))165    def test_delete_ofc_tenant(self):166        t, n, p, f, none = self.get_random_params()167        ofc_t, ofc_n, ofc_p, ofc_f, ofc_none = self.get_random_params()168        self.assertFalse(self.ofc.exists_ofc_tenant(self.ctx, t))169        session = self.ctx.session170        ndb.add_ofc_item(session, 'ofc_tenant', t, ofc_t, old_style=True)171        self.assertTrue(self.ofc.exists_ofc_tenant(self.ctx, t))172        self.ofc.delete_ofc_tenant(self.ctx, t)173        self.assertFalse(self.ofc.exists_ofc_tenant(self.ctx, t))174    def test_exists_ofc_network(self):175        t, n, p, f, none = self.get_random_params()176        ofc_t, ofc_n, ofc_p, ofc_f, ofc_none = self.get_random_params()177        self.assertFalse(self.ofc.exists_ofc_network(self.ctx, n))178        session = self.ctx.session179        ndb.add_ofc_item(session, 'ofc_network', n, ofc_n, old_style=True)180        self.assertTrue(self.ofc.exists_ofc_network(self.ctx, n))181    def test_delete_ofc_network(self):182        t, n, p, f, none = self.get_random_params()183        ofc_t, ofc_n, ofc_p, ofc_f, ofc_none = self.get_random_params()184        self.assertFalse(self.ofc.exists_ofc_network(self.ctx, n))185        session = self.ctx.session186        ndb.add_ofc_item(session, 'ofc_network', n, ofc_n, old_style=True)187        self.assertTrue(self.ofc.exists_ofc_network(self.ctx, n))188        net = {'tenant_id': t}189        self.ofc.delete_ofc_network(self.ctx, n, net)190        self.assertFalse(self.ofc.exists_ofc_network(self.ctx, n))191    def test_exists_ofc_port(self):192        t, n, p, f, none = self.get_random_params()193        ofc_t, ofc_n, ofc_p, ofc_f, ofc_none = self.get_random_params()194        self.assertFalse(self.ofc.exists_ofc_port(self.ctx, p))195        session = self.ctx.session196        ndb.add_ofc_item(session, 'ofc_port', p, ofc_p, old_style=True)197        self.assertTrue(self.ofc.exists_ofc_port(self.ctx, p))198    def test_delete_ofc_port(self):199        t, n, p, f, none = self.get_random_params()200        ofc_t, ofc_n, ofc_p, ofc_f, ofc_none = self.get_random_params()201        self.assertFalse(self.ofc.exists_ofc_port(self.ctx, p))202        session = self.ctx.session203        ndb.add_ofc_item(session, 'ofc_port', p, ofc_p, old_style=True)204        self.assertTrue(self.ofc.exists_ofc_port(self.ctx, p))205        port = {'tenant_id': t, 'network_id': n}206        self.ofc.delete_ofc_port(self.ctx, p, port)207        self.assertFalse(self.ofc.exists_ofc_port(self.ctx, p))208    def test_exists_ofc_packet_filter(self):209        t, n, p, f, none = self.get_random_params()210        ofc_t, ofc_n, ofc_p, ofc_f, ofc_none = self.get_random_params()211        self.assertFalse(self.ofc.exists_ofc_packet_filter(self.ctx, f))212        session = self.ctx.session213        ndb.add_ofc_item(session, 'ofc_packet_filter', f, ofc_f,214                         old_style=True)215        self.assertTrue(self.ofc.exists_ofc_packet_filter(self.ctx, f))216    def test_delete_ofc_packet_filter(self):217        t, n, p, f, none = self.get_random_params()218        ofc_t, ofc_n, ofc_p, ofc_f, ofc_none = self.get_random_params()219        self.assertFalse(self.ofc.exists_ofc_packet_filter(self.ctx, f))220        session = self.ctx.session221        ndb.add_ofc_item(session, 'ofc_packet_filter', f, ofc_f,222                         old_style=True)223        self.assertTrue(self.ofc.exists_ofc_packet_filter(self.ctx, f))224        self.ofc.delete_ofc_packet_filter(self.ctx, f)...test_volume.py
Source:test_volume.py  
...42        self.assertEqual(1, self.volumeDevice.unmount.call_count)43        utils.execute = origin_execute44        self.volumeDevice.unmount = origin_unmount45        os.path.exists = origin_os_path_exists46    def test__check_device_exists(self):47        origin_execute = utils.execute48        utils.execute = Mock()49        self.volumeDevice._check_device_exists()50        self.assertEqual(1, utils.execute.call_count)51        utils.execute = origin_execute52    def test__check_format(self):53        fake_spawn = _setUp_fake_spawn()54        self.volumeDevice._check_format()55        self.assertEqual(1, fake_spawn.expect.call_count)56    def test__check_format_2(self):57        fake_spawn = _setUp_fake_spawn(return_val=1)58        self.assertEqual(0, fake_spawn.expect.call_count)59        self.assertRaises(IOError, self.volumeDevice._check_format)60    def test__format(self):61        fake_spawn = _setUp_fake_spawn()62        self.volumeDevice._format()63        self.assertEqual(1, fake_spawn.expect.call_count)...Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!
