From 020c608802349d93cffda8c235a3a5d546028e96 Mon Sep 17 00:00:00 2001 From: Keith Date: Thu, 8 Jun 2017 18:57:12 +0100 Subject: [PATCH] Working on programs and program enrolments. Updated the setup.py to the new version number ready for pushing. --- dotmailer/program_enrolments.py | 27 +++++++++++++++++++++++++-- dotmailer/programs.py | 1 - setup.py | 2 +- tests/test_program_enrolments.py | 2 ++ tests/test_programs.py | 26 ++++++++++++++++++++++++++ tests/test_transaction_email.py | 2 -- 6 files changed, 54 insertions(+), 6 deletions(-) create mode 100644 tests/test_program_enrolments.py create mode 100644 tests/test_programs.py diff --git a/dotmailer/program_enrolments.py b/dotmailer/program_enrolments.py index c308d10..b7add7e 100644 --- a/dotmailer/program_enrolments.py +++ b/dotmailer/program_enrolments.py @@ -1,6 +1,7 @@ from dotmailer import Base from dotmailer.constants import constants from dotmailer.connection import connection +from dotmailer.exceptions import ErrorEnrolmentInvalid class ProgramEnrolment(Base): @@ -44,13 +45,21 @@ def _get_faults(self): :return: """ - return type(self).get_faults(self.id) + # Before proceeding check that the instance has an enrolment ID + # specified. If not raise an error. + if self.id is None: + raise ErrorEnrolmentInvalid() + # Since the functionality is the same, with the exception that + # we already know the ID value call the class instance passing + # self.id in. + return type(self).get_faults(self.id) @classmethod def get(cls, id): """ - + Gets a program enrolment by ID + :param id: The ID of the enrolment. This ID is a GUID and looking something like b0ff06d6-af04-4af8-a299-51bcbad94c1c :return: @@ -62,6 +71,13 @@ def get(cls, id): @classmethod def get_finished(cls, select=1000, skip=0): + """ + Gets program enrolments which have a finished status + + :param select: + :param skip: + :return: + """ response = connection.get( '{}/{}'.format( cls.end_point, constants.PROGRAM_ENROLMENT_FINISHED), @@ -71,6 +87,13 @@ def get_finished(cls, select=1000, skip=0): @classmethod def get_processing(cls, select=1000, skip=0): + """ + Gets program enrolments which have a processing status + + :param select: + :param skip: + :return: + """ response = connection.get( '{}/{}'.format( cls.end_point, constants.PROGRAM_ENROLMENT_PROCESSING), diff --git a/dotmailer/programs.py b/dotmailer/programs.py index 35b3fd4..0d92c51 100644 --- a/dotmailer/programs.py +++ b/dotmailer/programs.py @@ -1,5 +1,4 @@ from dotmailer import Base -from dotmailer.constants import constants from dotmailer.connection import connection diff --git a/setup.py b/setup.py index 8bc68f7..2b367f0 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ setup( name='dotmailer', - version='0.1', + version='0.2.0', description='DotMailer API wrapper', long_description=long_description, diff --git a/tests/test_program_enrolments.py b/tests/test_program_enrolments.py new file mode 100644 index 0000000..e82691b --- /dev/null +++ b/tests/test_program_enrolments.py @@ -0,0 +1,2 @@ +from dotmailer.program_enrolments import ProgramEnrolment + diff --git a/tests/test_programs.py b/tests/test_programs.py new file mode 100644 index 0000000..b72f71b --- /dev/null +++ b/tests/test_programs.py @@ -0,0 +1,26 @@ +import pytest +from dotmailer.programs import Program + + +def test_get_all(connection): + response = Program.get_all() + assert type(response) is list + if len(response) > 0: + assert response[0].id is not None + + +def test_get_id(connection): + response = Program.get_all() + if len(response) < 1: + assert False, 'Unable to test as no programs exists' + id = response[0].id + program = Program.get(id) + assert type(program) is Program + assert program.name == response[0].name + assert program.status == response[0].status + assert program.date_created == response[0].date_created + + +def test_invalid_get_id(connection): + with pytest.raises(Exception): + Program.get(0) diff --git a/tests/test_transaction_email.py b/tests/test_transaction_email.py index ed5ad15..a0e8db0 100644 --- a/tests/test_transaction_email.py +++ b/tests/test_transaction_email.py @@ -40,8 +40,6 @@ def test_get_stats(connection, aggregate_by): datetime.date(2016, 12, 31), aggregate_by ) - print response - print type(response) # Loop through the list of aggregated data points, checking that each # entry has all the expected keys