diff --git a/atlasapi/__init__.py b/atlasapi/__init__.py index a323088..98bc840 100644 --- a/atlasapi/__init__.py +++ b/atlasapi/__init__.py @@ -15,4 +15,4 @@ # __init__.py # Version of the realpython-reader package -__version__ = "2.0.6" +__version__ = "2.0.7" diff --git a/atlasapi/clusters.py b/atlasapi/clusters.py index 9ff9c19..cfe60fd 100644 --- a/atlasapi/clusters.py +++ b/atlasapi/clusters.py @@ -278,8 +278,10 @@ def __init__(self, backup_enabled: bool = False, srv_address: Optional[str] = None, providerSettings: Optional[ProviderSettings] = None, links: list = None, - id: Optional[str] = None + id: Optional[str] = None, + create_date: Optional[datetime] = None ) -> None: + self.create_date: Optional[datetime] = create_date self.id: Optional[str] = id self.providerSettings: Optional[ProviderSettings] = providerSettings self.backup_enabled: bool = backup_enabled @@ -341,10 +343,11 @@ def fill_from_dict(cls, data_dict: dict): providerSettings = ProviderSettings.from_dict(provider_settings_dict) links = data_dict.get('links', []) id = data_dict.get('id', None) + create_date = datetime.strptime(data_dict.get('createDate', None), FORMAT).astimezone(tz=pytz.UTC) return cls(backup_enabled, cluster_type, disk_size_gb, name, mongodb_major_version, mongodb_version, num_shards, mongo_uri, mongo_uri_updated, mongo_uri_with_options, paused, pit_enabled, replication_factor, state_name, autoscaling, replication_specs, - srv_address, providerSettings, links,id) + srv_address, providerSettings, links,id, create_date) def as_dict(self) -> dict: return_dict = self.__dict__ diff --git a/atlasapi/events_event_types.py b/atlasapi/events_event_types.py index 446e446..da03ea1 100644 --- a/atlasapi/events_event_types.py +++ b/atlasapi/events_event_types.py @@ -338,6 +338,14 @@ class AtlasEventTypes(Enum): ATLAS_MAINTENANCE_AUTO_DEFER_DISABLED = 'Atlas Maintenance Auto Defer Disabled' ATLAS_MAINTENANCE_START_ASAP = 'Atlas Maintenance Start Asap' ATLAS_MAINTENANCE_SCHEDULED_FOR_NEXT_WINDOW = 'Atlas Maintenance Scheduled For Next Window' + MAINTENANCE_WINDOW_ADDED = 'Atlas Maintenance Window Added' + MAINTENANCE_WINDOW_MODIFIED = 'Atlas Maintenance Window Modified' + MAINTENANCE_WINDOW_REMOVED = 'Atlas Maintenance Window Removed' + MAINTENANCE_DEFERRED = 'Atlas Maintenance Deferred' + MAINTENANCE_AUTO_DEFER_ENABLED = 'Atlas Maintenance Auto Defer Enabled' + MAINTENANCE_AUTO_DEFER_DISABLED = 'Atlas Maintenance Auto Defer Disabled' + MAINTENANCE_START_ASAP = 'Atlas Maintenance Start Asap' + MAINTENANCE_SCHEDULED_FOR_NEXT_WINDOW = 'Atlas Maintenance Scheduled For Next Window' COMPUTE_AUTO_SCALE_UNNECESSARY = 'Compute Auto Scale Unnecessary' COMPUTE_AUTO_SCALE_TRIGGERED = 'Compute Auto Scale Triggered' COMPUTE_AUTO_SCALE_SKIPPED = 'Compute Auto Scale Skipped' diff --git a/atlasapi/projects.py b/atlasapi/projects.py index 2197691..09dfa14 100644 --- a/atlasapi/projects.py +++ b/atlasapi/projects.py @@ -64,9 +64,10 @@ def from_dict(cls, data_dict): Returns: None """ + created_date = isodatetime.parse_datetime(data_dict.get("created")) return cls(id=data_dict.get("id"), name=data_dict.get("name"), links=data_dict.get("links", []), org_id=data_dict.get("orgId"), - created_date=data_dict.get("created"), cluster_count=data_dict.get("clusterCount")) + created_date=created_date, cluster_count=data_dict.get("clusterCount")) @property def create_dict(self) -> dict: @@ -107,17 +108,3 @@ def from_dict(cls,data_dict: dict): bool(data_dict.get("isRealtimePerformancePanelEnabled", False)), bool(data_dict.get("isSchemaAdvisorEnabled", False)), ) - - -""" -test_dict = { - "clusterCount": 2, - "created": "2016-07-14T14:19:33Z", - "id": "5a0a1e7e0f2912c554080ae6", - "links": [], - "name": "DocsFeedbackGroup", - "orgId": "5a0a1e7e0f2912c554080adc" -} - -print(Project.for_create(org_id='34', name='test_project').as_create_dict) -""" \ No newline at end of file diff --git a/setup.py b/setup.py index 3b3f09c..7f2367e 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ setup( name='atlasapi', - version='2.0.6', + version='2.0.7', python_requires='>=3.7', packages=find_packages(exclude=("tests",)), install_requires=['requests', 'python-dateutil', 'isodate', 'future', 'pytz', 'coolname', 'humanfriendly', 'nose'], diff --git a/tests/test_clusters.py b/tests/test_clusters.py index fd5b11e..98552e4 100644 --- a/tests/test_clusters.py +++ b/tests/test_clusters.py @@ -10,6 +10,7 @@ from atlasapi.atlas import Atlas from atlasapi.lib import AtlasPeriods, AtlasUnits, AtlasGranularities from json import dumps +from datetime import datetime from atlasapi.clusters import AtlasBasicReplicaSet, ClusterConfig from atlasapi.lib import MongoDBMajorVersion as mdb_version from atlasapi.clusters import ClusterConfig, ProviderSettings, ReplicationSpecs, InstanceSizeName @@ -179,3 +180,11 @@ def test_13_set_advanced_options(self): + def test_14_issue_154_additional_data(self): + cluster = self.a.Clusters.get_single_cluster_as_obj(self.TEST_CLUSTER_NAME) + self.assertTrue(type(cluster) is ClusterConfig) + self.assertEqual(cluster.name, self.TEST_CLUSTER_NAME) + self.assertIsInstance(cluster.create_date, datetime) + pprint(cluster.as_dict()) + + test_02_get_a_cluster_as_obj.basic = True diff --git a/tests/test_projects.py b/tests/test_projects.py index d98f2ca..4ed6cd7 100644 --- a/tests/test_projects.py +++ b/tests/test_projects.py @@ -3,6 +3,7 @@ """ +import datetime from pprint import pprint from os import environ, getenv from atlasapi.atlas import Atlas @@ -128,3 +129,11 @@ def test_10_get_project_settings(self): self.assertIsInstance(out, ProjectSettings, "The response must be a ProjectSettings obj") test_10_get_project_settings.basic = True + + + def test_11_get_project_create_date(self): + out = self.a.Projects.project_by_id(self.a.group) + pprint(out.__dict__) + self.assertIsInstance(out.created_date, datetime.datetime, "An datetime should be returned") + + test_02_get_project_by_id.basic = True \ No newline at end of file