diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba74660 --- /dev/null +++ b/.gitignore @@ -0,0 +1,57 @@ +# Byte-compiled / optimized / DLL files +__pycache__/ +*.py[cod] + +# C extensions +*.so + +# Distribution / packaging +.Python +env/ +build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +*.egg-info/ +.installed.cfg +*.egg + +# PyInstaller +# Usually these files are written by a python script from a template +# before PyInstaller builds the exe, so as to inject date/other infos into it. +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +nosetests.xml +coverage.xml +*,cover + +# Translations +*.mo +*.pot + +# Django stuff: +*.log + +# Sphinx documentation +docs/_build/ + +# PyBuilder +target/ diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..f233b72 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,10 @@ +language: python +python: + - "2.7" +# command to install dependencies, e.g. pip install -r requirements.txt --use-mirrors +install: pip install -r requirements.txt --use-mirrors +# command to run tests, e.g. python setup.py test +script: python coding102-REST-python/test_coding102.py +branches: + only: + - clus-updates diff --git a/README.md b/README.md index c6c1071..93295b4 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,5 @@ Sample code for the Cisco DevNet Coding Skills Learning Labs You can find step-by-step tutorials that walk through this sample code on [Cisco DevNet](http://learninglabs.cisco.com). +# Build Status +[![Build Status](https://travis-ci.org/CiscoDevNet/coding-skills-sample-code.svg?branch=clus-updates)](https://travis-ci.org/CiscoDevNet/coding-skills-sample-code) diff --git a/coding102-REST-python/apic-em1.py b/coding102-REST-python/apicEm1.py similarity index 66% rename from coding102-REST-python/apic-em1.py rename to coding102-REST-python/apicEm1.py index a597589..b1d01cf 100644 --- a/coding102-REST-python/apic-em1.py +++ b/coding102-REST-python/apicEm1.py @@ -23,11 +23,25 @@ import requests -# put the ip address or dns of your apic-em controller in this url -url = 'https://sandboxapic.cisco.com/api/v0/host/1/3' +def hello(): + # put the ip address or dns of your apic-em controller in this url + url = 'https://sandboxapic.cisco.com/api/v0/host/1/3' -# this statement performs a GET on the specified url -response = requests.get(url, verify=False) + # this statement performs a GET on the specified url + response = requests.get(url, verify=False) -# print the json that is returned -print(response.text) \ No newline at end of file + return response + +# This is special python syntax that enables you to run this script +# directly or use it as a module and test your code! +# Read more about it here: http://stackoverflow.com/questions/419163/what-does-if-name-main-do +if __name__ == '__main__': + + # this statement calls the method hello() and + # stores it into result + result = hello() + + # print the result as text. + # The responses library provides the .text convenience method to access + # the result body or text + print(result.text) diff --git a/coding102-REST-python/test_coding102.py b/coding102-REST-python/test_coding102.py new file mode 100644 index 0000000..1930ba0 --- /dev/null +++ b/coding102-REST-python/test_coding102.py @@ -0,0 +1,24 @@ + +import os +import unittest +import json +import apicEm1 + +class Coding102TestCase(unittest.TestCase): + + def setUp(self): + + self.app = apicEm1 + + def tearDown(self): + + print("tear down") + + def test_hello(self): + + result = self.app.hello() + self.assertTrue(result is not None) + self.assertEquals(200, result.status_code) + +if __name__ == '__main__': + unittest.main() diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..7b27fd3 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +requests==2.6.2 +wsgiref==0.1.2