def can_convert_data_classes_to_and_from_string(): User = dodge.data_class("User", ["username", "password"]) user = User("bob", "password1") serialised_user = dodge.dumps(user) unserialised_user = dodge.loads(serialised_user, User) expected_user = User("bob", "password1") assert_equal(unserialised_user, expected_user)
def can_convert_nested_data_classes_to_and_from_string(): Profile = dodge.data_class("Profile", ["bio"]) User = dodge.data_class("User", ["username", dodge.field("profile", type=Profile)]) user = User("bob", Profile("I'm Bob.")) serialised_user = dodge.dumps(user) unserialised_user = dodge.loads(serialised_user, User) assert_equal(user, unserialised_user)
def can_convert_nested_data_classes_to_and_from_string(): Profile = dodge.data_class("Profile", ["bio"]) User = dodge.data_class("User", [ "username", dodge.field("profile", type=Profile), ]) user = User("bob", Profile("I'm Bob.")) serialised_user = dodge.dumps(user) unserialised_user = dodge.loads(serialised_user, User) assert_equal(user, unserialised_user)
def get_package_tarball(self, package_name, tarball_dir, params=None): with create_temporary_dir() as package_dir: self.get_package(package_name, package_dir, params=params) package_description = dodge.loads( read_file(os.path.join(package_dir, ".whack-package.json")), PackageDescription ) package_name = package_description.name package_filename = "{0}.whack-package".format(package_name) package_tarball_path = os.path.join(tarball_dir, package_filename) create_tarball(package_tarball_path, package_dir, rename_dir=package_name) return PackageTarball(package_tarball_path)