|
| 1 | +import os |
| 2 | +import uuid |
| 3 | +from expects import expect, equal |
| 4 | +from mamba import before, description, it |
| 5 | +from sdcclient import SdSecureClient, SdMonitorClient |
| 6 | +from specs import be_successful_api_call |
| 7 | +from collections import defaultdict |
| 8 | + |
| 9 | +TEAM_PREFIX_NAME = 'sysdig-sdk - ' |
| 10 | + |
| 11 | +with description("Teams", "integration", "teams") as self: |
| 12 | + with before.all: |
| 13 | + self.secure_client = SdSecureClient( |
| 14 | + sdc_url=os.getenv("SDC_SECURE_URL", "https://secure.sysdig.com"), |
| 15 | + token=os.getenv("SDC_SECURE_TOKEN") |
| 16 | + ) |
| 17 | + self.monitor_client = SdMonitorClient( |
| 18 | + sdc_url=os.getenv("SDC_MONITOR_URL", "https://app.sysdigcloud.com"), |
| 19 | + token=os.getenv("SDC_MONITOR_TOKEN") |
| 20 | + ) |
| 21 | + |
| 22 | + with before.each: |
| 23 | + self.team_name = f'{TEAM_PREFIX_NAME}{uuid.uuid4()}' |
| 24 | + |
| 25 | + with it("it should list all teams"): |
| 26 | + ok, teams_monitor = self.monitor_client.get_teams() |
| 27 | + expect((ok, teams_monitor)).to(be_successful_api_call) |
| 28 | + |
| 29 | + ok, teams_secure = self.secure_client.get_teams() |
| 30 | + expect((ok, teams_secure)).to(be_successful_api_call) |
| 31 | + |
| 32 | + count_monitor = defaultdict(int) |
| 33 | + count_secure = defaultdict(int) |
| 34 | + |
| 35 | + def count_products(teams, count): |
| 36 | + for team in teams: |
| 37 | + for product in team['products']: |
| 38 | + count[product] += 1 |
| 39 | + |
| 40 | + count_products(teams_monitor, count_monitor) |
| 41 | + count_products(teams_secure, count_secure) |
| 42 | + |
| 43 | + expect(len(count_secure)).to(equal(len(count_monitor))) |
| 44 | + for k, v in count_monitor.items(): |
| 45 | + expect(count_secure[k]).to(equal(v)) |
| 46 | + expect(len(teams_secure)).to(equal(len(teams_monitor))) |
| 47 | + |
| 48 | + with it("it should list only monitor teams"): |
| 49 | + ok, team = self.secure_client.create_team(self.team_name) |
| 50 | + expect((ok, team)).to(be_successful_api_call) |
| 51 | + |
| 52 | + ok, teams = self.monitor_client.get_teams(product_filter='SDC') |
| 53 | + expect((ok, teams)).to(be_successful_api_call) |
| 54 | + |
| 55 | + secure_teams = [t for t in teams if 'SDS' in t['products']] |
| 56 | + expect(len(secure_teams)).to(equal(0)) |
| 57 | + |
| 58 | + ok, res = self.secure_client.delete_team(self.team_name) |
| 59 | + expect((ok, res)).to(be_successful_api_call) |
| 60 | + |
| 61 | + with it("it should list only secure teams"): |
| 62 | + ok, team = self.monitor_client.create_team(self.team_name) |
| 63 | + expect((ok, team)).to(be_successful_api_call) |
| 64 | + |
| 65 | + ok, teams = self.secure_client.get_teams(product_filter='SDS') |
| 66 | + expect((ok, teams)).to(be_successful_api_call) |
| 67 | + |
| 68 | + monitor_teams = [t for t in teams if 'SDC' in t['products']] |
| 69 | + expect(len(monitor_teams)).to(equal(0)) |
| 70 | + |
| 71 | + ok, res = self.monitor_client.delete_team(self.team_name) |
| 72 | + expect((ok, res)).to(be_successful_api_call) |
0 commit comments