コード例 #1
0
def export(email, password, useLocally, replaceLatestVersion,
           hasBreakingChange):
    files = os.listdir("./dist")
    whlFiles = [file for file in files if os.path.splitext(file)[1] == ".whl"]
    assert len(whlFiles), "More than one whl files"

    match = re.search("pyinventory-([.0-9]+)-py3-none-any.whl", whlFiles[0])
    version = match.group(1)

    res = "\n".join(
        open(GRAPHQL_PYINVENORY_PATH, "r").read().splitlines()[10:-1])

    packages = json.loads(res)

    client = InventoryClient(email, password, is_local_host=useLocally)

    if len(packages) != 0:
        latestVersion = packages[0]["version"]
        if LooseVersion(version) == LooseVersion(latestVersion):
            print("version {} is already exported".format(version))
            if replaceLatestVersion:
                print("Replace version {} with new version".format(version))
                latestPackage = packages.pop(0)
                try:
                    client.delete_file(latestPackage["whlFileKey"], True)
                except Exception:
                    print(f'whlFileKey {latestPackage["whlFileKey"]} cannot '
                          "be deleted")
            else:
                return
        elif LooseVersion(version) < LooseVersion(latestVersion):
            print(
                "newer version {} is already exported than current version {}".
                format(latestVersion, version))
            return

    whlFileKey = client.store_file(os.path.join("./dist", whlFiles[0]),
                                   "application/zip", True)

    newPackage = {
        "version":
        version,
        "whlFileKey":
        whlFileKey,
        "uploadTime":
        datetime.isoformat(datetime.fromtimestamp(int(time.time()))) +
        "+00:00",
        "hasBreakingChange":
        hasBreakingChange,
    }
    packages.insert(0, newPackage)

    newContent = json.dumps(packages)
    open(GRAPHQL_PYINVENORY_PATH,
         "w").write(GRAPHQL_PYINVENORY_CONTENT.format(newContent))

    export_doc()
    schemas = extract_zip("graphql_schema_versions/old_schemas.zip")
    schemas[version] = open("../graph/graphql/schema/symphony.graphql").read()
    archive_zip("graphql_schema_versions/old_schemas.zip", schemas)
コード例 #2
0
ファイル: __init__.py プロジェクト: KingKongOne/magma
def init_client(email: str, password: str) -> InventoryClient:
    if TEST_MODE == TestMode.LOCAL:
        return InventoryClient(email, password, is_local_host=True)
    elif TEST_MODE == TestMode.REMOTE:
        return InventoryClient(email, password, tenant=f"{TENANT}.staging")
    else:
        return InventoryClient(email, password, is_dev_mode=True)
コード例 #3
0
class BaseTest(unittest.TestCase):
    client: InventoryClient = InventoryClient(TEST_USER_EMAIL,
                                              TEST_USER_EMAIL,
                                              is_dev_mode=True)

    @classmethod
    def setUpClass(cls) -> None:
        cls._waitForPlatform()
        cls.client = InventoryClient(TEST_USER_EMAIL,
                                     TEST_USER_EMAIL,
                                     is_dev_mode=True)

    @classmethod
    def tearDownClass(cls) -> None:
        cls.client.session.close()

    @classmethod
    def _waitForPlatform(cls) -> None:
        deadline = time.monotonic() + 60
        while time.monotonic() < deadline:
            try:
                response = requests.get(PLATFORM_SERVER_HEALTH_CHECK_URL,
                                        timeout=0.5)
                if response.status_code == 200:
                    return
            except Exception:
                time.sleep(0.5)
        raise Exception("Failed to wait for platform")
コード例 #4
0
 def test_user_deactivated(self) -> None:
     user_name = f"{self.random_string()}@fb.com"
     u = add_user(self.client, user_name, user_name)
     deactivate_user(self.client, u)
     active_users = get_active_users(self.client)
     self.assertEqual(1, len(active_users))
     with self.assertRaises(UserDeactivatedException):
         InventoryClient(user_name, user_name, is_dev_mode=True)
コード例 #5
0
ファイル: ipt_tx.py プロジェクト: stjordanis/magma-1
def import_tx(email, password, csvPath, csvOutPath, csvErrPath):
    with open(csvPath, mode="rb") as infile:
        reader = csv.reader(infile, delimiter=",", encoding="utf-8")
        columns_row = next(reader)
        columns_row = ["ITEM"] + columns_row[1:]
        Data = namedtuple("Data", columns_row)
        reporter = InventoryReporter(csvOutPath, csvErrPath)
        client = InventoryClient(email, password, "ipt", reporter=reporter)
        for i, data in enumerate(map(Data._make, reader)):
            import_tx_row(client, "{}:{}".format(csvPath, i), data)
コード例 #6
0
 def test_user_created(self) -> None:
     user_name = f"{self.random_string()}@fb.com"
     u = add_user(self.client, user_name, user_name)
     self.assertEqual(user_name, u.email)
     self.assertEqual(UserStatus.ACTIVE, u.status)
     active_users = get_active_users(self.client)
     self.assertEqual(2, len(active_users))
     client2 = InventoryClient(user_name, user_name, is_dev_mode=True)
     active_users = get_active_users(client2)
     self.assertEqual(2, len(active_users))
コード例 #7
0
 def setUpClass(cls) -> None:
     cls._waitForPlatform()
     cls.client = InventoryClient(TEST_USER_EMAIL,
                                  TEST_USER_EMAIL,
                                  is_dev_mode=True)
コード例 #8
0
 def setUp(self):
     self._waitForPlatform()
     self.client = InventoryClient(self.TEST_USER_EMAIL,
                                   self.TEST_USER_EMAIL,
                                   is_dev_mode=True)