Skip to content

Commit

Permalink
Working on programs and program enrolments.
Browse files Browse the repository at this point in the history
Updated the setup.py to the new version number ready for pushing.
  • Loading branch information
Keith committed Jun 8, 2017
1 parent 0a475e4 commit 020c608
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
27 changes: 25 additions & 2 deletions dotmailer/program_enrolments.py
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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:
Expand All @@ -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),
Expand All @@ -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),
Expand Down
1 change: 0 additions & 1 deletion dotmailer/programs.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from dotmailer import Base
from dotmailer.constants import constants
from dotmailer.connection import connection


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

setup(
name='dotmailer',
version='0.1',
version='0.2.0',
description='DotMailer API wrapper',
long_description=long_description,

Expand Down
2 changes: 2 additions & 0 deletions tests/test_program_enrolments.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from dotmailer.program_enrolments import ProgramEnrolment

26 changes: 26 additions & 0 deletions tests/test_programs.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 0 additions & 2 deletions tests/test_transaction_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 020c608

Please sign in to comment.